How to send an audio from whatsapp to Dialogflow using twilio?

23 views
Skip to first unread message

Fox C

unread,
Apr 17, 2022, 11:34:44 AM4/17/22
to Dialogflow Essentials Edition users
I am doing a chatbot with dialogflow-es and I connected it with twilio for whatsapp, but the problem now is that I want that dialogflow receive the audio´s user, but I don´t know how....
in less words: I need that the audio arrive to dialogflow.

Jose Gutierrez Paliza

unread,
Apr 20, 2022, 12:44:38 PM4/20/22
to Dialogflow Essentials Edition users

Following this Dialogflow integration[1] with Twilio.
There is a server that receives the incoming webhook from Twilio. You’ll have to add the const `numMedia` and send the message.

Once you know how much media has been sent, you can access them in parameter `MediaUrl{N}` where N is an integer. The media is delivered as a URL, so you’ll need to download it.

The `server.js` file would look like this:

app.post('/', async function(req, res) {

  const body = req.body;

  const text = body.Body;

  const id = body.From;


  const numMedia = parseInt(body.NumMedia, 10);

  if (numMedia > 0) {

    for (let i = 0; i < numMedia; i++) {

      console.log(body[`MediaUrl${i}`]);

    }

  }  


  const dialogflowResponse = (await sessionClient.detectIntent(

      text, id, body)).fulfillmentText;

  const twiml = new  MessagingResponse();

  const message = twiml.message(dialogflowResponse);

  res.send(twiml.toString());

});


To deal with the audio in Dialogflow, you can use Auto Speech Adaptation[2].


[1]https://github.com/GoogleCloudPlatform/dialogflow-integrations/tree/03676af04840c21c12e2590393d5542602591bee/twilio 

[2]https://cloud.google.com/dialogflow/es/docs/speech-adaptation
Reply all
Reply to author
Forward
0 new messages