如何在拨号会话与 Twilio 异步接收忙音后留下 mp3 语音邮件?

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

我想创建一个拨号会话循环(在一个拨号会话结束后,创建另一个)以便一次呼叫多个客户端。

我的拨号动词有这个方法:

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;
}

当我的 DialCallStatusbusyno-answer 我想留下一个保存的 mp3 消息(语音信箱)

但是当我更新 call /w dialCallSid(在 $client->leaveVoiceMail($_REQUEST['DialCallSid']); 中)时,我得到了这个错误:

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

有没有办法在当前通话中异步地在拨号结束时留言?

谢谢!

如果 DialCallStatus returns 占线或无人接听,则表示被叫方未接听电话。如果拨叫方的语音邮件或人工接听电话,您只能留下语音邮件或播放自动通知。

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

也许使用 Calls REST API 资源来模拟出站呼叫并使用应答机检测 (AMD) 来促进该过程可能会更好。