Search code examples
botsrepeatactions-on-googledialogflow-es

Repeat last sentence


I am using actions-on-google and Dialogflow to build a bot.

I was wondering how I can easily repeat the last sentence when asked by the user ("repeat please").

One way would be to have repeat followup intents in Dialogflow but this is quite heavy since :

  • you need to add one after each intent and I have many
  • in a multi-user environment you need to keep track of the last sentence for every user ...

Does anyone know how to accomplish this?


Solution

  • Broadly speaking, the best way would be to take advantage of Dialogflow Contexts. As you send the message, you can also add that message to a context (for example, you can call it "last_message"). You can then have another Intent that takes as an input context the "last_message" context and, if triggered, uses the value saved in the context to repeat it.

    @SysCoder has a package that will help you do this for node.js.

    Clarification

    This assumes that you're generating the response through fulfillment. In cases like this, it should be fairly easy to save the message you're sending back in two places, rather than one. Libraries such as voice-repeater or multivocal handle much of this for you, but it isn't difficult to do yourself.

    If you're handling all the replies through the Response section of the GUI, then this approach wouldn't work.