Tertarik mengembangkan aplikasi Voip dengan PHP, gunakan OzekiPhone


Tertarik mengembangkan aplikasi Voip dengan PHP, gunakan OzekiPhone

PHP VoIP developers 101


Part 1: PHP example on sending SMS, making VoIP calls

If you are unsure how to use the Ozeki Phone System XE for your PHP application, read this short guide. After reading this you should be able to send and recieve SMS messages, voice calls and make your very own projects.

Part 2: PHP example on recording VoIP calls, call routing

1. What you need

2. Get started

Overview

HTTP API enables you to get information from the PBX in real time and to control calls with HTTP requests. Take a look at how it works through the example of Call command. Call command can be used to initiate a voice call. It makes an API extension to call a number and do tasks with the call. The tasks are declared in an OzML response document as seen in Figure 1.


Figure 1 - How the Call command works

Step 1: Create a call using a HTTP request, for example:


Step 2: Accept the CallConnected request from Ozeki Phone System XE on your webserver and return an XML to handle the call. Example request sent by Ozeki Phone System XE PBX to your webserver: http://yoursite.com/callconnected.php

OzML example response returned by callconnected.php:

  1. <Response>
  2. <Delay>1</Delay>
  3. <Speak>Congratulations, this is your first OzML Response command.</Speak>
  4. <Delay>2</Delay>
  5. <Speak>Have a nice day!</Speak>
  6. </Response>

To send a test response to a call connected request in a simple manner using the tester, fill out the Response OzML field. You can choose from Example OzMLs or write your own one.

If you want to use HTTP API, first install a webserver (like Apache). For detailed setup instructions, take a look at our step-by-step guide.

Connecting Apache 2.2 and PHP 5.4

First you need to download PHP 5.4.8 . When you downloaded the zip file, unpack it. Preferably, do not contain any spaces in the path, because it can lead mistakes easily. After unpacking .reg extension files, they needed to be run. Then rename php.ini-production file to php.ini.

Afterwards we open httpd.conf file for editing, with a text editor. Since you unpacked files in C:/Program_Files/PHP, you can find it in conf folder in the main directory of Apache. Now, add the next entries at the end of that file.

  1. PHPIniDir "C:/Program_Files/PHP/"
  2. LoadModule php5_module "C:/Program_Files/PHP/php5apache2_2.dll"

If you are ready, insert the next row under <IfModule mime_module> entry.

  1. AddType application/x-httpd-php .php

Finally rename index.html file (found in htdocs folder in Apache) to index.php.

Now you need to install an API extension in the Ozeki Phone System XE in order to receive calls and SMS messages. Find out how to install a new API extension.

3. Receive incoming voice calls

If your webserver is working, API extension notifications can be added by http API. With these, you can handle your incoming calls. You can choose different recorded text to different extensions. The easiest way is defining the text in an OzML file. So, when an extension receives a call, the previously given text will be read too. As a result, the file needs to be available.

With Speak tag you can specify which text will be read.

  1. <Speak>Congratulations, this is your first OZML Response command.</Speak>

You can use <Delay> for pausing the reading. It postpones the reading by 1 sec.

  1. <Delay>1</Delay>

It is possible to play a wav or mp3 file when there is an incoming call. You can define with <Play> tag. You can also give an URL here.

  1. <Play Repeat = true>c:testsound.wav</Play>

You can use <BlindTransfer> for forwarding calls. So calls are forward to the desired extension.

  1. <BlindTransfer>101</BlindTransfer>

You can send SMS messages with the next tag.

  1. <SendSms recipient="45026467">Hello from Ozeki Phone System XE! </SendSms>

It is possible to handle informations from the incoming calls with using <UserInput> tag. With timeout attribute you can decide for how long the caller can answer. And with Repeat you can decide whether this time is over, text will be read again or not.

  1. <UserInput timeout="10" repeat="true"></UserInput >

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <Response>
  3. <Delay>1</Delay>
  4. <UserInput timeout="10" repeat="true">
  5. <InitialCommands>
  6. <Speak>Welcome to the Ozeki Phone System XE IVR.</Speak>
  7. <Speak>To send an SMS, press 1.</Speak>
  8. <Speak>To hear some more information, press 2.</Speak>
  9. <Speak>To transfer the call to another number, press 3.</Speak>
  10. </InitialCommands>
  11. <Inputs>
  12. <Input key="1">
  13. <Speak>A test SMS will be sent.</Speak>
  14. <SendSms recipient="45026467">Hello from Ozeki Phone System XE!</SendSms>
  15. </Input>
  16. <Input key="2">
  17. <Speak>You pressed button 2. For more information on OZML syntax, visit www.ozekiphone.com</Speak>
  18. </Input>
  19. <Input key="3">
  20. <BlindTransfer>101</BlindTransfer>
  21. <Speak>Sorry, but blind transfer failed to extension 101. Please setup an extension in the system.</Speak>
  22. </Input>
  23. </Inputs>
  24. </UserInput>
  25. <Speak>Good bye.</Speak>
  26. </Response>

Code example 1 - PHP codes to answer an incoming call

Commands sent by the caller can be initialized by using <InitialCommands> tag.

  1. <InitialCommands>
  2. <Speak>Welcome to the Ozeki Phone System XE IVR.</Speak>
  3. <Speak>To send an SMS, press 1.</Speak>
  4. <Speak>To hear some more information, press 2.</Speak>
  5. <Speak>To transfer the call to another number, press 3.</Speak>
  6. </InitialCommands>

Code example 2 - PHP codes to initialize commands

Inside <Inputs> tag, you can decide different interactions to different inputs, sent by the caller. Situations can be selected by <Input> tag.

  1. <Inputs>
  2. <Inputs>
  3. <Input key="1">
  4. <Speak>A test SMS will be sent.</Speak>
  5. <SendSms recipient="45026467">Hello from Ozeki Phone System XE!</SendSms>
  6. </Input>
  7. <Input key="2">
  8. <Speak>You pressed button 2. For more information on OZML syntax, visit www.ozekiphone.com</Speak>
  9. </Input>
  10. <Input key="3">
  11. <BlindTransfer>101</BlindTransfer>
  12. <Speak>Sorry, but blind transfer failed to extension 101. Please setup an extension in the system.</Speak>
  13. </Input>
  14. </Inputs>

Code example 3 - PHP codes to different inputs

This next example PHP script uses an SQL connection to connect to a database and query information about the customer who initated the call. The script uses the 'Caller' parameter from the HTTP request originating from the Ozeki Phone System XE to run an SQL SELECT query statement on the database. If the query was successfull, the OzML response will contain the full name of the customer, therefore making the response more interactive and personalized. Please change the ozekixepbx.ip text to the ip address where the Ozeki Phone System XE is installed. On the yoursite.com the address should be that where the sample applications are running.

  1. <?php
  2. $con=mysqli_connect("ozekixepbx.ip","mysql.user","66GkjOSDBd","customers");
  3. $callerId = $_REQUEST['Caller'];
  4. $date = new DateTime();
  5. $now = $date->format('Y-m-d H:i:s');
  6. //Failed to connent to database. Return OzML Response with the original caller id
  7. }
  8. else {
  9. $sqlQuery = $con->prepare('SELECT FullName FROM customers.customerentries WHERE CallerId = ?');
  10. $sqlQuery->bind_param('s', $callerId);
  11. $sqlQuery->execute();
  12. $result = $sqlQuery->get_result();
  13. $row = $result->fetch_assoc();
  14. if($row) {
  15. $callerId = $row["FullName"];
  16. }
  17. }
  18. print <<<END
  19. <Response>
  20. <Delay>1</Delay>
  21. <Speak>Good day $callerId! You have called our customer support hotline at $now.</Speak>
  22. <Speak>Your call has been noted, our assistans will call you back shortly.</Speak>
  23. <Delay>1</Delay>
  24. <Speak>For more information, visit our website.</Speak>
  25. </Response>
  26. END;
  27. mysqli_close($con);
  28. ?>

Code example 4 - PHP codes to different inputs

4. Make outgoing voice calls

Making an outgoing call is only possible with the command above. After making a connection, specified OzML file (shows in the URL) will be read too. You can also choose PHP file, which is generate the relevant XML file. You can give the called number with Dialled. ApiExtension is stands for that extension with what you can make a call.

	  http://ozekixepbx.ip:7780/?command=Call&Dialed=100  &ApiExtension=9997&Url=http://yoursite.com/speak.xml	  

5. Receive SMS message

Receiving SMS messages, like receiving voice calls, is possible with Api Extension notification. At the URL of Api Extension Notification, Incoming Message URL shows the file with http report generated by the incoming message. At the http response you can find the sender, recipient, identity of SMS and API extension, which received the text message.

6. Send SMS message

To send an SMS you can use the command above. ApiExtension is given the extension from which you want to send an SMS. You can edit your text in Message section. Delivery signs, provided by the supplier, are stored onto a file, which was given in the URL. Http request shows the ID of the previously sent SMS, so you can quote it later.

	  http://ozekixepbx.ip:7780/?command=SendSms&ApiExtension=9997&Recipient=  %2b061554670&Message=Hello+world&DeliveryReportUrl=http://yoursite.com/smsdelivered.php	  

7. Create a more advanced project

The Ozeki Phone System XE offers a lot more options for PHP developers. You can interact with existing calls, control and configure the PBX, you can introduce new communication techniques and media formats. 
For more infromation check out: HTTP API Online Manual

Part 2: PHP example on recording VoIP calls, call routing

If you have any questions or need assistance, please contact us at  info@ozekiphone.com

Dig deeper!
People who read this also read...

Popular posts from this blog

Dunia Aplikasi OpenSource

Mengenal Fungsi Dan Komponen Panel Listrik

Membangun Ruang Server (1)