0

When the call ends, I want to send data to Microsoft teams. For that purpose, I am making a POST request using the Twilio webhook. I have added the link for HTTP request in CALL STATUS CHANGES. But I also want to send data collected during calls. Is there any way to do that?

Article here(https://www.twilio.com/docs/usage/webhooks/voice-webhooks) doesn't mention anything about passing data.

My POST request URI looks something like this:- https://xyz?Name=Himanshu&Phone=1234567890

I want Name and Phone data to be collected from Memory.

Himanshu Kumar
  • 89
  • 1
  • 10

1 Answers1

2

Twilio developer evangelist here.

When Twilio sends a webhook request about a voice call it will send a whole bunch of parameters including CallSid, To, From (the number user called from), AccountSid, CallStatus and more all of which are listed here.

I would not recommend making the Twilio webhook directly to Microsoft Teams as Twilio expects there to be a response to the request. Also, Twilio cannot know the name of your caller either.

Instead, I would recommend setting up the webhook request to go to your own application where you can parse out the data you need from the request, collect other data like name, and then make the request to Teams to complete your interaction.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • I also want to send data collected in the event.Memory object during call from the user, not just what is being sent by default. – Himanshu Kumar Jun 12 '21 at 11:46
  • Ah, I did not realise you were using Autopilot for this. [The Autopilot request](https://www.twilio.com/docs/autopilot/actions/autopilot-request) looks a bit different to a regular Twilio Voice webhook, but all the information is there. If you want to use the data in `event.Memory` you will need to JSON parse the memory, like `const data = JSON.parse(event.Memory);` and then you will have access to everything you have collected or remembered during the conversation. – philnash Jun 14 '21 at 04:19
  • When the caller disconnects call immediately, we loose event object and call another function with a different object[CALL STATUS CHANGES]. I need access to memory inside previous event object to gather partially collected data. – Himanshu Kumar Jun 29 '21 at 08:07
  • This seems to be the same question as [this one](https://stackoverflow.com/questions/67955970/handle-call-end-in-twilio) and I recommend that you store the items in the memory every time you receive a callback from Autopilot. That way, you have the partial data even if the person hangs up. – philnash Jun 29 '21 at 23:28
  • Yes, I am aware of this solution and have implemented this as well. This solution seems very inefficient to me. I was looking for a better way. – Himanshu Kumar Jun 30 '21 at 06:14
  • Oh, you might be able to use the Event Webhooks: https://www.twilio.com/docs/autopilot/api/event-webhooks. Try subscribing to the `onDialogueEnd` event and see if that is fired when someone hangs up. It should deliver the contents of the memory as long as you subscribe to webhook requests as `POST` requests. – philnash Jun 30 '21 at 06:18