hi is there a convient way to say things or ask questions in a delay ?
for example
convo.say('hello...') i want to wait 5 seconds until it sends this to the user
convo.say("hi again")i want to wait 5 minutes until it sends this to the user
convo.say("last hi") i want this to be sent immediatly after the previous messages has been sent,
thanks.
@gilLionKing I quickly have a look and it seems that BotKit doesn't supports this under the hood (@peterswimm can confirm it or decline), but what you can actually do is to monkey patch say() and ask() functions and have setTimeout inside.
An example would be something like this (didn't tested it, but you should get an idea):
var originalSay = convo.say;
convo.say = function(text, wait) {
var me = this;
if (typeof(delay) == 'number' && wait > 0) {
setTimeout(function() {
originalSay.call(me, text);
}, wait);
} else {
originalSay.call(me, text);
}
};
hi thanks . i tried this style the examle doesnt work since this is the timeout context when setting timeout
and it cant add a message so i tried passing a convo instead of this
oldSay.call(convo, text, cb);
this has been working sporadically. sometimes the message shows up and sometimes doesn't.
what can cause this ? also just setting a timeout on a say like this :
doesn't work for some reason.
@gilLionKing I've updated my example a little bit, i've chek it out and it's not that easier as I thought. Let me think a bit.
@gilLionKing ok, man, sorry for confusing, it's not possible actually :) because convo.say() is not directly sending message but adds it to the sort of task queue wich triggers every tick. This tick is an internal BotKit clock which ticks at a regular pace, by default every 1500ms.
You can change this value by calling setTickDelay() function. Ex. controller.setTickDelay(4000);
Here is a documentation for setTickDelay().
@gilLionKing I would pay attention to this explanation from the doc:
The 1.5 second delay between sending messages serves two purposes: first, it creates a small delay between outgoing messages, giving some small simulation of typing time. Second, it helps to keep bots API use within a reasonable limit in order to prevent being rate limited by the message platform.
Hi thanks man but first of all i tried using the tick before like that
module.exports = function(controller,messagingApi) {
controller.setTickDelay(6000);
and it has no affect, messages are being sent with a second difference.
second how would you use it in my example ? just change it on the fly for every message ? would that work ?
I don't think it is a good idea to change it on the fly though. As far as I understood, you can do it once and send messages with the same pace like 1500ms || 6000ms.
The alternative way to go, would be replyWithTyping() function, then it would delay message based on the length of the text.
Hello,
You can do like that :
`````
setTimeout(() => {
bot.reply(message, 'hello...');
}, 5000);
setTimeout(() => {
// Start a new conversation here
convo.say('hi again');
convo.say("last hi")
}, 300000);
`````
WDYT ?
@ouadie-lahdioui I think this approach wouldn't be deterministic since convo.say() has its own clock when it sends messages (every 1500ms by default). So, per my understanding, it's kind of hack, which we already discussed above. Or am I missing something? 馃槂
You can specify a custom delay on each message in a conversation.
convo.say({text: 'hello', delay: 3000});
I added a note about this to the docs!
https://botkit.ai/docs/core.html#changing-the-pace-of-the-conversation-with-custom-per-message-delay
@julianusti you didn't miss anything 馃憤
Closing this as answered
Hey @benbrown , just to confirm, that delay parameter doesn't work with addMessage and addQuestion, correct, or possibly not with Quick Links and/or attachments? Or is something else of mine broken? :)
Most helpful comment
I added a note about this to the docs!
https://botkit.ai/docs/core.html#changing-the-pace-of-the-conversation-with-custom-per-message-delay