Skip to content

Instantly share code, notes, and snippets.

@jfinstrom
Last active May 20, 2020 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfinstrom/560ef51b455fb5c27a27e6545c909182 to your computer and use it in GitHub Desktop.
Save jfinstrom/560ef51b455fb5c27a27e6545c909182 to your computer and use it in GitHub Desktop.
ari thing
/*
* Copyright © 2019 James Finstrom <code@g3p0.xyz>
* This work is free. You can redistribute it and/or modify it under the
* terms of the Do What The Fuck You Want To Public License, Version 2,
* as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
*
* npm install ari-client
* npm install request
* Asterisk Dialplan
* Copied From: https://wiki.asterisk.org/wiki/display/AST/Getting+Started+with+ARI
* exten => 1000,1,NoOp()
* same => n,Answer()
* same => n,Stasis(sendhook)
* same => n,Hangup()
* run: nohup node arithing.js &
* probably better to use PM2 or something to manage the process ¯\_(ツ)_/¯
* get the ari user and password from /etc/asterisk/ari.conf
* Yes there are 19 lines of comments for 10 lines of code. You're welcome
*/
var client = require('ari-client');
var request = require('request');
client.connect('http://localhost:8088/ari/', 'username', 'password',function(err,ari){
ari.on('StasisStart',function(event,channel){
request.post('https://postb.in/1568770796124-5495820760261').form({"channel":event.channel});
channel.continueInDialplan();
});
ari.start('sendhook');
});
@netindicium
Copy link

Could this be modified to notify via Push to onesignal ? https://documentation.onesignal.com/reference#create-notification
Thanks for sharing.

@jfinstrom
Copy link
Author

yes you would just change the endpoint and the post data (within form();)
This example uses https://www.npmjs.com/package/request which was valid when this was made and is now deprecated so a different library may want to be used. It may be worth using a one signal client https://www.npmjs.com/package/onesignal and only use the parts of channel you need.....

let message = `Call From ${channel.callerid.name (${channel.callerid.number})}`

See https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+REST+Data+Models#Asterisk13RESTDataModels-Channel

@netindicium
Copy link

Thank you very much, will give it a try. Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment