-
Notifications
You must be signed in to change notification settings - Fork 1
/
snom-xml-agi.php
executable file
·91 lines (82 loc) · 2.63 KB
/
snom-xml-agi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/php
<?php
/**
* (c) 2017 Volker Kettenbach
*
* See LICENSE for license details
*
* AGI tool for asterisk to send SIP-notifys with dialog-info in xml format
* to Snom phones. Tested in Snon 370 and 320.
* Use in asterisk as follows:
*
* exten => 82,1,AGI(snom-xml-agi.php, <identify to notify on other phone>)
* exten => 82,n,AGI(snom-xml-agi.php, <another identity>)
* exten => 82,n,Dial(.....)
*
*
**/
require_once('PhpSIP.class.php');
$agivars = array();
while (!feof(STDIN)) {
$agivar = trim(fgets(STDIN));
if ($agivar === '') {
break;
}
$agivar = explode(':', $agivar);
$agivars[$agivar[0]] = trim($agivar[1]);
}
extract($agivars);
#The info passed by Asterisk is:
#agi_request - The filename of your script
#agi_channel - The originating channel (your phone)
#agi_language - The language code (e.g. "en")
#agi_type - The originating channel type (e.g. "SIP" or "ZAP")
#agi_uniqueid - A unique ID for the call
#agi_callerid - The caller ID number (or "unknown")
#agi_calleridname - The caller ID number (or "unknown")
#agi_callingpres - The presentation for the callerid in a ZAP channel
#agi_callingani2 - The number which is defined in ANI2 see Asterisk Detailed Variable List (only for PRI Channels)
#agi_callington - The type of number used in PRI Channels see Asterisk Detailed Variable List
#agi_callingtns - An optional 4 digit number (Transit Network Selector) used in PRI Channels see Asterisk Detailed Variable List
#agi_dnid - The dialed number id
#agi_rdnis - The referring DNIS number
#agi_context - Origin context in extensions.conf
#agi_extension - The called number
#agi_priority - The priority it was executed as in the dial plan
#agi_enhanced - The flag value is 1.0 if started as an EAGI script
#agi_accountcode - Account code of the origin channel
try
{
$api = new PhpSIP('');
#$api->setDebug(true);;
$api->addHeader('Asterisk PBX');
$api->addHeader('Event: xml');
$api->setMethod('NOTIFY');
$api->setFrom('sip:[email protected]');
$api->addHeader('Content-Type: application/snomxml');
if ($agi_calleridname == $agi_callerid) {
$text = $agi_callerid;
} else {
$text = $agi_calleridname . ' ' . $agi_callerid;
}
$api->setUri("sip:".$agi_arg_1);
$api->setBody('
<?xml version="1.0" encoding="UTF-8"?>
<SnomIPPhoneText>
<Text>
An:' . $agi_extension . ' Von:' . $text . ' <br/>
Um: ' . date("D M j G:i:s") . '
</Text>
<SoftKeyItem>
<Name>F1</Name>
<Label>Clear</Name>
<Softkey>CANCEL</Softkey>
</SoftKeyItem>
</SnomIPPhoneText>
');
$res = $api->send();
#echo "response: $res\n";
} catch (Exception $e) {
echo $e;
}
?>