Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Description

This service has the goal to notify a external system when some events occur into Asterisk based PBX.

Use Cases

Imagine you need open a popup in the User screen when he answer a call.

In the exact time the User answer the call the Notification Service will send a request to your Webhook with all call data.

Other use case is when a customer Abandon the wait in Call Queue and you need to known that to do something, like call him back.

In the exact time the Customer abandon the wait, the Notification Service will send a request to your Webhook with the call data.

See the sample case with Slack integration.

Notification Events

The notification events are:

  • When a User answer a call
  • When a call get in a Queue wait
  • When a Customer Abandon a Call Queue wait

Notification

The Notification will be send through POST(default) or GET method, in a RESTFul Request with JSON Object in the Body.

JSON format:

Code Block
themeRDark
languagejs
{
	"eventdate":"2016-10-25T14:04:36-02:00",
	"agent":"8019",
	"from":"4839548000",
	"fromname":"Ramal 8023",
	"holdtime":"4",
	"ringtime":"3",
	"destination":"8019",
	"method":"POST"
}

 

Onde:

FieldDescription
eventdateEvent Date and time
agentOperator/Agent that answer this call
fromCaller for this call.
fromnameWhen we know the name of the Caller, we use it, if not the from filed will be used.
holdtimeThe hold time that the Caller wait for answer.
ringtimeThe ring time in the Agent endpoint before he answered the call.
destinationThe endpoint where the call was answered by the Agent/Operator.
methodIs the notification method registered for this webhook.

 

 

Enabling a Notification

To enable a event notification you need access the Q-Manager Admin Interface and in the option "Integrations" click on button "Integration Add".

Choice the type Integration "Notification" and complete with Service data.

You can choice the fields that API will send to the service using the Section Mapping.

Additional fields also can be send through the Section Fields, like a token or any other the service could need.

In the field value you can use original fields content, for example, use as value of a new field the content of the field fromname. To do that mention the field using {}, {fromname}.

Yu can combine fields or text content in the value, like:

Code Block
themeMidnight
languagetext
Field Name: text
Field Value:
The Customer {fromname} abandoned the Queue {queue} at {eventdate}

In the Section Headers you can send Headers for your request, like an Authorization header.

Server side code Sample

This is an example of code you can have in your server to receive the Notification Service.

PHP + Apache

This code in php receive the requests comming from Notification and save it in a log file called "http.log". 

Code Block
themeDJango
languagephp
<?php
$method = $_SERVER['REQUEST_METHOD'];
$client = $_SERVER['REMOTE_ADDR'];
$query = $_SERVER['QUERY_STRING'];
$json = file_get_contents('php://input');
$obj = json_decode($json);

file_put_contents("http.log",$json . "\n", FILE_APPEND);
// your complete JSON Object is in $obj
// you can do everything accessing the element directly, like this $obj->from , $obj->destination , $obj->agent , and etc.

// saving in a log:
// file_put_contents("http.log","from: {$obj->from}" . "\n", FILE_APPEND);
// file_put_contents("http.log","destination: {$obj->destination}" . "\n", FILE_APPEND);
// file_put_contents("http.log","agent: {$obj->agent}" . "\n", FILE_APPEND);
// here an exemplo testing the complete object and saving it in a log file
/*
if(is_object($obj)){
        foreach($obj as $key => $value){
                if(is_object($value)){
                        foreach($value as $skey => $svalue){
                                file_put_contents("http.log","object -> object: {$key} -> {$skey} -> {$svalue}\n", FILE_APPEND);
                        }
                }elseif(is_array($value)){
                        foreach($value[0] as $skey => $svalue){
                                file_put_contents("http.log","object -> array: {$key} -> {$skey} -> {$svalue}\n", FILE_APPEND);
                        }
                }else{
                        file_put_contents("http.log","object array: {$key} -> {$value}\n", FILE_APPEND);
                }
        }
}
*/
// returning Ok in a JSON object
$return = json_encode(array("status" => "Ok"));
echo $return;