【问题标题】:Twilio Voice Api - Is it possible to record message and play the record message in the a flowTwilio Voice Api - 是否可以在流中录制消息并播放录制消息
【发布时间】:2016-06-11 16:46:13
【问题描述】:

当收到来电时,我需要让来电者录制消息。然后拨打一个号码并在接听者接听电话时播放录制的消息。

这可能吗?

【问题讨论】:

    标签: twilio twilio-api


    【解决方案1】:

    注意:将 Account SID、Auth Token、电话号码、网站地址替换为您的值。

    第 1 步。

    接听来电并录音(http://somewebsite.xyz/recordMessage.php

    <?php    
        header("content-type: text/xml");
        echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    ?>
    
    <Response>
        <Say>
            Please leave a message at the beep. 
            Press the star key when finished. 
        </Say>
        <Record 
            action="http://somewebsite.xyz/makeOutgoingCall.php" 
            maxLength="60"
            timeout="10"
            finishOnKey="*"
            />
        <Say>I did not receive a recording</Say>
    </Response>
    

    https://www.twilio.com/docs/api/twiml/record

    录制完成后,Twilio 将向“操作”URL 发出请求,并将录制的 URL 作为名为 RecordingUrl ($_REQUEST['RecordingUrl']) 的参数传递

    第 2 步。

    拨打电话 (http://somewebsite.xyz/makeOutgoingCall.php)

    <?php
        header("content-type: text/xml");
        echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    ?>
    
    <Response>
        <Say>Thank you for your message. Goodbye.</Say>
        <Hangup/>
    </Response>
    
    <?php
        // Include the Twilio PHP library
        require 'Services/Twilio.php';
    
        // Twilio REST API version
        $version = "2010-04-01";
    
        // Set our Account SID and AuthToken
        $sid = 'AC123';
        $token = 'abcd';
    
        // A phone number you have previously validated with Twilio
        $phonenumber = '4151234567';
    
        $recordingUrl = urlencode($_REQUEST['RecordingUrl']);
    
        // The URL Twilio will request when the call is answered            
        $twilioRequestUrl = "http://somewebsite.xyz/playRecordedMessage.php?RecordingUrl=".$recordingUrl;
    
        // Instantiate a new Twilio Rest Client
        $client = new Services_Twilio($sid, $token, $version);
    
        try {
    
            // Initiate a new outbound call
            $call = $client->account->calls->create(
                $phonenumber, // The number of the phone initiating the call
                '5101234567', // The number of the phone receiving call
                $twilioRequestUrl 
            );
            //echo 'Started call: ' . $call->sid;
        } catch (Exception $e) {
            //echo 'Error: ' . $e->getMessage();
        }
    

    https://www.twilio.com/docs/libraries/php

    https://www.twilio.com/docs/quickstart/php/rest/call-request

    第 3 步。

    播放录制的消息 (http://somewebsite.xyz/playRecordedMessage.php)。

    <?php
    
        // and play the recording back, using the URL that Twilio posted
        header("content-type: text/xml");
        echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    ?>
    <Response>
        <Say>Take a listen to your message.</Say>
        <Play><?php echo $_REQUEST['RecordingUrl']; ?></Play>
        <Say>Goodbye.</Say>
    </Response>
    

    https://www.twilio.com/docs/quickstart/php/twiml/play-mp3-for-caller

    https://www.twilio.com/docs/api/twiml/play

    【讨论】:

    • 感谢您的示例回复。在第 2 步中,呼叫者应该正在通话中。接收者应听到录制的消息并与呼叫者交谈。删除响应中的挂断是否有效?
    • 您是否要筛选来电? “接收者”是否总是与呼叫者交谈?如果没有,你对来电者怎么办?请使用完整的用户故事更新您的问题。
    • 从呼叫者那里获得筛选问题的答案并将答案播放给接收者的想法。
    • 您可以将呼叫者置于队列中而不是挂断,当呼叫者等待时,接收者会听到录音,然后您可以连接接收者加入队列并与呼叫者通话。使用 Dial 和 Queue 标签修改第 2 步和第 3 步。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多