0

When i try to pass param from my application using [TwilioVoice Call] method i am not able to get those param on twiML application. but when i try to pass same data from POSTMAN with FormData its working fine and also successfully able to create call.

Would you please help me how can i use param passed from my iOS application into twiML

TwiML Application in PHP :

<?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 Objective-C :

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

Twilio Error Log when i try to pass param from iOS

Warning - 13224 Dial: Twilio does not support calling this number or the number is invalid

enter image description here

Reference TwiML Application Code

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

PinkeshGjr
  • 8,460
  • 5
  • 41
  • 56

2 Answers2

1

Twilio developer evangelist here.

The 12100 error comes from Twilio not being able to parse the TwiML returned from your server. In this case, it is because your PHP is not returning TwiML, it's trying to make a call using the REST API.

It should return a <Dial> with a nested <Client>. You can build this up using the helper library too. Try changing your code to this:

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

Let me know if that helps.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • thanks for the reply, i have tried same but still same error, take a look at my updated code above. – PinkeshGjr Feb 26 '18 at 05:47
  • Are you able to make a request to your PHP application and see what XML is being returned? That might help point to where the error is. – philnash Feb 26 '18 at 05:51
  • Bah, I've just seen my error. Hold on, need to update the code in the answer. – philnash Feb 26 '18 at 05:51
  • Ok, corrected it. It was around the `$dial`. Take another look and let me know if that works. – philnash Feb 26 '18 at 05:52
  • Got another error please take look i have added more detail logs so that will help find issue. – PinkeshGjr Feb 26 '18 at 06:09
  • Thanks for adding the screenshot. The issue is that the parameters being sent are `To` and `From`, but you are trying to extract `to` and `from`. Parameters are case sensitive. So if you update your PHP to use `To` and `From` it should work. You can use `$_REQUEST` rather than checking for `$_GET` and `$_POST` too. I'll update my answer too. – philnash Feb 26 '18 at 06:23
  • thanks for the quick response i got this error "Warning - 13224 Dial: Twilio does not support calling this number or the number is invalid". updated my question for the same – PinkeshGjr Feb 26 '18 at 06:34
  • Ah, I should have seen this coming. You don't need the `client:` prefix inside the ``. Try string replacing `"client:"` from `$to`. I'll update my answer again too. – philnash Feb 26 '18 at 06:37
  • thank you so much for the help, now i am successfully able to connect call and its really working fine, twilio dashboard still show this error "Error - 52131 Invalid APNs credentials" even push notification is working well – PinkeshGjr Feb 26 '18 at 06:56
  • Sounds like you're sorted then. Great to hear! If you continue to have a problem with APNS credentials then do ask another question and we can try to get to the bottom of that. – philnash Feb 26 '18 at 06:58
  • 1
    yes sure thank you so much for the kind of information – PinkeshGjr Feb 26 '18 at 06:59
0

Step 1. In the name you have to pass name of the user(any thing you want)

Step 2. You need to generate token using 3 parameters

Step 3. You need to create object of VoiceGrant

Step 4. You need to pass Id

Step 5. You need to set PUSH notification Id generate from twilio

$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');
             }
mechnicov
  • 12,025
  • 4
  • 33
  • 56