Reputation: 47985
I would like to implement an simple timer within a communication.
My scenario is a small math trainer where you train 5 minutes, after the 5 minutes of normal interaction I would like to inform the user that the time is now up. I don't want to wait until the user has finished his next input/answer (optional just if there is currently no input).
Is there any way to "push" an answer time based?
Upvotes: 5
Views: 3163
Reputation: 3703
This is probably irrelevant for you by now but I'm writing an answer for people who might visit here.
You can implement this with events
in Dialogflow (formerly API.ai). See here for documentation.
You define an intent based on an event called, say, time-is-up
, and have a timer on your end that triggers this event after five minutes.
Upvotes: 0
Reputation: 1234
Sadly it looks like they are not interested in adding any sort of delay features: Dialogflow (API.AI) Forums :- Adding a delay to responses, so it feels more real
But this is one reason why building a server side solution in between your deployment integration (ex. Facebook messenger) and API.ai is so useful- it let's you customize fulfillments, including sending fulfillments triggered by your own custom logic built on top of API.ai solutions.
So in the case of FB messenger as a simple example, you could do something like below, and just build any logic you want to call sendTextMessage:
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);
}
});
}
Upvotes: 0
Reputation: 4656
The Conversation API does not support a push model. When you get the users response, you can check the timer and respond appropriately.
Upvotes: 2