Coder Social home page Coder Social logo

plivo-php's Introduction

plivo-php

UnitTests

The Plivo PHP SDK makes it simpler to integrate communications into your PHP applications using the Plivo REST API. Using the SDK, you will be able to make voice calls, send SMS and generate Plivo XML to control your call flows.

Supported PHP Versions: This SDK works with PHP 7.3+.

Installation

To install Composer

Globally in Mac

  1. Download the latest version of Composer.

  2. Run the following command in Terminal:

     $ php ~/Downloads/composer.phar --version
    
  3. Run the following command to make it executable:

     $ cp ~/Downloads/composer.phar /usr/local/bin/composer
     $ sudo chmod +x /usr/local/bin/composer
     $ Make sure you move the file to bin directory.
    
  4. To check if the path has /usr/local/bin, use

     $ echo $PATH
    

    If the path is different, use the following command to update the $PATH:

     $ export PATH = $PATH:/usr/local/bin
     $ source ~/.bash_profile 
    
  5. You can also check the version of Composer by running the following command:

     $ composer --version.       
    

Globally in Linux

  1. Run the following command:

     $ curl -sS https://getcomposer.org/installer | php
    
  2. Run the following command to make the composer.phar file as executable:

     $ chmod +x composer.phar
    
  3. Run the following command to make Composer globally available for all system users:

     $ mv composer.phar /usr/local/bin/composer
    

Windows 10

  1. Download and run the Windows Installer for Composer.

    Note: Make sure to allow Windows Installer for Composer to make changes to your php.ini file.

  2. If you have any terminal windows open, close all instances and open a fresh terminal instance.

  3. Run the Composer command.

     $ composer -V
    

Steps to install Plivo Package

  • To install the stable release, run the following command in the project directory:

      $ composer require plivo/plivo-php
    
  • To install a specific release, run the following command in the project directory:

      $ composer require plivo/plivo-php:4.14.0
    
  • To test the features in the beta release, run the following command in the project directory:

      $ composer require plivo/plivo-php:v4.2-beta1
    
  • Alternatively, you can download this source and run

      $ composer install
    

This generates the autoload files, which you can include using the following line in your PHP source code to start using the SDK.

<?php
require 'vendor/autoload.php'

Getting started

Authentication

To make the API requests, you need to create a RestClient and provide it with authentication credentials (which can be found at https://console.plivo.com/dashboard/).

We recommend that you store your credentials in the PLIVO_AUTH_ID and the PLIVO_AUTH_TOKEN environment variables, so as to avoid the possibility of accidentally committing them to source control. If you do this, you can initialise the client with no arguments and it will automatically fetch them from the environment variables:

<?php
require 'vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient();

Alternatively, you can specifiy the authentication credentials while initializing the RestClient.

<?php
require 'vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient("<auth_id>", "<auth_token>");

The Basics

The SDK uses consistent interfaces to create, retrieve, update, delete and list resources. The pattern followed is as follows:

<?php
$client->resources->create($params) # Create
$client->resources->get($id) # Get
$client->resources->update($id, $params) # Update
$client->resources->delete($id) # Delete
$client->resources->list() # List all resources, max 20 at a time

You can also use the resource directly to update and delete it. For example,

<?php
$resource = $client->resources->get($id)
$resource->update($params) # update the resource
$resource->delete() # Delete the resource

Also, using $client->resources->list() would list the first 20 resources by default (which is the first page, with limit as 20, and offset as 0). To get more, you will have to use limit and offset to get the second page of resources.

Examples

Send a message

<?php
require 'vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient();
$message_created = $client->messages->create([ 
        "src" => "+14156667778", 
        "dst" => "+14156667777", 
        "text"  =>"Hello, this is a sample text from Plivo"
]);

Make a call

<?php
require 'vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient();
$call_made = $client->calls->create(
    '+14156667778',
    ['+14156667777'],
    'https://answer.url'
);

Lookup a number

<?php
require 'vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient("<auth_id>", "<auth_token>");
$response = $client->lookup->get("<number-goes-here>");

Generate Plivo XML

<?php
require 'vendor/autoload.php';
use Plivo\XML\Response;

$response = new Response();
$response->addSpeak('Hello, world!');
echo($response->toXML());

This generates the following XML:

<?xml version="1.0" encoding="utf-8"?>
<Response>
  <Speak>Hello, world!</Speak>
</Response>

Run a PHLO

<?php
/**
 * Example for API Request
 */
require 'vendor/autoload.php';
use Plivo\Resources\PHLO\PhloRestClient;
use Plivo\Exceptions\PlivoRestException;
$client = new PhloRestClient("<auth_id>", "<auth_token>");
$phlo = $client->phlo->get("<phlo_id>");
try {
    $response = $phlo->run(["field1" => "value1", "field2" => "value2"]); // These are the fields entered in the PHLO console
    print_r($response);
} catch (PlivoRestException $ex) {
    print_r($ex);
}
?>

WhatsApp Messaging

Plivo's WhatsApp API allows you to send different types of messages over WhatsApp, including templated messages, free form messages and interactive messages. Below are some examples on how to use the Plivo Go SDK to send these types of messages.

Templated Messages

Templated messages are a crucial to your WhatsApp messaging experience, as businesses can only initiate WhatsApp conversation with their customers using templated messages.

WhatsApp templates support 4 components: header , body, footer and button. At the point of sending messages, the template object you see in the code acts as a way to pass the dynamic values within these components. header can accomodate text or media (images, video, documents) content. body can accomodate text content. button can support dynamic values in a url button or to specify a developer-defined payload which will be returned when the WhatsApp user clicks on the quick_reply button. footer cannot have any dynamic variables.

Example:

<?php
require 'vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient("<auth_id>","<auth_token>");

$template = '{ 
            "name": "template_name",
            "language": "en_US",
            "components": [
                {
                    "type": "header",
                    "parameters": [
                        {
                            "type": "media",
                            "media": "https://xyz.com/s3/img.jpg"
                        }
                    ]
                },
                {
                    "type": "body",
                    "parameters": [
                        {
                            "type": "text",
                            "text": "WA-Text"
                        }
                    ]
                }
            ]
          }';

$response = $client->messages->create([  
        "src" => "+14156667778",
        "dst" => "+14156667777",
        "type"=> "whatsapp",
        "template"=> $template,
        "url"=> "https://foo.com/wa_status/"
]);
print_r($response);
?>

Free Form Messages

Non-templated or Free Form WhatsApp messages can be sent as a reply to a user-initiated conversation (Service conversation) or if there is an existing ongoing conversation created previously by sending a templated WhatsApp message.

Free Form Text Message

Example:

<?php
require 'vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient("<auth_id>","<auth_token>");
$response = $client->messages->create([  
        "src"=> "+14156667778",
        "dst"=> "+14156667777",
        "text"=> "Hello, this is sample text",
        "type"=> "whatsapp",
        "url"=> "https://foo.com/wa_status/"
]);
print_r($response);
?>

Free Form Media Message

Example:

<?php
require 'vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient("<auth_id>","<auth_token>");
$response = $client->messages->create([  
        "src"=> "+14156667778",
        "dst"=> "+14156667777",
        "text"=> "Hello, this is sample text",
        "type"=> "whatsapp",
        "media_urls"=> ["https://sample-videos.com/img/Sample-png-image-1mb.png"],
        "url"=> "https://foo.com/wa_status/"
]);
print_r($response);
?>

Interactive Messages

This guide shows how to send non-templated interactive messages to recipients using Plivo’s APIs.

Quick Reply Buttons

Quick reply buttons allow customers to quickly respond to your message with predefined options.

Example:

<?php
require '/usr/src/app/vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient("<auth_id>","<auth_token>");

$interactive = '{
        "type": "button",
        "header": {
            "type": "media",
            "media": "https://xyz.com/s3/img.jpg"
        },
        "body": {
            "text": "Make your selection"
        },
        "action": {
            "buttons": [
                {
                    "title": "Click here",
                    "id": "bt1"
                },
                {
                    "title": "Know More",
                    "id": "bt2"
                },
                {
                    "title": "Request Callback",
                    "id": "bt3"
                }
            ]
        }
    }';

$response = $client->messages->create([
        "src"=> "+14156667778",
        "dst"=> "+14156667777",
        "type"=> "whatsapp",
        "interactive"=> $interactive
]);
print_r($response);
?>

Interactive Lists

Interactive lists allow you to present customers with a list of options.

Example:

<?php
require '/usr/src/app/vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient("<auth_id>","<auth_token>");

$interactive = '{
        "type": "list",
        "header": {
            "type": "text",
            "text": "Welcome to Plivo"
        },
        "body": {
            "text": "You can review the list of rewards we offer"
        },
        "footer": {
            "text": "Yours Truly"
        },
        "action": {
            "buttons": [{
                "title": "Click here"
            }],
            "sections": [
                {
                    "title": "SECTION_1_TITLE",
                    "rows": [
                        {
                            "id": "SECTION_1_ROW_1_ID",
                            "title": "SECTION_1_ROW_1_TITLE",
                            "description": "SECTION_1_ROW_1_DESCRIPTION"
                        },
                        {
                            "id": "SECTION_1_ROW_2_ID",
                            "title": "SECTION_1_ROW_2_TITLE",
                            "description": "SECTION_1_ROW_2_DESCRIPTION"
                        }
                    ]
                },
                {
                    "title": "SECTION_2_TITLE",
                    "rows": [
                        {
                            "id": "SECTION_2_ROW_1_ID",
                            "title": "SECTION_2_ROW_1_TITLE",
                            "description": "SECTION_2_ROW_1_DESCRIPTION"
                        },
                        {
                            "id": "SECTION_2_ROW_2_ID",
                            "title": "SECTION_2_ROW_2_TITLE",
                            "description": "SECTION_2_ROW_2_DESCRIPTION"
                        }
                    ]
                }
            ]
        }
    }';

$response = $client->messages->create(
        [
                "src"=> "+14156667778",
                "dst"=> "+14156667777",
                "type"=> "whatsapp",
                "interactive"=> $interactive
        ]
);
print_r($response);
?>

Interactive CTA URLs

CTA URL messages allow you to send links and call-to-action buttons.

Example:

<?php
require '/usr/src/app/vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient("<auth_id>","<auth_token>");

$interactive = '{
      "type": "cta_url",
        "header": {
            "type": "media",
            "media": "https://xyz.com/s3/img.jpg"
        },
        "body": {
            "text": "Know More"
        },
        "footer": {
            "text": "Plivo"
        },
        "action": {
            "buttons": [
                {
                    "title": "Click here",
                    "cta_url": "https:plivo.com"
                }
            ]
        }
    }';

$response = $client->messages->create([
        "src"=> "+14156667778",
        "dst"=> "+14156667777",
        "type"=> "whatsapp",
        "interactive"=> $interactive
]);
print_r($response);
?>

Location Messages

This guide shows how to send templated and non-templated location messages to recipients using Plivo’s APIs.

Templated Location Messages

Example:

<?php
require '/usr/src/app/vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient("<auth_id>","<auth_token>");

$template = '{
        "name": "plivo_order_pickup",
        "language": "en_US",
        "components": [
            {
                "type": "header",
                "parameters": [
                    {
                        "type": "location",
                        "location": {
                            "longitude": "122.148981",
                            "latitude": "37.483307",
                            "name": "Pablo Morales",
                            "address": "1 Hacker Way, Menlo Park, CA 94025"
                        }
                    }
                ]
            }
        ]
    }';

$response = $client->messages->create([
        "src"=> "+14156667778",
        "dst"=> "+14156667777",
        "type"=> "whatsapp",
        "template"=> $template
]);
print_r($response);
?>

Non-Templated Location Messages

Example:

<?php
require '/usr/src/app/vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient("<auth_id>","<auth_token>");

$location = '{
        "longitude": "122.148981",
        "latitude": "37.483307",
        "name": "Pablo Morales",
        "address": "1 Hacker Way, Menlo Park, CA 94025"
    }';

$response = $client->messages->create([
        "src"=> "+14156667778",
        "dst"=> "+14156667777",
        "type"=> "whatsapp",
        "location"=> $location
]);
print_r($response);
?>

More examples

More examples are available here. Also refer to the guides for configuring the PHP laravel to run various scenarios & use it to test out your integration in under 5 minutes.

Reporting issues

Report any feedback or problems with this version by opening an issue on Github.

Local Development

Note: Requires latest versions of Docker & Docker-Compose. If you're on MacOS, ensure Docker Desktop is running.

  1. Export the following environment variables in your host machine:
export PLIVO_AUTH_ID=<your_auth_id>
export PLIVO_AUTH_TOKEN=<your_auth_token>
export PLIVO_API_DEV_HOST=<plivoapi_dev_endpoint>
export PLIVO_API_PROD_HOST=<plivoapi_public_endpoint>
  1. Run make build. This will create a docker container in which the sdk will be setup and dependencies will be installed.

The entrypoint of the docker container will be the setup_sdk.sh script. The script will handle all the necessary changes required for local development.

  1. The above command will print the docker container id (and instructions to connect to it) to stdout.
  2. The testing code can be added to <sdk_dir_path>/php-sdk-test/test.php in host
    (or /usr/src/app/php-sdk-test/test.php in container)
  3. The sdk directory will be mounted as a volume in the container. So any changes in the sdk code will also be reflected inside the container.

To use the local code in the test file, import the sdk in test file using:
require /usr/src/app/vendor/autoload.php
(Local sdk code will be mounted at /usr/src/app inside the container and vendor directory will be created by setup script while installing dependencies).

  1. To run test code, run make run CONTAINER=<cont_id> in host.
  2. To run unit tests, run make test CONTAINER=<cont_id> in host.

<cont_id> is the docker container id created in 2. (The docker container should be running)

Test code and unit tests can also be run within the container using make run and make test respectively. (CONTAINER argument should be omitted when running from the container)

plivo-php's People

Contributors

abinaya-shunmugavel avatar abrolnalin avatar ajay-kg avatar ajay-plivo avatar anindya-plivo avatar codertech120386 avatar eniyavan-muruganantham-plivo avatar gunjan01 avatar huzaif-plivo avatar kalyan-plivo avatar kapilp93 avatar kaushikdas-plivo avatar koushik-ayila avatar kowshik-plivo avatar kritarth-plivo avatar kunal-plivo avatar manas-plivo avatar manjunath-plivo avatar mohsin-plivo avatar narayana-plivo avatar nirmitijain avatar nixonsam avatar rajneeshkatkam-plivo avatar renoldthomas-plivo avatar rex-plivo avatar saksham-plivo avatar saurabhnewatiya-plivo avatar shubham-plivo avatar sreyantha-plivo avatar varshit97plivo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

plivo-php's Issues

Not pulling sms numbers

When attempting to pull sms numbers with the latest, nothing comes back.

    $plivo_sms = new RestClient($plivo['auth_id'], $plivo['auth_token']);

    // returns 0 results
    $r = $plivo_sms->getPhoneNumbers()->getList('GB', array(
         "type" => "mobile",
         "limit" => 10,
         "offset" => 0
    ));

    // returns 0 results
    $r = $plivo_sms->getPhoneNumbers()->getList('GB', array(
         "services" => "sms",
         "limit" => 10,
         "offset" => 0
    ));

     // returns 0 results
    $r = $plivo_sms->getPhoneNumbers()->getList('GB', array(
         "type" => "mobile",
         "services" => "sms",
         "limit" => 10,
         "offset" => 0
    ));

    // returns 10 results all 800 numbers with smsEnabled: false
    $r = $plivo_sms->getPhoneNumbers()->getList('GB', array(
         "limit" => 10,
         "offset" => 0
    ));

This is on top of the error described in #128.

I have tried multiple locales to make sure it wasn't a number availability issue. GB, US, CA, MX, and others are all returning 0 items. Perhaps the error is causing this though, I am unsure.

Code not working . I need help asap .

function plivo_sms_send2($src,$dst,$text){
require APPPATH.'libraries'.DIRECTORY_SEPARATOR.'plivo-php'.DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'autoload.php';
//use Plivo\RestAPI;
$ci = get_instance();
$ci->load->model('Admin_model');
$data = $ci->Admin_model->providers(5);
foreach($data as $r){
$AUTH_ID = $r['api_secret_key'];
$AUTH_TOKEN = $r['api_token'];
}
$p = new RestAPI($AUTH_ID, $AUTH_TOKEN);
$params = array(
'src' => $src, // Sender's phone number with country code
'dst' => $dst, // Receiver's phone number with country code
'text' => $text // Your SMS text message
);
$response = $p->send_message($params);
echo "Response : ";
print_r($response['response']);
echo "
Api ID : {$response['response']['api_id']}
";
echo "Message UUID : {$response['response']['message_uuid'][0]}
";

}

The error i get

Parse error: syntax error, unexpected 'use' (T_USE) in /var/www/sms.supreme-data.com/html/application/helpers/plivo_helper.php on line 37
A PHP Error was encountered

Severity: Parsing Error

Message: syntax error, unexpected 'use' (T_USE)

Filename: helpers/plivo_helper.php

Line Number: 37

Backtrace:

guzzlehttp/guzzle v3.8.1 ?

Why are you "hard"-setting such an old version of guzzle? It's at v6.x right now.
A lot of other libs depend on guzzle also, and the plivo lib is unnecessarily limiting this version.

Only shows 2 messages in list()

So everything was fine with 4.1 and PHP 5.5.9. Now that I am using 4.3 and PHP 7.3.7 the api is returning weird results. I have another ticket about the parameters but to be more specific to this issue:

If I use $response = $client->messages->list() I should get a list of all logs in Plivo, I used to no problem. Now this just gives me a specific 2 logs and nothing else. No matter what I do this is all I get back, if I include parameters is breaks completely like my other ticket describes. What is going on?

Web SDK- Hang Up Issue

When you call a telephone number and the user on the phone(landline or mobile) hangs up the phone. Plivo is not recognizing the disconnection of the line and stays open.

Problem with plivo/php-sdk 4.1.0

Hello,
I installed the last version of plivo php-sdk from composer (4.1.0).

When I run the example I receive this error:
PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function Plivo\Resources\Call\CallInterface::create(), 3 passed in [...] on line 17 and at least 4 expected in [...]/vendor/plivo/php-sdk/src/Plivo/Resources/Call/CallInterface.php:70

$client = new \Plivo\RestClient($id, $token);

try {
    $response = $client->calls->create(
        $cellular_from,
        ["+39XXXXXXXX"],
        "sms test"
    );
}
catch (\Exception $e) {
    \print_r($e);
}

If I downgrade to 4.0.0-beta1 this code works correctly.
Anyone can help me?

Thanks
Alex

Error in Plivo Application undefined index "log_incoming_messages"

There is an error coming from Plivo lib core files. The error is in constructor of Application Class. where $properties variable is constructed from response. Error is undefined index ["log_incoming_messages"]. Originally the response contains singular while in lib its accessed as plural with. The error is resolved by removing s from ["log_incoming_messages"] to ["log_incoming_message"]. now the lines looking as

'logIncomingMessages' => $response['log_incoming_messages'] x
'logIncomingMessages' => $response['log_incoming_message'] 👍

Client Error Response while sending SMS

I get the following error while trying to make a POST request to send message:

Client error response [status code] 400 [reason phrase] BAD REQUEST [url] https://api.plivo.com/v1/Account/{AUTH ID}/Message/

When you look at the trace, there's an exception being thrown by Guzzle. But there's no way to know what may be wrong with the request being made by Plivo.

Any idea how to solve this?

HTTP Error in Plivo_Confrence.php

Hello,
i don't know why i am getting this error on my localhost pc

Fatal error: Uncaught

HTTP_Request2_MessageException: Curl error: Received HTTP code 302 from proxy after CONNECT in D:\xampp\htdocs\plivo\HTTP\Request2\Adapter\Curl.php on line 177
Exception trace
#FunctionLocation
0HTTP_Request2_Adapter_Curl::wrapCurlError('Resource id #10')D:\xampp\htdocs\plivo\HTTP\Request2\Adapter\Curl.php:177
1HTTP_Request2_Adapter_Curl->sendRequest(Object(HTTP_Request2))D:\xampp\htdocs\plivo\HTTP\Request2.php:93 in D:\xampp\htdocs\plivo\HTTP\Request2\Adapter\Curl.php on line 149

Wrong declaration of Response::toXML()

A PHP Error was encountered

Severity: Runtime Notice

Message: Declaration of Response::toXML() should be compatible with Element::toXML($header = false)

Filename: plivo/plivo.php

Line Number: 768

Empty token throws wrong message

When initializing Rest API with empty $auth_token:
$client = new RestAPI($auth_id, $auth_token);

we get a wrong message:
no auth_id

By looking at the code I found bug at line 29 in plivo.php:

  •    if ((!isset($auth_id)) || (!$auth_token)) {
    
  •    if ((!isset($auth_id)) || (!$auth_id)) {
    

You should replace $auth_token with $auth_id.

Bypass SSL certificate verification with GuzzleHttp 6.x

Hi there,

Just a little workaround for those having the issue of the Error 60 regarding SSL certificate verification failure, when using send_message() function since updated Plivo to v1.1.0 making use of GuzzleHttp 6.1, and want to avoid SSL cert verification (ie : for local testing purpose)

I run into this issue today after updating my dev environment to the latest version of plivo and GuzzleHttp to 6.1.

I dont know if this can be implemented by plivo PHP team in a future release (by asking for a PR ?), but in case, I'm sharing it here...

So, at the begining of plivo.php (vendor/plivo/plivo.php if installed via composer), find this code :

private function request($method, $path, $params = array()) {
    $url = $this->api.rtrim($path, '/').'/';

    $client = new Client([
        'base_uri' => $url,
        'auth' => [$this->auth_id, $this->auth_token],
        'http_errors' => false
    ]);
    ...

and add support of optional "verify" parameter (defaults to true), like this :

private function request($method, $path, $params = array(), $sslVerif = true) {
    $url = $this->api.rtrim($path, '/').'/';

    $client = new Client([
        'base_uri' => $url,
        'auth' => [$this->auth_id, $this->auth_token],
        'http_errors' => false,
        'verify' => $sslVerif
    ]);
    ...

then, still in plivo.php file, modify the send_message() function to accept and handle the new optional $sslVerif parameter, as follows:

public function send_message($params = array(), $sslVerif = true) {
    return $this->request('POST', '/Message/', $params, $sslVerif);
}

From now, in your controller, if you want to avoid SSL certificate verification, you can add false parameter to send_message() call, like this:

$plivoAPI->send_message($params, false);

or keep verification active by either setting the parameter to true, or by just not sending it :

$plivoAPI->send_message($params, true); 
// or $plivoAPI->send_message($params);
//These two calls will work the same way as we put default value of $verify to true

You should keep in mind that modifying the lib is definitely not a "best practice", as you will lose your changes if you update or reinstall the lib. That's why I'm asking Plivo team if it would be possible to implement it in a future release.

Regards.
Khalil

Issue with API response

I installed Plivo PHP SDK using Composer and the requests are exectued correctly but the response from the API is really strange (see below). Works perfectly with CURL though.

Did this happen to someone else by any chance?

Code:
require 'composer/vendor/autoload.php'; use Plivo\RestClient; $client = new RestClient("XXX", "YYY"); try { $response = $client->numbers->list(); var_dump($response); } catch (PlivoRestException $ex) { // print_r(ex); }

Response:
object(Plivo\Resources\ResourceList)#36 (5) { ["client":protected]=> object(Plivo\BaseClient)#2 (3) { ["timeout":protected]=> NULL ["httpClientHandler":protected]=> object(Plivo\HttpClients\PlivoGuzzleHttpClient)#5 (3) { ["guzzleClient":protected]=> object(GuzzleHttp\Client)#6 (1) { ["config":"GuzzleHttp\Client":private]=> array(7) { ["handler"]=> object(GuzzleHttp\HandlerStack)#7 (3) { ["handler":"GuzzleHttp\HandlerStack":private]=> object(Closure)#14 (2) { ["static"]=> array(2) { ["default"]=> object(Closure)#12 (2) { ["static"]=> array(2) { ["default"]=> object(GuzzleHttp\Handler\CurlMultiHandler)#8 (5) { ["factory":"GuzzleHttp\Handler\CurlMultiHandler":private]=> object(GuzzleHttp\Handler\CurlFactory)#9 (2) { ["handles":"GuzzleHttp\Handler\CurlFactory":private]=> array(0) { } ["maxHandles":"GuzzleHttp\Handler\CurlFactory":private]=> int(50) } ["selectTimeout":"GuzzleHttp\Handler\CurlMultiHandler":private]=> int(1) ["active":"GuzzleHttp\Handler\CurlMultiHandler":private]=> NULL ["handles":"GuzzleHttp\Handler\CurlMultiHandler":private]=> array(0) { } ["delays":"GuzzleHttp\Handler\CurlMultiHandler":private]=> array(0) { } } ["sync"]=> object(GuzzleHttp\Handler\CurlHandler)#10 (1) { ["factory":"GuzzleHttp\Handler\CurlHandler":private]=> object(GuzzleHttp\Handler\CurlFactory)#11 (2) { ["handles":"GuzzleHttp\Handler\CurlFactory":private]=> array(1) { [0]=> resource(49) of type (curl) } ["maxHandles":"GuzzleHttp\Handler\CurlFactory":private]=> int(3) } } } ["parameter"]=> array(2) { ["$request"]=> string(10) "" ["$options"]=> string(10) "" } } ["streaming"]=> object(GuzzleHttp\Handler\StreamHandler)#13 (1) { ["lastHeaders":"GuzzleHttp\Handler\StreamHandler":private]=> array(0) { } } } ["parameter"]=> array(2) { ["$request"]=> string(10) "" ["$options"]=> string(10) "" } } ["stack":"GuzzleHttp\HandlerStack":private]=> array(4)
and it keeps going...

missing global namespace indicator

In this file
namespace Plivo\XML;
class Speak extends Element {

the __construct references mb_encode_numericentity without the \ to put it in the global namespace
should be $body = \mb_encode_numericentity($body, [0x80, 0xffff, 0, 0xffff]);

search_numbers from RestAPI

Method "search_numbers" in RestAPI calls up for AvailableNumber URL part, while by Plivo API docs it should be "PhoneNumber". So this method does not work as it should.

The SDK messes with the php $_SESSION

Somehow, when using the Plivo\RestClient to send a message, the $_SESSION variable gets messed up. Either the SDK is not using namespace in the $_SESSION or some other tinkering is done.
This conflicted with our authentication system.
We resorted to using plain curl_exec.

I would expect this not to happen.

Web SDK

It seems the Plivo Web SDK does not play audio when connected to a voicemail sometimes.

GuzzleHttp refrenced incorrectly?

I kept getting 500 errors on line 41 where it declares the new Client of the helper file. I changed line 5 from use GuzzleHttp\Client; to use Guzzle\Http\Client; to fix it, but now there are other errors with getting a response. Not sure but maybe I need to be using an older version of Guzzle or your code needs updated to support the newer version?

Messages doesn't allow parameters 4.3

Was working fine in 4.1, but since I upgraded I am not only getting the wrong amount of messages if left with out any parameters, but including some results in tons of errors. For instance:

$response = $client->messages->list( array( 'message_direction' => 'outbound', 'offset' => $offset, 'message_time__gte' => $fromTime, 'message_time__lte' => $toTime, ) );

Including any or all of those gives me:

[Wed Jul 24 17:19:49.965662 2019] [fcgid:warn] [pid 27461] [client 1.2.3.4.5.6] mod_fcgid: stderr: PHP Warning: Invalid argument supplied for foreach() in .../api/vendor/plivo/php-sdk/src/Plivo/Resources/Message/MessageInterface.php on line 86, referer: /history.php?log_id=19&type=phone

[Wed Jul 24 17:19:49.965675 2019] [fcgid:warn] [pid 27461] [client 1.2.3.4.5.6] mod_fcgid: stderr: PHP Notice: Undefined index: meta in .../api/vendor/plivo/php-sdk/src/Plivo/Resources/Message/MessageInterface.php on line 92, referer: history.php?log_id=19&type=phone

[Wed Jul 24 17:19:49.965678 2019] [fcgid:warn] [pid 27461] [client 1.2.3.4.5.6] mod_fcgid: stderr: PHP Fatal error: Uncaught TypeError: Argument 2 passed to Plivo\Resources\ResourceList::__construct() must be of the type array, null given, called in .../api/vendor/plivo/php-sdk/src/Plivo/Resources/Message/MessageList.php on line 24 and defined in .../api/vendor/plivo/php-sdk/src/Plivo/Resources/ResourceList.php:45, referer: history.php?log_id=19&type=phone

[Wed Jul 24 17:19:49.965681 2019] [fcgid:warn] [pid 27461] [client 1.2.3.4.5.6] mod_fcgid: stderr: Stack trace:, referer: history.php?log_id=19&type=phone

[Wed Jul 24 17:19:49.965683 2019] [fcgid:warn] [pid 27461] [client 1.2.3.4.5.6] mod_fcgid: stderr: #0 .../api/vendor/plivo/php-sdk/src/Plivo/Resources/Message/MessageList.php(24): Plivo\Resources\ResourceList->__construct(Object(Plivo\BaseClient), NULL, Array), referer: /history.php?log_id=19&type=phone

[Wed Jul 24 17:19:49.965686 2019] [fcgid:warn] [pid 27461] [client 1.2.3.4.5.6] mod_fcgid: stderr: #1 .../api/vendor/plivo/php-sdk/src/Plivo/Resources/Message/MessageInterface.php(92): Plivo\Resources\Message\MessageList->__construct(Object(Plivo\BaseClient), NULL, Array), referer: history.php?log_id=19&type=phone

[Wed Jul 24 17:19:49.965689 2019] [fcgid:warn] [pid 27461] [client 1.2.3.4.5.6] mod_fcgid: stderr: #2 [internal function]: Plivo\Resources\Message\MessageInterface->getList(Array), referer: history.php?log_id=19&type=phone

[Wed Jul 24 17:19:49.965692 2019] [fcgid:warn] [pid 27461] [client 1.2.3.4.5.6] mod_fcgid: stderr: #3 .../api/vendor/plivo/php-sdk/src/Plivo/Resources/ResourceInterface.php(65): call_user_func_array(Array, Array), referer: history.php?log_id=19&type=phone

[Wed Jul 24 17:19:49.965694 2019] [fcgid:warn] [pid 27461] [client 1.2.3.4.5.6] mod_fcgid: stderr: #4 /home/.../public_html/new/deliver in .../api/vendor/plivo/php-sdk/src/Plivo/Resources/ResourceList.php on line 45, referer: history.php?log_id=19&type=phone

Porblem, SMS with purchased number .

$client = new RestClient("xxxxx", "xxxx");
$message_created = $client->messages->create(
'purchased number', <---
[$number],
$message !== null ? $message . $digits : "Sem mensagem"
);

Does not display number purchased when sms arrives at destination.

Caught exception: Curl failed with error Failed to connect to 127.0.0.1: Permission denied

Hi,

I have installed Plivo on Centos with Freeswithch 1.4.26. When I am using example-call.php from web server then its showing error "Caught exception: Curl failed with error Failed to connect to 127.0.0.1: Permission denied " but when I am running directly on command then call i going to Freeswitch withour any error. I am running command like "php example-call.php".

Please guide me. Is anything I am missing?

Thanks
Uday.

Error running php plivo app

I get this Fatal error: Class 'Plivo\Response' not found in /home/licsy/ivrtugo.licsy.com/IvrFlow.php on line 14,
And one of the Plivo Support agents answer me this:

Hi ROIBots,

Please check whether you have installed the plivo helper in your directory.
If not, then the same can be installed using pip by running this command in the terminal from the directory you are working in -
'sudo pip install plivo'.
Once the plivo helper is installed the, Class 'Plivo\Response' will be found and you shall not receive the error anymore.

But composer install is all I need to install so my doubt is it is necessary to run pip Plivo install?

Regards,

Send message response missing api_id

The MessageCreateResponse Class and MessageInterface Class does not pass back "api_id" even though it is available in the $responseContents variable in MessageInterface->create() function. Also I did not see a way to get the response code anymore.

php 5.4 requirement

This isn't really an issue with the php or anything, just noticed on the Plivo website it was Plivo supports PHP >= 5.2, but notice the version of Guzzlehttp is 6.1.1, which requires at least php 5.4 or above...and might even be higher than that. Doesn't seem to work with php 5.3.10 in the project I am working on.

undefined index restriction

Here's the snippet from Plivo\Resources\PhoneNumber\PhoneNumber::__construct:
image

The problem is that there is no restriction and restrictionText in response:
image

X-Plivo-Signature-V2 and X-Plivo-Signature-V2-Nonce

X-Plivo-Signature-V2 and X-Plivo-Signature-V2-Nonce are not passed to the answer_url.

I checked for $_SERVER['HTTP_X-Plivo-Signature-V2'] and $_SERVER['HTTP_X-Plivo-Signature-V2-Nonce']. I even double checked using getallheaders().

I want to validate that the request is coming from Plivo before returning any sensitive data.

Please advise.

Use namespace and/or add prefix

User, Element, Response etc. are very common class names that are more likely to be named as such in the application so importing plivo would conflict IMHO

add get meta method

Can you add a meta getter to the \Plivo\Resources\ResourceList?
I need the pagination info.
/**
* @return array
*/
public function meta()
{
return $this->meta;
}

Undefined Index 'restriction' v4.3.3


$plivo_sms = new RestClient($plivo['auth_id'], $plivo['auth_token']);

$r = $plivo_sms->phonenumbers->list('GB');

This example taken directly from docs.

Undefined index: restriction in /vendor/plivo/plivo-php/src/Plivo/Resources/PhoneNumber/PhoneNumber.php on line 51

Undefined index: restriction_text in /vendor/plivo/plivo-php/src/Plivo/Resources/PhoneNumber/PhoneNumber.php on line 52

$params not passed to request method, in "buy_phone_number"

In order to support the app_id param for the buy phone number method, the method must pass trough $params to the private request method. It should be:

public function buy_phone_number($params = array()) {
   $number = $this->pop($params, "number");
   return $this->request('POST', '/PhoneNumber/'.$number.'/', $params);
}

Currently it is:

public function buy_phone_number($params = array()) {
   $number = $this->pop($params, "number");
   return $this->request('POST', '/PhoneNumber/'.$number.'/');
}

so the app_id is never POSTED to the API.

bug in delete number response

in file src/Plivo/Resources/Number/NumberInterface.php at line 147
the delete function is not returnning the instanse of the client object

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.