How to configure Plivo and a shared webhost

These are instructions on how to configure plivo on a shared webhost

Requirements:
1. Plivo account with a phone number
2. Shared webhost with SSH access

On your shared webhost:

  1. Log onto your remote webserver (mines is a shared webhost) via SSH. I used the software called Putty to SSH into my shared webhost.
  2.  Go to your root of your domain. Commands I used were CD
  3.  Now type ‘composer require plivo/plivo-php’

Copy the sample code from plivo. In this example we are going to edit the ‘Forward an Incoming SMS’. I copied the php code for this example.

<?php
    require 'vendor/autoload.php';
    use Plivo\Response;
    // Sender's phone numer
    $from_number = $_REQUEST["From"];
    // Receiver's phone number - Plivo number
    $to_number = $_REQUEST["To"];
    // The SMS text message which was received
    $text = $_REQUEST["Text"];
    // Output the text which was received, you could also store the text in a database.
    // echo("Message received - From $from_number, To: $to_number, Text: $text");
    // The phone number to which the SMS has to be forwarded
    $to_forward = '3333333333';
    $params = array(
        'src' => $to_number,
        'dst' => $to_forward
    );
    $body = $text;
    // Generate a Message XML with the details of
    // the reply to be sent.
    $r = new Response();
    $r->addMessage($body, $params);
    Header('Content-type: text/xml');
    echo($r->toXML());
?>

In the above code, you’ll edit line 13 to the number you want the SMS message to be sent to.

Save it with the extension php. eg. forwardsms.php

Next, we want to forward incoming voice calls to another phone number.  Copy the sample code from plivo ‘Forward an Incoming Call’. Again, I copied the php code for this example

<?php
    require 'vendor/autoload.php';
    use Plivo\Response;
    // Fetch the from_number from the URL
    $from_number = $_REQUEST['From'];
    $r = new Response();
    // Add Dial tag
    $params = array(
        'callerId' => $from_number # Caller ID
    );
    $d = $r->addDial($params);
    $number = "2222222222";
    $d->addNumber($number);
    Header('Content-type: text/xml');
    echo($r->toXML());
?>

In the above you’ll edit line 12 so that voice calls will be transferred to the number you entered.

Save it with the extension php. eg. forwardcalls.php

Now, upload the two files you created, in this example (forwardsms.php and forwardcalls.php) to your shared webhost.

Now configure plivo to read these two files.

Log onto your plivo account.

Click on ‘Applications’

Click ‘New Applications’

In ‘Application Name’ box, give your application a name. eg. hotlinebling

In ‘Message URL’ box put ‘http://yourdomain.com/forwardsms.php’ Obviously, yourdomain.com should be whatever your domain name is.

In ‘Answer URL’ box put ‘http://yourdomain.com/forwardcalls.php’

In ‘Hangup URL’ box put ‘http://yourdomain.com/forwardcalls.php’

Click ‘Create’ button

 

Next, configure the number to use this application.

Click on ‘Numbers’. Located at the top navigation in plivo

Select the phone that you want to use

In ‘Plivo App’ box, click on the down arrow and select the application that you created. In this example, hotlinebling will be listed.

In ‘Alias’ box, give it another name. Can be anything.

Click on ‘Update’ button