Adding custom delay depending on length of previous response in Rasa Webchat

You made a mistake while copying my code, look at the line before the return.

I really suggest you learn JavaScript, this is something really simple, but no one but you will know exactly what you want better than you :slight_smile:.

I will make my code more beginner-friendly and explain it.

// Initializing a variable; this will be the length of the previous message
let m1 = null

customMessageDelay: (message) => {
    // Set the value of delay to the last message's delay (null on first message)
    let delay = m1

    // If the delay is null, aka if m1 is null, aka if this is the first message ever, set the delay according to the current message instead (you can instead set m1 to 0 if it is null and then set the delay to m1+message.length)
    if (delay == null) delay = message.length

    // Multiply the delay by 30
    delay = delay * 30

    // Make sure the delay is between 1000 and 6000 milliseconds
    if (delay > 6000) delay = 6000
    if (delay < 1000) delay = 1000

    // Save the current message's length in m1 to be used next time (you can save the delay instead, or anything you  want)
    m1 = message.length

    return delay
}
1 Like