0

In the twilio API is it possible to figure out how long a message is going to take?

My Requst come from that I need to figure out if a verbal message has been said.

a API endpoint to get the time of a special Twiml or asking on a call if it did all the say would be the best option.

We are logging length of call etc but we still need to see if they have heard all of message or hang up before it is all done.

1 Answers1

2

Twilio developer evangelist here.

There's no way to know how long a message will take, but I have another idea.

If you set up your <Say> message with a <Redirect> after it, then the user will have heard all the message if the <Redirect> url receives a request.

<Response>
  <Say>This is an important message.</Say>
  <Redirect method="POST">https://example.com/results/success</Redirect>
</Response>

Let me know if that helps at all.

Update

So, the above didn't exactly work as Twilio seems to read ahead and load the <Redirect> URL before the <Say> has completed. However, we can still use this to help.

In the response to the <Redirect> URL, we can make Twilio call to another URL somehow. For example, the following TwiML will call out to a URL to fetch a file to <Play> to the user. Rather than call directly to an mp3 file you can make this call to a server that notes the call got this far and then returns a short, maybe silent, mp3 file. Then we can hangup because we've done what we needed to do.

<Response>
  <Play>https://example.com/record_call_complete_and_return_mp3</Play>
  <Hangup/>
</Response>

This is a bit of a hack, but it seems to work as the <Play> URL is only requested when Twilio starts the response to the <Redirect>.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • That is one of the ways I have tried - I will try this out. I hoped Twilio had something like the get call information but for how long a Twiml would take to say - but using a redirect is fine and it is something which was already in my head only it didn't develop that much since this sound as a better option :). – Kasper Sanguesa-Franz Mar 13 '18 at 15:01
  • We don't have an API for that. You could record the message as an mp3, or send the dynamic text you need recorded to an API, like AWS Polly, and you'd be able to calculate the length of the mp3 file and use that? I'd have thought the Redirect was more definite than recording the length of a call and matching it up to a known message length. – philnash Mar 13 '18 at 21:57
  • As long as I can say that they have heard the full message it should be good enuogh - still loooking into if the redirect is going as planned – Kasper Sanguesa-Franz Mar 14 '18 at 10:29
  • The problem is that the redirect is called before it gets to that, currently it is making x say, then a `gather` followed by a say which is going if they do not input anything - that is working as planned. – Kasper Sanguesa-Franz Mar 14 '18 at 12:51
  • i have replaced the gather and the last say with a redirect instead - before i get to hear the full message it is already calling the redirect for the message eg. the say was called at `2018-03-14 12:48:52 UTC` the redirect was called at `2018-03-14 12:48:55 UTC` the message takes longer than 3 to listen too, - I basically want a callback if all the messages was heard instead of a redirect – Kasper Sanguesa-Franz Mar 14 '18 at 12:54
  • Ah, perhaps Twilio is calling the redirect early in order to preload the response. When you had a gather, was that to ask whether they had heard the message and was that working? Seems like the best way to tell if a person listened to the whole message. – philnash Mar 14 '18 at 23:19
  • Basically yes the gather is to ask them either to verify or deny it. The problem for me is that they need to hear the whole message (before the gather) for it to be legal active. – Kasper Sanguesa-Franz Mar 15 '18 at 09:00
  • In that case, I'd have it set up like: `The important messagePress 1 to accept`. That way they can't short circuit the `` until the first message has completed. – philnash Mar 15 '18 at 22:18
  • The problem with that approach is they need to verify it, since my calls is to verify something they need to say yes or no to that., and asking them if they have heard it is not suitable. – Kasper Sanguesa-Franz Mar 16 '18 at 08:27
  • I’m not clear what you need then, sorry. Perhaps our can email me at philnash@twilio.com and we can solve this off SO. – philnash Mar 16 '18 at 08:54
  • After a mail correspondance about it we have seen that the way to do it would to use a play instead of a extra gather. – Kasper Sanguesa-Franz Mar 19 '18 at 11:56
  • Can you create a new answer then I can give that one the bounty and the right answer/ – Kasper Sanguesa-Franz Mar 19 '18 at 12:02