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.
1. What you need
- A text editor (for example Notepad++)
- Ozeki Phone System XE installed on your PC (Download now)
- A connected softphone
- A connected SMS service
2. Get started
- Create an API extension in Ozeki Phone System XE
- Create a text file saved as .php
- Copy-paste your php file into the www folder of the webserver
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.
Step 1: Create a call using a HTTP request, for example:
Figure 1 - How the Call command works
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:
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.
If you are ready, insert the next row under <IfModule mime_module> entry.
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.
You can use <Delay> for pausing the reading. It postpones the reading by 1 sec.
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.
You can use <BlindTransfer> for forwarding calls. So calls are forward to the desired extension.
You can send SMS messages with the next tag.
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.
Commands sent by the caller can be initialized by using <InitialCommands> tag.
Inside <Inputs> tag, you can decide different interactions to different inputs, sent by the caller. Situations can be selected by <Input> tag.
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.
4. Make outgoing voice callsMaking 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.
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 messageTo 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.
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
If you have any questions or need assistance, please contact us at firstname.lastname@example.org
People who read this also read...