Answer after a given delay

I would like to implement a simple timer in a message.

My scenario is a small mathematical trainer in which you train for 5 minutes, after 5 minutes of normal interaction I would like to inform the user that now is the time. I do not want to wait until the user completes his next login / response (optional if there is currently no input).

Is there a way to โ€œpushโ€ response time?

+5
source share
2 answers

The chat API does not support the push model. When you receive a response from users, you can check the timer and respond accordingly.

+2
source

Unfortunately, it seems that they are not interested in adding any delay functions: Dialogflow Forums (API.AI): - Adding a delay to answers, so that it seems more real

But this is one of the reasons why building a server-side solution between your deployment integration (e.g. Facebook messenger) and the API.ai API is so useful - it allows you to customize the execution, including sending the execution caused by your own logic built on top of the API solutions .ai.

So, in the case of FB messenger, as a simple example, you can do something like below and just build any logic you want sendTextMessage to call:

function sendTextMessage(recipientId, text) { sendTypingOff(recipientId) var messageData = { recipient: { id: recipientId }, message: { text: text } } callSendAPI(messageData); } //Calls FB messenger API. If successful returns a message ID in response function callSendAPI(messageData) { request({ uri: 'https://graph.facebook.com/v2.6/me/messages', qs: { access_token: config.FB_PAGE_TOKEN }, method: 'POST', json: messageData }, function (error, response, body) { if (!error && response.statusCode == 200) { var recipientId = body.recipient_id; var messageId = body.message_id; if (messageId) { console.log("Successfully sent message with id %s to recipient %s", messageId, recipientId); } else { console.log("Successfully called Send API for recipient %s", recipientId); } } else { console.error("Failed calling Send API", response.statusCode, response.statusMessage, body.error); } }); } 
0
source

Source: https://habr.com/ru/post/1261075/


All Articles