0
votes

I'm a newbie and pardon me if my question do not make sense. I Would like to send a voice mail with some message if user do not answer/declined outbound call.

Steps Followed:

I am using 'textPlus' mobile app and got a US number. I could successfully place an outbound call to the US number which I got in textPlus app. Also I noticed that if call is unanswered/declined by the user , twilio is delivering a voice mail with the same message which had been used for making out bound call to the textPlus app number.

I want to change responses for cases if outbound call answered vs unanswered/declined.

Approaches I tried:

  1. I tried subscribing to the 'statusCallbackEvent' events and use 'modify call in-progress' api to change the text if outbound call is 'busy/no-answer/declined'. Unfortunately, it is generically showing 'completed' status but not 'busy,no-answer,declined' like mentioned in article. Caveat : as twilio out bound call it self is delivering voice mail if unanswered/declined, it is sending status as answered. So I could not able to distinguish between calls answered vs voice mail delivered.

  2. I did try this approach and understood that this will work for in bound calls

  3. I even tried subscribing to AMD by 'MachineDetection: Enable'. Apparently, by the time it detects call moves to 'completed' stage. Reference article.

Help required

  1. How to distinguish busy/no-answer/declined statuses
  2. Suggest me with right approach to achieve above requirement. Do let me know if am missing anything.
1

1 Answers

0
votes

I finally found a solution for the above. I believe this will be a kind of work around to the solution with which I can live with. I observed that when I send 'MachineDetection:Enable' while making outbound call, I see that in the response of outbound call api, 'MachineDetectionDuration' value is being returned.

Upon investigating that value against many answered vs unanswered vs declined calls across multiple devices, I comprehensively found if 'MachineDetectionDuration' is more than 1000 it happens to be a answered call. Else it is unanswered / declined.

Following is the sample code snippet, which I believe should be help full:

Outbound API:

curl --location --request POST 'https://api.twilio.com/2010-04-01/Accounts/<account sid>/Calls.json' \
--header 'Authorization: Basic <Account sid:token>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'Url=https://jasper-jackal-xxx.twil.io/sendVoiceMail' \
--data-urlencode 'To=+<to num>' \
--data-urlencode 'From=+<from num>' \
--data-urlencode 'MachineDetection=Enable'

Url: Twilio function

exports.handler = function(context, event, callback) {
    let twiml = new Twilio.twiml.VoiceResponse();
    if (event.MachineDetectionDuration > 1000)
        twiml.say("Call answered case message");
    else
        twiml.say("This is a voice mail. Text has been updated successfully"); //sends voice mail

    callback(null, twiml);
};