Asterisk send data to Web application

Can someone give me some advice. Our clients have existing web application, in their form you can input code and hit enter and display information of customer base on the inputted code, now the client want us, if there is incoming call, they want to display automatically the code and show the information of the customer.
can someone help me on this how to achieve or please advice me what other work around.

Thank you in advance.

when they answer the incoming call they want to show there web application form and display the customer information…I hope i explain it well.

Thank you in advance.

There are probably multiple ways this could be handled, but I’ll mention one:

Create an AMI application that’s tied into the web application and listens for events. For instance, in your case you might want to listen for the dial end event. When this event is received you can check the DialStatus to see if it was answered or not. If answered then you can use one of the other fields like exten to correlate it to the customer code. Once a customer code is matched then you can display the appropriate information to the client.

1 Like

I have achieved this task using AMI events specially newchannel event , Then using PHP you can save the event values in an array and fire a post back to your remote web app with the needed information, using the PHP functions file_get_contents or curl to your remote web app, the variables extacted from the AMI event will be avaiable on the global array $_POST OR $_GET depending on the method use to make the post back usually the GET method

Hi @ambiorixg12,

Thank you for the reply…Yes I am using php. can you please show me simple example how to do this so that I can have some idea and guide… I haven’t used AMI events or the API ?. please help me I really need your help.

Update: So my web application browser is always open so that the in-charge or the one who answers the incoming call can see the customer information automatically. this is what I want I hope you can help me.

Thank you in advance.

Hi @kharwell,

Thank you for the reply, can you please show me example of AMI application ? I haven’t tried to used the events ?.

Thank you in advance.

<?php $socket = fsockopen("127.0.0.1","5038", $errno, $errstr,10); if (!$socket){ echo "$errstr ($errno)\n"; }else{ fputs($socket, "Action: Login\r\n"); fputs($socket, "UserName: admin\r\n"); fputs($socket, "Secret: 13201\r\n\r\n"); fputs($socket, "Action: WaitEvent\r\n"); fputs($socket, "Action: Logoff\r\n\r\n"); while(!feof($socket)){ $result=fread($socket,5000); if (preg_match("/\b$argv[1]\b/i", $result,$match)){ echo $result; } } } fclose($socket); ?>

On the command line you run the script and the event to catch it will output the event in this case 2 events are fire are make or recive a call, one for the sip device making the call and the other for the sip trunk device used to make the call

php event_catch.php Newchannel

Event: Newchannel
Privilege: call,all
Channel: SIP/101-00000002
ChannelState: 0
ChannelStateDesc: Down
CallerIDNum: 101
CallerIDName:
ConnectedLineNum:
ConnectedLineName:
Language: en
AccountCode:
Context: home
Exten: 13052341212
Priority: 1
Uniqueid: 1493266023.6
Linkedid: 1493266023.6

Event: Newchannel
Privilege: call,all
Channel: SIP/paco-00000003
ChannelState: 0
ChannelStateDesc: Down
CallerIDNum:
CallerIDName:
ConnectedLineNum:
ConnectedLineName:
Language: en
AccountCode:
Context: from-trunk
Exten: s
Priority: 1
Uniqueid: 1493266023.7
Linkedid: 1493266023.6

NOTE: you can catch any event fired by asterisk just need to run the php script on the command line and the event name

php event_catch.php asterisk_ami_event_name

list of events here Home - Asterisk Documentation

Hi @ambiorixg12,

Thank you for the reply and giving example…can I ask the php file that you use socket is that event_catch.php ? is this resides in my web app folder ?..also where should I put this Event,privilege and etc… I am confuse. please help me.

Event: Newchannel
Privilege: call,all
Channel: SIP/101-00000002
ChannelState: 0
ChannelStateDesc: Down
CallerIDNum: 101
CallerIDName:
ConnectedLineNum:
ConnectedLineName:
Language: en
AccountCode:
Context: home
Exten: 13052341212
Priority: 1
Uniqueid: 1493266023.6
Linkedid: 1493266023.6

Event: Newchannel
Privilege: call,all
Channel: SIP/paco-00000003
ChannelState: 0
ChannelStateDesc: Down
CallerIDNum:
CallerIDName:
ConnectedLineNum:
ConnectedLineName:
Language: en
AccountCode:
Context: from-trunk
Exten: s
Priority: 1
Uniqueid: 1493266023.7
Linkedid: 1493266023.6

Thank you in advance.

Sorry I tried to be as clear as possible, And I was expecting at least you have the basic PHP and Asterisk knowledge. But based on your response to my last post, you re far to understand ,what I was talking about. I dont ask you to be an expert, because if so you wont be here asking for help. But at least you should have basic knowledge of the technoly involved on this process.Sorry But I cant do nothing more beyond what I did.

But Anyway I will do the google search for you , and I will post the information you need read in order to understand my approach

http://php.net/manual/en/features.commandline.usage.php
https://www.voip-info.org/wiki-Asterisk+manager+API
http://www.asteriskdocs.org/

HI @ambiorixg12,

Thank you for the reply…I know php but asterisk I have little knowledge for this.I just started 3 days in asterisk… I am just confuse of Event, privlige, channel. is that the response in socket when we are connected in asterisk ?

Thank you in advance.

Yes, that is a reponse sent from Asterisk to the PHP script , that response is an event in my example there are 2 events. You will insert that reponse into an array and you will fire the needed array values to your web app. In the other hand have if you just have 3 days using Asterisk you should learn the Asterisk basic http://www.asteriskdocs.org/ and once you can handle basic stuff you can jump to advanced contexts like AMI events. But what you are trying to do is equivalent on programming ,trying to create your own class without at least know how to at least declare a variable

Hi, Okay, I thought the php file will be put inside in the asterisk server…because when I had the test the text to speech in the tutorial if followed I put the php script inside in asterisk and I can connect to …but in your case my listener is in my web application folder.

Thank you in advance.

Dont want to mess with the thread but you also can try many applications available outside, I made something in the past(like 5 years) Here

HI navaismo

Thank you for the help, I will also try, this will serve as my guide. thank you so much.

HI @ambiorixg12,

Can I ask I’m not clear with the socket where should I run this or put this in my web server where my web app resides or in the asterisk ? because in asterisk I can also put php files.

Thank you in advance.

Hi I wish I could test your file, but I don’t know how to test can you provide some step please…

Thank you in advance.

From the readme that seesm missing:

This Program is provided “AS IS” without warranty, or support.

/ ************************************* Requirements *********** ****************************************** /

  1. In order to use this program you need to add a user to the asterisk manager. For example: Open the

/etc/asterisk/manager.conf file and add the following lines.

  [Popup];

  Secret = popup_pass; paswword

  Deny = 0.0.0.0 / 0.0.0.0

  Permit = 10.0.1.0 / 255.255.255.0; Change by your IP or localhost

  Read, system, call, log, verbose, agent, user, config, dtmf, reporting, cdr, dialplan

  Write = system, call, agent, user, config, command, reporting, originate, message
  1. Load the new manager configuration into asterisk with the following command:

    Manager relaod

  2. If you activate the “Activate Browser” option you will need to install Firefox on your system.

/************************************** Installation instructions ******** ******************************** /

  1. For Linux:

    • Copy the Linux / CallMonitor folder to the location you want.

    • Ensure that the Callmonitor binary has execute permissions, this is achieved by entering a

      Console and entering the following command:

      Chmod + x CallMonitor

    • Run from console or from Desktop.

  1. For Windows:

    • Copy the Windows / CallMonitor folder to the location you want.

    • Run the program by double clicking on the icon.

    • When you minimize the application, it will be added to the taskbar to show it again

      Right click on the icon and choose Show.

/***************************************** Characteristics ******* ********************************************* /

This program provides the following functions:

  1. Opens a popup window containing the: Name (CALLERID (name)) and the Caller’s Number (CALLERID (num))

  2. Open a web browser (FireFox) with the given URL and the parameters:

    • UNIQUEID.

    • CALLERIDNAME

    • CALLERIDNUM

/ ***************************************** LICENSE ******* ************************************************** **** /

COPYLEFT

Thank you for the reply and some steps I will try these…by the way can I ask, Is this like socket your program will connect to asterisk ?. using i.p and port ?

Thank you in advance.

Yes, exactly the same process that the other friends told you, AMI, Sockets listening events, in fact you can see the events activating the debug.

Hi can I ask how can I activate the debug ?

Thank you in advance.