Hit a url on each call

Hi all,

I want to hit a url on incoming calls passing two variables (To and From Number) on call answered.

e.g: http://192.168.0.1/test/asterisk/index.php?from=1237&to=xxx

how can I achieve this. any API required.

Sounds like a job for AMI. The REST API might be able to do something as well.

A lot depends on what you want /test/asterisk/index.php to do.

^^ That is your API, where you are sending the information to. So you need to figure out how you want to call it. Is it an AGI(), CURL(), SYSTEM(), etc.

Standard feature of Superfecta. Configure the superfecta scheme with “Send to URL” and ensure Superfecta is enabled for your inbound route(s).

edit - also a standard feature for the paid CRM module. Using webhooks, you can trigger a URL call on inbound and/or outbound calls, but you will have to config the receiving server to process the POST data.

4 Likes

can you share any example with superfecta.

how this can be achieved?

any guidelines or start point from where I can start.

https://wiki.freepbx.org/display/FPG/CID+Superfecta+User+Guide

Please share your outcome, I am interested in this as well.

1 Like

I think this is not something I am looking for.

I want to send data in variables for To and From CALLERID. when some one calls into a queue, this information will be parsed in To and From variables.

I am looking for writing post script php agi.

Can anyone help me in this.

Do you even need to though? What about just cURLing the URL with the variables in the dialplan. Add it to extensions override?

any example. i don’t know how to cURL

cURL examples:

You could wrap that in a System() dialplan command:

That’s it. Try the cURL on the command line until it does what you want. Once it does, add it to the dialplan and replace your static numbers with the channel variables ,ex. ${CALLERID(DIND)}

You don’t need to use System(curl...) from dialplan, there is a curl dialplan function:

freepbx*CLI> core show function CURL

  -= Info about function 'CURL' =-

[Synopsis]
Retrieves the contents of a URL

[Description]
  url       - URL to retrieve
  post-data - Optional data to send as a POST (GET is default action)


[Syntax]
CURL(url[,post-data])
2 Likes

I don’t know how to write this curl script with asterisk dialplan

can you give me a little example

so nice of you

exten => s,n,CURL(url[,post-data])

Your phone itself likely also has an action URL that can be used.

2 Likes

Guys,

I am able to write a php code to get the variables I needed.

But now I want to place it first for testing on one of my extension.

Code:--------

#!/usr/bin/env php
<?php

require_once "phpagi.php";


//
// A very simple PHP example that sends a HTTP POST to a remote site
//

$agi = new AGI();
//$AGI->answer();
//#$logger = new AGI_Logger($agi);
//$cdr = new AGI_CDR($agi);

//if ($cdr->caller_known() && $cdr->called_known()) {
   //$cdr->flush_cdr();
//}


$called_ext = $agi->request['agi_extension'];
$cid = $agi->parse_callerid();
$caller_ext = $cid['username'];

$agi->verbose("Called Extension =  $called_ext");

$agi->verbose('---------------------------------------HERE');



echo $called_ext;
echo $caller_ext;



$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://172.16.18.29/test/asterik/index.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
            "from=$caller_ext&to=$called_ext");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec($ch);

curl_close ($ch);

print_r($server_output);
$agi->verbose("Server Output =  $server_output");

// Further processing ...
?>

it gives me this output.

CLI> channel originate Local/10001@fak extension 1004@from-internal
 /var/lib/asterisk/agi-bin/testcurl_post.php: Called Extension =  10001
 /var/lib/asterisk/agi-bin/testcurl_post.php: ---------------------------------------HERE
 /var/lib/asterisk/agi-bin/testcurl_post.php: Server Output =  
 /var/lib/asterisk/agi-bin/testcurl_post.php: OK
 /var/lib/asterisk/agi-bin/testcurl_post.php: 
 /var/lib/asterisk/agi-bin/testcurl_post.php: 
  == Spawn extension (fak, 10001, 2) exited non-zero on 'Local/10001@fak-00000016;2'
CLI> 

Now I want to set it in the real extension on which upon calling it executes this and then other operations of pbx works as remains the same.
I place it here but not worked for me.

exten => 1003,1,AGI(/var/lib/asterisk/agi-bin/testcurl_post.php)
exten => 1003,n,Set(__RINGTIMER=${IF($["${DB(AMPUSER/1003/ringtimer)}" > "0"]?${DB(AMPUSER/1003/ringtimer)}:${RINGTIMER_DEFAULT})})
exten => 1003,n,Macro(exten-vm,1003,1003,0,0,0)
exten => 1003,n(dest),Set(__PICKUPMARK=)
exten => 1003,n,Macro(vm,1003,${DIALSTATUS},${IVR_RETVM})
exten => 1003,n,Goto(vmret,1)
exten => 1003,hint,SIP/1003&Custom:DND1003,CustomPresence:1003

exten => vmb1003,1,Macro(vm,1003,BUSY,${IVR_RETVM})
exten => vmb1003,n,Goto(vmret,1)

exten => vmu1003,1,Macro(vm,1003,NOANSWER,${IVR_RETVM})
exten => vmu1003,n,Goto(vmret,1)

exten => vms1003,1,Macro(vm,1003,NOMESSAGE,${IVR_RETVM})
exten => vms1003,n,Goto(vmret,1)

exten => vmi1003,1,Macro(vm,1003,INSTRUCT,${IVR_RETVM})
exten => vmi1003,n,Goto(vmret,1)

Any help will be appreciated.

For testing, make a custom context and then put your phone in that context.

[from-php-test]
exten => s,1,NoOp()
exten => s,n,AGI(/var/lib/asterisk/agi-bin/testcurl_post.php)
exten => s,n,Goto(from-internal,${EXTEN},1)

In the advanced tab for your extension, change the context to from-php-test

Once you know it works, change the context to [from-internal-custom] as that is included by default in [from-internal], and remove the extra pieces. Don’t forget to put your extension back on from-internal when you are done.

[from-internal-custom]
exten => s,1,AGI(/var/lib/asterisk/agi-bin/testcurl_post.php)

This last bit may be wrong, i haven’t done it in a while, but you get the idea.

1 Like

In my advanced tab there is custom context field no field with context and from-internal