Reputation: 2185
I am creating an action for Google assistant getting some data from a REST API. The action launch a http request then parse the response to create the resulting action speech, all this processing is done using a Promise to perform it asynchronously. As a result, there is a certain amount of time before the user get the action response.
Is there a way to first tell a acknowledgement sentence like "ok, I am searching" then as soon as the http answer is processed to complete the action with a second sentence ?
Below is the skeleton of the asynchronous intent:
app.intent('IntentName', (conv, {params}) => {
// ==> Provide here an acknowledgement to the user <==
// return a promise to handle this intent asynchronously
return new Promise(function (resolve, reject) {
http.get(httpOptions, function (resp) {
processing...
conv.close(strSpeech);
});
});
});
Upvotes: 1
Views: 230
Reputation: 50701
Not as directly as you expect, no.
Actions on Google and Dialogflow work in a very conversational back-and-forth way. With only some exceptions, once your Action sends back a reply, you're not able to send anything to the user until they send you back another request.
One of those exceptions is that you're able to send a notification through the Assistant to your user. Notifications are only available on some surfaces, and aren't really suited if the response will be coming within a few seconds, so this may not be a good solution in your case.
Better, although a bit of a hack, is to immediately send back a reply that includes a Media Response that includes a few seconds of "hold music". While the hold music is playing, you can have your code determining the answer and storing the result in a cache. At the end of the music, your Action will be called again to indicate the audio is over. If you have an answer by then, you can return it. If not, you can start a few more seconds of hold music.
Upvotes: 1