Search code examples
twiliotwilio-php

Twiml voice response to incoming call not working after record start


I want to record an incoming call request(both sides), and than say some line.

my webhook response to incmong call is:

        $response = new VoiceResponse;
        $response->record([
            'action' => 'http://example.com',
            'timeout' => '180',
            'recordingStatusCallback' => 'http://example2.com',
        ]);
        $response->say("hello world!", array('voice' => 'alice'));
        return $response;

which give the following twiml:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
   <Record action="http://example.com" timeout="180" recordingStatusCallback="http://example2.com"/>
   <Say voice="alice">hello world!</Say>
</Response>

the problem I face is the "Hello world" not play, if I remove the $response->record part then the "Hello world" work


Solution

  • The <Record> TwiML verb is used to take a recording of the person on the phone, like in a voicemail situation. The <Record> verb will effectively block and not execute any other TwiML until the recording is complete, then it will make a request to the URL in the action attribute, so your <Say> will never be executed.

    If you are trying to record a voicemail, then I recommend putting the <Say> first and instructing the caller to leave their message after a beep.

    $response = new VoiceResponse;
    $response->say("Hello world! Please leave your message after the beep.", array('voice' => 'alice'));
    $response->record([
        'action' => 'http://example.com',
        'timeout' => '180',
        'recordingStatusCallback' => 'http://example2.com',
    ]);
    return $response;
    

    If you are trying to record the entire incoming call from the beginning, you need to use the REST API to start the recording.

    If you are trying to do something else with the call, please comment below and I'll try to help out.