Custom IVR with JSON

Hi,

Can someone help with install this module in FreePBX

My setup
FreePBX 13.0.191.11
Asterisk 13.14.0

For the purposes of discussion here, FreePBX is nothing more than a GUI for Asterisk (I know, but for this, it’s OK) so the installation of this module is almost nothing more than the regular Asterisk install.

If there are “contexts” to install, you’ll need to add them to the appropriate “whatever _custom.conf” files (e.g., extensions_custom.conf) instead of the ‘base’ Asterisk conf files. Other than that, it should be pretty much straight Asterisk.

This is an Asterisk module, and requires that Asterisk be re-compiled. If you’re using the FreePBX distro there is no supported way to compile Asterisk. You are probably better off using a normal AGI file.

I know its not the same thing, but we’ve been using Shell in the dial plan, with a cURL and pearl commands to refine the JSON result to just what we need. It works very well with our FreePBX distro without having to install any additional dependencies. All in just one line of the dial plan.

Thanks for the answer I will use the idea with the console and curl or php
It is a pity that recompilation is difficult or impossible in freepbx

It’s actually neither of those, it just creates a system that is no longer technically a “distro” system.

The process for creating a new kernel is the standard “Asterisk” way of doing it - the problem is that updates for the system will want to overwrite your custom kernel when new versions of SNG come out (like the 7.5 update last week).

Hello @comtech,

Would you mind sharing with us your one line command to parse a JSON response?

Thank you,

Daniel Friedman

I use jq

 jq
jq - commandline JSON processor [version 1.5-1-a5b5cbe]
Usage: jq [options] <jq filter> [file...]

	jq is a tool for processing JSON inputs, applying the
	given filter to its JSON text inputs and producing the
	filter's results as JSON on standard output.
	The simplest filter is ., which is the identity filter,
	copying jq's input to its output unmodified (except for
	formatting).
	For more advanced filters see the jq(1) manpage ("man jq")
	and/or https://stedolan.github.io/jq

	Some of the options include:
	 -c		compact instead of pretty-printed output;
	 -n		use `null` as the single input value;
	 -e		set the exit status code based on the output;
	 -s		read (slurp) all inputs into an array; apply filter to it;
	 -r		output raw strings, not JSON texts;
	 -R		read raw strings, not JSON texts;
	 -C		colorize JSON;
	 -M		monochrome (don't colorize JSON);
	 -S		sort keys of objects on output;
	 --tab	use tabs for indentation;
	 --arg a v	set variable $a to value <v>;
	 --argjson a v	set variable $a to JSON value <v>;
	 --slurpfile a f	set variable $a to an array of JSON texts read from <f>;
	See the manpage for more options.

We could compile this module separately as part of our build process for asterisk is anyone wants it.

2 Likes
A simple example that strips the keys for main_ip from your vultr instances

# curl -sH 'API-Key:(yourapi)' https://api.v
ultr.com/v1/server/list|jq -r '.[] | {main_
ip}|join(",")'
1 Like

I think adding this module to FreePBX is great idea

I curl a webpage, then python (could be done with pearl too) the response to find the data field (oldest_call_waiting) I want and return the value. In this case I am looking at an unconnected phone system (Avaya) before I send calls to it.

curl -s 'YOURURLHERE' | python -c "import sys, json; print json.load(sys.stdin) ['oldest_call_waiting']"

Wrap it in System or Shell and go :slight_smile:

http://www.itp-redial.com/class/weekly-notes/week4-notes/system-and-shell

In fact I think @dicko actually helped me with this a long while back, so kudos to him.

2 Likes

Hello @comtech,

I use bash scripts to pull data from the Asterisk console all the time, and I think that it is much more faster than the regular AGI or REST API. So, I think that your bash script is really nice, smart and fast. And If @dicko helped you with that so great work from his side as well.

Thank you,

Daniel Friedmn

Yes, I think it has it’s merits. If the treatment is happening to all calls and it pretty central/internal to FreePBX, we usually go this route. The best part about FreePBX/Asterisk is how flexible it is. Use asterisk as a service (ARI) or pull your scripts from any language in to the dial plan, they can do it all. With these tools, the only real limit is your ability to think/dream of a solution.

1 Like

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