victorbalssa
victorbalssa

Reputation: 2813

How to leave a mp3 voicemail after dial session receive busy signal asynchronously with Twilio?

I want to create a loop of dial sessions (after one dial session end, another one is created) in order to call multiple clients at a time.

I have this method in action of my dial verb :

public function afterCall(Call $call, DialSession $ds, TwilioClient $client): VoiceResponse
{

        $voiceResponse = new VoiceResponse();
        $voiceResponse->pause(['length' => 1]);

        if ($_REQUEST['DialCallStatus'] === 'completed') {
            $call->status = Call::COMPLETED;
            $call->connected = true;
            $call->recording_link =  $_REQUEST['RecordingUrl'];
        }

        if ($_REQUEST['DialCallStatus'] === 'busy' || $_REQUEST['DialCallStatus'] === 'no-answer') {
            $call->status = Call::BUSY;
            $client->leaveVoiceMail($_REQUEST['DialCallSid']);
        }

        if ($_REQUEST['DialCallStatus'] !== 'completed' &&
            $_REQUEST['DialCallStatus'] !== 'busy' &&
            $_REQUEST['DialCallStatus'] !== 'no-answer'
        ) {
            $call->status = Call::ERROR;
        }

        return $voiceResponse;
}

When my DialCallStatus is busy or no-answer I would like to leave a saved mp3 message (voicemail)

But when I update call /w dialCallSid (in $client->leaveVoiceMail($_REQUEST['DialCallSid']);) I got this error :

Twilio\Exceptions\RestException: [HTTP 400] Unable to update record: Call is not in-progress. Cannot redirect.

Is there a way to leave a message on Dial end asynchronously from the current call ?

Thank you !

Upvotes: 0

Views: 160

Answers (1)

Alan
Alan

Reputation: 10771

If DialCallStatus returns busy or no-answer, it means the dialed party is not answering the call. You can only leave a voice mail or play an automated announcement if the dialed parties voicemail or human actually answered the call.

https://www.twilio.com/docs/voice/twiml/dial#dialcallstatus

Maybe you would be better served using the Calls REST API resource to imitate an outbound call and use Answering Machine Detection (AMD) to facilitate the process.

Upvotes: 1

Related Questions