【问题标题】:Twilio Programmable Voice isn't workingTwilio 可编程语音无法正常工作
【发布时间】:2018-02-23 06:50:45
【问题描述】:

当我尝试使用 [TwilioVoice Call] 方法从我的应用程序传递参数时,我无法在 twiML 应用程序上获取这些参数。但是当我尝试使用 FormData 从 POSTMAN 传递相同的数据时,它工作正常并且还能够成功创建调用。

你能帮我如何使用从我的 iOS 应用程序传递到 twiML 的参数

PHP 中的 TwiML 应用程序:

<?php
/*
 * Makes a call to the specified client using the Twilio REST API.
 */
include('./vendor/autoload.php');
include('./config.php');
$to = isset($_GET["to"]) ? $_GET["to"] : "";
if (!isset($to) || empty($to)) {
    $to = isset($POST["to"]) ? $_POST["to"] : "";
}
$from = isset($_GET["from"]) ? $_GET["from"] : "";
if (!isset($from) || empty($from)) {
    $from = isset($POST["from"]) ? $_POST["from"] : "";
}

use Twilio\Twiml;
$response = new Twiml();
$dial = $response->dial(['callerId' => $from]);
$dial->client($to);
echo $response;

iOS 目标-C:

self.call = [TwilioVoice call:[self fetchAccessToken]
                           params:@{@"to": @"1",@"from":@"2"}
                             uuid:uuid
                         delegate:self];

当我尝试从 iOS 传递参数时的 Twilio 错误日志

警告 - 13224 拨号:Twilio 不支持拨打此号码或号码无效

参考 TwiML 应用程序代码

https://github.com/twilio/voice-quickstart-server-php

【问题讨论】:

    标签: objective-c twilio twilio-api twilio-php twilio-twiml


    【解决方案1】:

    这里是 Twilio 开发者宣传员。

    12100 error 来自 Twilio 无法解析从您的服务器返回的 TwiML。在这种情况下,这是因为您的 PHP 没有返回 TwiML,它正在尝试 make a call using the REST API。

    它应该返回一个带有嵌套&lt;Client&gt; 的&lt;Dial&gt;。您也可以使用帮助程序库来构建它。尝试将您的代码更改为:

    <?php
        include('./vendor/autoload.php');
        include('./config.php');
    
        $to = isset($_REQUEST["To"]) ? $_REQUEST["To"] : "";
        $to = str_replace("client:", "", $to);
    
        $from = isset($_REQUEST["From"]) ? $_REQUEST["From"] : "";
    
        use Twilio\Twiml;
    
        $response = new Twiml();
        $dial = $response->dial(['callerId' => $from]);
        $dial->client($to);
    
        echo $response;
    

    如果有帮助,请告诉我。

    【讨论】:

    • 感谢您的回复,我尝试了相同但仍然相同的错误,看看我上面更新的代码。
    • 您是否能够向您的 PHP 应用程序发出请求并查看返回的 XML 内容?这可能有助于指出错误所在。
    • 呸,我刚刚看到我的错误。等等,需要更新答案中的代码。
    • 好的,已更正。它在$dial 附近。再看看,让我知道这是否有效。
    • 是的,非常感谢您提供的信息
    【解决方案2】:

    第 1 步。在名称中您必须传递用户的名称(任何您想要的)

    第 2 步。您需要使用 3 个参数生成令牌

    步骤 3. 你需要创建 VoiceGrant 的对象

    第 4 步。您需要传递 Id

    第 5 步。您需要设置从 twilio 生成的 PUSH 通知 ID

    $name = $this->input->post('name');
                //$PUSH_CREDENTIAL_SID = 'CRaf1a66dd4a7656876e16c7820ef5c01e';
                 $outgoingApplicationSid = 'APf9b1b789ba690b8789d95a42511f2018';
                  // choose a random username for the connecting user
                 $identity = $name;
                 // Create access token, which we will serialize and send to the client
    
    
                 $token = new AccessToken(
                 $this->twilioAccountSid,
                 $this->twilioApiKey,
                 $this->twilioApiSecret,
                 3600,
                 $identity
                  );
              //     $chatGrant = new ChatGrant( $pushCredentialSid= "CRaf1a66dd4a7656876e16c7820ef5c01e");
              //
              // print_r($chatGrant);die;
                 // Create Chat grant
                 // $voiceGrant = new VoiceGrant($serviceSid = 'IS840a7e5f64634ab6bf179c3f8b0adfc4',$pushCredentialSid = 'CRaf1a66dd4a7656876e16c7820ef5c01e');
                 $voiceGrant = new VoiceGrant();
                 $voiceGrant->setOutgoingApplicationSid($outgoingApplicationSid);
    
                 // Optional: add to allow incoming calls
                 $voiceGrant->setIncomingAllow(true);
    
                 $voiceGrant->setPushCredentialSid('CRaf1a66dd4a7656876e16c7820ef5c01e');
    
    
                 // Add grant to token
                 $token->addGrant($voiceGrant);
    
                 // render token to string
                $voice_token = $token->toJWT();
                 if($voice_token){
                    $data['token'] = $voice_token;
                     $this->response = array('status'=>1,'data'=>$data);
                 }else{
                     $this->response = array('status'=>0,'message'=>'Not found');
                 }
    

    【讨论】:

    • 请检查步骤
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-16
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多