Add Stasis application in dialplan (to use Asterisk ARI with FreePBX)

Hello,

I want to use Asterisk REST Interface (ARI) with FreePBX (last version) :
wiki.asterisk.org/wiki/display/AST/Getting+Started+with+ARI

In this tutorial, we have to do this :

3) Create a dialplan extension for your Stasis application. Here, we’re choosing extension 1000 in context default - if your SIP phone is configured for a different context, adjust accordingly.
extensions.conf
> [default]
> exten => 1000,1,NoOp()
> same => n,Answer()
> same => n,Stasis(hello-world)
> same => n,Hangup()

In FreePBX, we can’t edit the file extensions.conf directly (“Do NOT edit this file as it is auto-generated by FreePBX.” in the header of this file).

So, I have to add my dialplan in extensions_custom.conf
But I don’t know, what I have to write, to add Statis application for all incoming calls like in this tutorial.

Without this dialplan modification, I have this error : “Channel not in a Stasis application”, when I use this ARI command :
/channels/{channelId}/hold (Home - Asterisk Documentation)

How I can do this ?
Someone here has used ARI (Asterisk REST Interface) with FreePBX ?

Thank you.

I am working towards this however @lgaetz is the custom dialplan wiz kid.

Using the distro and Asterisk 13, you just need to install the ws_node package “npm install -g wscat”. Steps 1 and 2 are done entirely within the GUI in advanced settings and Asterisk REST Interface users. Install the FreePBX “Asterisk REST Interface Users” module if necessary. In advanced settings, enable “pretty print json” to see similar output as the tutorial

Step 3 - edit /etc/asterisk/extensions_custom.conf:

[from-internal-custom]
; make sure 1000 doesn't conflict with an extension already on the system
exten => 1000,1,NoOp(entering ${CONTEXT} as defined in extensions_custom.conf)
 same => n,Answer()
 same => n,Stasis(hello-world)
 same => n,Hangup()

After this, follow the tutorial as shown. I got it working by opening up two SSH sessions to the PBX, one for the ws node socket output, and another one to issue the curl commands from the linux CLI. Initially it was not clear to me that the curl command was intended to be used at the Linux command line not the socket. Also be sure to substitute the actual channel id in place of that shown in the tutorial:

curl -v -u asterisk:asterisk -X POST "http://localhost:8088/ari/channels/<<channel_id>>/play?media=sound:hello-world"
3 Likes

Thank you Lgaetz, that works correctly.

What I have to do in the diaplan, If I want to add Stasis Application “Hello world” for external calls, incoming on my SIP device (number 7020) ?
I want to answer, hold and handgup a incoming call with ARI, to control the call without touch the phone.

I know this thread is a little dated, but I haven’t found anything more recent applicable. I didn’t get quite as far as @Saurel did 3 years ago. But now everyone has 3 more years experience. :slight_smile:

I took the following steps:

  1. Installed ws_node with “npm install -g wscat”

  2. Created user “asterisk” in Settings > Asterisk REST Interface User with (temporary) password “asterisk”

  3. Enabled “Pretty JSON” in Advanced Settings > Asterisk REST Interface

  4. Created this in extensions_custom.conf:

;enable Asterisk REST interface (ARI)
[from-internal-custom]
exten => 9999,1,NoOp(entering ${CONTEXT} as defined in extensions_custom.conf)
 same => n,Answer()
 same => n,Stasis(hello-world)
 same => n,Hangup()
  1. fwconsole reload

  2. Ran the following as root and got this output:

[root@agents ~]# wscat -c "ws://localhost:8088/ari/events?api_key=asterisk:asterisk&app=hello-world"
/usr/lib/node_modules/wscat/bin/wscat:22
class Console extends EventEmitter {
^^^^^
SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

So, without digging through vm.js, module.js and node.js I am hoping someone can tell me what I did wrong.

Why don’t you use the official node js asterisk module made specifically for this?

Ahhh … I guess because I’m using 3 year old documentation. Can you point me at the official node js asterisk module made specifically for this?

Use that along with our freepbx nodejs module

1 Like

Yikes! That is awesome! I love playgrounds and new toys to play with. Sadly, I usually break them.

When I go to freepbx - npm and copy the “You can utilize FreePBX like so” script, then click on “Test with RunKit” it takes me to RunKit. I paste the script in the sandbox and click run, I get

Error: Cannot find module 'asterisk-manager'
at Module._resolveFilename in core internal/modules/cjs/loader.js — line 580

So I’m not sure exactly how to invoke.

When I installed ari-client I got warnings:

[root@agents ~]# npm install ari-client
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.12.18","npm":"2.15.11"})
npm WARN deprecated [email protected]: No longer maintained, please upgrade to swagger-client@3.
npm WARN engine [email protected]: wanted: {"node":">= 4"} (current: {"node":"0.12.18","npm":"2.15.11"})
npm WARN deprecated [email protected]: The sprintf package is deprecated in favor of sprintf-js.
npm WARN engine [email protected]: wanted: {"node":">=6"} (current: {"node":"0.12.18","npm":"2.15.11"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.12.18","npm":"2.15.11"})
npm WARN engine [email protected]: wanted: {"node":">=6"} (current: {"node":"0.12.18","npm":"2.15.11"})
[email protected] node_modules/ari-client
âââ [email protected]
âââ [email protected]
âââ [email protected]
âââ [email protected]
âââ [email protected] ([email protected], [email protected])
âââ [email protected] ([email protected], [email protected])
âââ [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

When I installed FreePBX, I got 2.0.0 instead of 2.1.2:

[root@agents ~]# npm install http://mirror.freepbx.org/npm/freepbx-2.0.0.tgz --save
[email protected] node_modules/freepbx
âââ [email protected]
âââ [email protected]
âââ [email protected]
âââ [email protected]
âââ [email protected] ([email protected], [email protected], [email protected], [email protected])

Then when I tried to run it with node: (“it” being the “You can utilize FreePBX like so” script saved as freepbx.js)

[root@agents ~]# node freepbx.js
Unhandled rejection ReferenceError: Bluebird is not defined #different versions installed with ARI and FreePBX packages
    at Conf.get (/var/www/html/fop2/node_modules/freepbx/dist/lib/Conf.js:80:13)
    at /var/www/html/fop2/freepbx.js:11:16
    at tryCatcher (/var/www/html/fop2/node_modules/freepbx/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/var/www/html/fop2/node_modules/freepbx/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/var/www/html/fop2/node_modules/freepbx/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/var/www/html/fop2/node_modules/freepbx/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/var/www/html/fop2/node_modules/freepbx/node_modules/bluebird/js/release/promise.js:694:18)
    at _drainQueueStep (/var/www/html/fop2/node_modules/freepbx/node_modules/bluebird/js/release/async.js:138:12)
    at _drainQueue (/var/www/html/fop2/node_modules/freepbx/node_modules/bluebird/js/release/async.js:131:9)
    at Async._drainQueues (/var/www/html/fop2/node_modules/freepbx/node_modules/bluebird/js/release/async.js:147:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/var/www/html/fop2/node_modules/freepbx/node_modules/bluebird/js/release/async.js:17:14)
    at processImmediate [as _immediateCallback] (timers.js:367:17)

Then I tried the script https://github.com/asterisk/node-ari-client/blob/master/examples/originate.js:

[root@agents fop2]# node originate.js
[ 'This API is using a deprecated version of Swagger!  Please see http://github.com/wordnik/swagger-core/wiki for more info' ]

Being that I am an idiot, I did all this on a box about to go into production with a LOT of custom code. I hope I didn’t break anything important to FreePBX modules.

So, now I am confused and befuddled about what to do and how I should update what to get the sample scripts to run. Do you have any further guidance for me about how to configure and invoke something like originate.js or “You can utilize FreePBX like so” script? (And I will do all further playing on development box.) :crazy_face:

Thanks so much for your help!

You can’t run the freepbx module from a random web browser. That’s what happens when you run using run kit. It runs the code in your browser. How can your browser talk to freepbx.

Also I gave you the link to npm. Why would you install freepbx with the url. Use npm. Npm install freepbx.

These simple things make me think you are WAY over your head here with whatever you are trying to do.

Take a step back. In your directory install freepbx from npm. Not a url. It’s already in npm. Then you’ll have the module. Next install asterisk-ari. Then query freepbx to get the default credentials.

I’ll write this up later tonight. I’m just baffled that I give you the link to npm to install yet you go out and install it with the url. That’s what npm is there for.

Also you are on nodejs 0.12. Which means you are on CentOS 6. Or Schmooze 6. You should upgrade to CentOS 7. SNG 7. That’s why you have warnings (the warnings are pretty clear as to why they are warning you)

You are correct, I am always in over my head. But I’m swimming as hard as I can! All that stuff was on the links you gave me. Apparently the mobile page is different from the regular web page.

I missed the little “> npm i freepbx” over on the right side because it said in bigger letters in the middle "
npm install http://mirror.freepbx.org/npm/freepbx-2.0.0.tgz --save" and I tested with RunKit because it said, “Test with RunKit” right under your avatar. Thank you for the links. I guess I picked the wrong ones because, as you say, I am over my head.

As to what I am trying to do: originate a call on a trunk and bridge it to an extension all the while sending call progress updates to the browser.

I can’t upgrade to SNG7 because I need HA and it does not exist for SNG7 and (according to the rumors I hear from partners) will probably only be available on 13 until 15 is released.

Can I make this work on CentOS 6?

Oops! I think I did break something. The event Hangup on inbound channel used to return

[ConnectedLineNum] => 1184 (the connected extension)

Now it returns

[ConnectedLineNum] => <unknown>

Is there any way to undo what I did? Or will doing it correctly overwrite anything I broke?

Nothing you did in this thread changed anything asterisk or freepbx does

That is reassuring. Thanks, Andrew.
Will work on Schmooze 6.6 ?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.