Leave a message after the beep using Twilio’s API

Leave a message after the beep using Twilio’s API

How to leave a message after the beep using Twilio’s Answering Machine Detection!

·

2 min read

This short technical article contains the key details that I had to dig up from Twilio’s API docs when we needed to record a message after the beep.

This article does not contain the code specifics, you can use any language or SDK’s available to use Twilio’s API. Its contains the key information you need to know to do this task.

By using twilio’s API and its answering machine detection mechanism we can do this very easily.

When making a call with your program to a number, you can set a parameter “AnsweredBy” to enable machine detection.

“AnsweredBy” parameter can be set to “Enable” or “DetectMessageEnd”

If set to “Enable”, Alt text of image Twilio API answering machine detection - record a message after the beep

the events can be,

  • machine_start
  • human
  • fax
  • unknown

This helps in detecting at the start of the call whether it was human or machine which returned the call.

Twilio then sends a request to your set URL/ application and you can send a recording based on the detection, the parameters sent to your application by Twilio look something like this, Leave a message after the beep using Twilio’s Answering Machine Detection

But if you want to leave a message after the beep you will have to set it to “DetectMessageEnd” as shown below,

AnsweredBy: "DetectMessageEnd"

If you set it to “DetectMessageEnd” the events generated are,

  • machine_end_beep (this is what you need)
  • machine_end_silence
  • machine_end_other
  • human
  • fax
  • unknown.

So the event you are looking for is “machine_end_beep” which as it reads means the event that occurs when the voicemail beep is ended and now you can start playing your message. This is extremely useful when sending out (bulk) voice messages and getting hit by a voicemail. Instead of playing the recording as soon as the call is picked you can play your message when the voicemail recording has finished by doing your logic on this event.

Read more, the article is published on https://peham.dev/learning/leave-a-message-after-the-beep-using-twilio-api/

If you have more questions write a comment below or reach out to me at https://peham.dev/#contact