(Work in progress – will update as the code becomes more stable)
I had a neat idea to have asterisk send me a MSN message based on an Asterisk event.
I was able to have asterisk execute an AGI that would send me a MSN msg for every incoming call.
Info
It took me about 45 minutes to get this all working (msn msgs with callerid of incoming calls)
I think it is kind of neat and will (as time permits) enhance this.
If anyone is interested in this, email me voip (at) les (dot) net.
Based on the response, I may speed up development.
Goals
My current asterisk setup answers the phone, greets the caller with a paranoid disclaimier (we monitor calls, etc)
Then does a DIAL to my known phone numbers.
I will modify this action to send me a MSN message with the callerid of who is calling as a MSN message.
The caller will be placed in a meetme or some kind of limbo.
Upon receiving the MSN message, I will type “accept” “drop” “voicemail” or something to that effect
based on my MSN response, the caller will branch as directed from my MSN reply.
I used the following software:
http://www.hypothetic.org/docs/msn/index.php
I wrote an AGI script that would append the callerid+did into a text file in the /tmp directory.
I modified the MSN php code to poll for the text file once a second (Ugly, yes I know)
Upon finding the text file, it would load its contents line by line and message them to my primary MSN account.
It would then delete the text file.
I modified my extensions.conf to call the AGI on every single incoming call, then dispatch it to my normal DID handler.
The result was a MSN message that arrived for every caller to my system.
Steps
Phase 1
1) Create a new MSN account for originating the messages
2) Login to the account, and add your existing MSN as a contact
3) Logout, and Login as your existing MSN account and accept the new contact.
4) Program the MSN script with your newly created account/password
Phase 2
Modify msnp9.class.php and add a timeout on function __get()
function _get()
{
stream_set_timeout($this->fp, 1); <—- add this line
if ($data = @fgets($this->fp, 4096))
{
This will cause the _get function to fall through the fgets after 1 second.
Phase 3
Modify msnp9.class.php in the function rx_data()
Before case ‘RNG’ add
case ‘ILN’:
$online = 1;
break;
This will set a flag to say “we are online now, we can send out messages”
Phase 4
Modify msnp9.class.php in the function rx_data()
$online = 0;
while (! feof($this->fp))
{
if ($online) {
if (file_exists(“/tmp/msn.txt”)) {
$cid = fopen(“/tmp/msn.txt”,”r”);
$sbsess = new switchboard;
while (!feof($cid)) {
$num = chop(fgets($cid,4096));
if ($num != ”) {
$sbsess->tx_im($this->fp, “CID: $num”, $this->passport, ‘l###YOUR NEW MSN ACCOUNT###’);
}
}
fclose($cid);
$sbsess->im_close();
unlink(“/tmp/msn.txt”);
}
}
$data = $this->_get();
Phase 5
Create an AGI script that opens, appends, and writes a single line to /tmp/msn.txt, and closes the file.
Phase 6
Run the msn php script like a daemon from the command line
Add #!/usr/bin/php -q to the beginning of the script
and run ./msn.php
This will cause the msn script to run, login to msn, and loop forever.
See also:
- Asterisk AGI php: PHP for AGI scripting in Asterisk
- Asterisk call notification
Go back to Asterisk