# Asterisk send data to Web application

**URL:** <https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494>\
**Category:** Asterisk Integration\
**Created:** [April 26, 2017, 8:25am UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494 "2017-04-26T08:25:07Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jemz](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@jemz](https://community.asterisk.org/u/jemz)\
**Post date:** [April 26, 2017, 8:25am UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/1 "2017-04-26T08:25:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jemz](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@jemz](https://community.asterisk.org/u/jemz)\
**Post date:** [April 26, 2017, 2:19pm UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/2 "2017-04-26T14:19:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kharwell](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/kharwell/32/1924_2.png) [@kharwell](https://community.asterisk.org/u/kharwell)\
**Post date:** [April 26, 2017, 10:54pm UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/3 "2017-04-26T22:54:58Z")

</div>

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

Create an [AMI](https://wiki.asterisk.org/wiki/pages/viewpage.action?pageId=4817239) application that’s tied into the web application and listens for [events](https://wiki.asterisk.org/wiki/display/AST/Asterisk+14+AMI+Events). For instance, in your case you might want to listen for the [dial end](https://wiki.asterisk.org/wiki/display/AST/Asterisk+14+ManagerEvent_DialEnd) 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.

---

<div class="post-metadata">

**Author:** ![ambiorixg12](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/ambiorixg12/32/1887_2.png) [@ambiorixg12](https://community.asterisk.org/u/ambiorixg12)\
**Post date:** [April 26, 2017, 11:13pm UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/4 "2017-04-26T23:13:39Z")

</div>

I have achieved this task using AMI events specially [newchannel event](https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+ManagerEvent_Newchannel) , 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

---

<div class="post-metadata">

**Author:** ![jemz](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@jemz](https://community.asterisk.org/u/jemz)\
**Post date:** [April 27, 2017, 3:32am UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/5 "2017-04-27T03:32:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jemz](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@jemz](https://community.asterisk.org/u/jemz)\
**Post date:** [April 27, 2017, 3:58am UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/6 "2017-04-27T03:58:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ambiorixg12](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/ambiorixg12/32/1887_2.png) [@ambiorixg12](https://community.asterisk.org/u/ambiorixg12)\
**Post date:** [April 27, 2017, 4:12am UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/7 "2017-04-27T04:12:21Z")

</div>

\<?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](https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+AMI+Events)

---

<div class="post-metadata">

**Author:** ![jemz](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@jemz](https://community.asterisk.org/u/jemz)\
**Post date:** [April 27, 2017, 5:03am UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/8 "2017-04-27T05:03:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ambiorixg12](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/ambiorixg12/32/1887_2.png) [@ambiorixg12](https://community.asterisk.org/u/ambiorixg12)\
**Post date:** [April 27, 2017, 5:31am UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/9 "2017-04-27T05:31:56Z")

</div>

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](http://php.net/manual/en/features.commandline.usage.php)  
[https://www.voip-info.org/wiki-Asterisk+manager+API](https://www.voip-info.org/wiki-Asterisk+manager+API)  
[http://www.asteriskdocs.org/](http://www.asteriskdocs.org/)

---

<div class="post-metadata">

**Author:** ![jemz](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@jemz](https://community.asterisk.org/u/jemz)\
**Post date:** [April 27, 2017, 5:39am UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/10 "2017-04-27T05:39:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ambiorixg12](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/ambiorixg12/32/1887_2.png) [@ambiorixg12](https://community.asterisk.org/u/ambiorixg12)\
**Post date:** [April 27, 2017, 5:48am UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/11 "2017-04-27T05:48:49Z")

</div>

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/](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

---

<div class="post-metadata">

**Author:** ![jemz](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@jemz](https://community.asterisk.org/u/jemz)\
**Post date:** [April 27, 2017, 6:55am UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/12 "2017-04-27T06:55:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![navaismo](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/navaismo/32/2481_2.png) [@navaismo](https://community.asterisk.org/u/navaismo)\
**Post date:** [April 27, 2017, 1:58pm UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/13 "2017-04-27T13:58:03Z")

</div>

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](https://www.dropbox.com/s/wdxn46ntmes42sl/DM_CallMonitor_V1.5RC3_EN.zip?dl=0)

---

<div class="post-metadata">

**Author:** ![jemz](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@jemz](https://community.asterisk.org/u/jemz)\
**Post date:** [April 27, 2017, 2:06pm UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/14 "2017-04-27T14:06:31Z")

</div>

HI navaismo

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

---

<div class="post-metadata">

**Author:** ![jemz](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@jemz](https://community.asterisk.org/u/jemz)\
**Post date:** [April 27, 2017, 2:21pm UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/15 "2017-04-27T14:21:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jemz](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@jemz](https://community.asterisk.org/u/jemz)\
**Post date:** [April 27, 2017, 2:29pm UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/16 "2017-04-27T14:29:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![navaismo](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/navaismo/32/2481_2.png) [@navaismo](https://community.asterisk.org/u/navaismo)\
**Post date:** [April 27, 2017, 3:01pm UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/17 "2017-04-27T15:01:24Z")

</div>

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:
> 
> 2. If you activate the “Activate Browser” option you will need to install Firefox on your system.
> 
> /\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Installation instructions \*\*\*\*\*\*\*\* \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* /
> 
> 1. For Linux:
> 
> 1. For Windows:
> 
> /\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* 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:
> 
> / \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* LICENSE \*\*\*\*\*\*\* \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* \*\*\*\* /
> 
> COPYLEFT

---

<div class="post-metadata">

**Author:** ![jemz](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@jemz](https://community.asterisk.org/u/jemz)\
**Post date:** [April 27, 2017, 4:06pm UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/18 "2017-04-27T16:06:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![navaismo](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/navaismo/32/2481_2.png) [@navaismo](https://community.asterisk.org/u/navaismo)\
**Post date:** [April 27, 2017, 4:20pm UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/19 "2017-04-27T16:20:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jemz](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@jemz](https://community.asterisk.org/u/jemz)\
**Post date:** [April 28, 2017, 2:43am UTC](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494/20 "2017-04-28T02:43:15Z")

</div>

Hi can I ask how can I activate the debug ?

Thank you in advance.

[Next page](https://community.asterisk.org/t/asterisk-send-data-to-web-application/70494.md?page=2)
