Git Product home page Git Product logo

eastrisk's Introduction

<p>(c) 2010 Erlang Solutions, Ltd</p>
<h2>Introduction</h2>
<p>
Eastrisk consists of two separate parts, AGI, Asterisk Gateway Intefrace, and
the Asterisk Manager Interface.
</p>
<h2>AGI</h2>
<p>
The Asterisk Gateway Interface is a way for external programs to control the
dialplan. An AGI application is usually used to do advanced logic, or
communicate with external resources, such as Mnesia databases, Erlang
applications etc.
The Eastrisk application is capable of doing both FastAGI and normal AGI.
</p>
<p>
<h3>AGI</h3>
The Erlang AGI interface consists of both an Erlang application and a small
program written in C. The C program will be executed by Asterisk and pass on
information to a Erlang node through TCP/IP, usually on port 6666.
To use the AGI, place the binary created from the C sources in the 
<code>agi-bin</code> (usually in <code>/var/lib/asterisk/</code>) directory
and add something similar to<br />
<code>exten => _X.,1,AGI(erl.agi)</code><br />
to your dialplan.
</p>
<h3>FastAGI</h3>
<p>
FastAGI allows AGI scripts to be executed over a network and thus eliminates
the use of C code to connect to the AGI server.
To use the FastAGI put something similar to 
<code>exten => _X.,1,AGI(agi://localhost:6666)</code><br />
in your dialplan.
</p>
<h3>Using the connection:</h3>
<p>
When the AGI Sever receives a connection an {@link agi_channel}
process is spawned. When this
process has initialised it will notify any added event handlers (see
gen_event(3)) through the {@link agi_events}. The event handler will be
supplied with channel environment variables and the pid of the channel. The
event handler should then spawn a process which will communicate with the AGI
channel using the {@link agi} module.
</p>
<h3>Example of simple AGI session:</h3>
<p>
The event handler:<br />
<pre>
EventHandler:handle_event({new_channel, ChannelPid, ChannelEnv}, State) ->
    spawn(agi_com, start, [ChannelPid, ChannelEnv]),
    {ok, State}
</pre>
</p>
<p>
agi_com:<br />
<pre>
agi_com:start(ChannelPid, ChannelEnv) ->
    agi:answer(ChannelPid),
    case agi:stream_file(ChannelPid, "filename", "123") of
		{ok, {Value, _Endpos}} ->
			save_data(Value);
		_Else -> % never pressed any digits / hung up
			ok
	end,
    agi:hangup(ChannelPid),
    agi_channel:close(ChannelPid).
</pre>
</p>
To disable the AGI server to run, set the environment variable 
<code>agi_server</code> to <code>false</code> before the application is started.
<h2>Asterisk Manager Interface</h2>
<p>
The Asterisk Manager Interface is used to allow a program to issue commands on
an Asterisk server and also listen to PBX events.
The Erlang Asterisk Manager interface
can be used in two ways, either as a behaviour with a callback module or as an
by subscribing to events from an event manager.
</p>
<h3>Manager Event Manager</h3>
<p>
To use the manager event manager, make sure that the environment variables
<code>mgr_name</code> and <code>mgr_secret</code> are set appropriately.
Then use {@link ast_manager_events} to subscribe to events.
</p>
<h3>Manager behaviour</h3>
<p>
To use the Manager interface as a behaviour, just add
<code>-behaviour(manager).</code> and make sure to implement
<code>init/1</code>, <code>handle_event/2</code>, <code>code_change/3</code> and
<code>terminate/2</code>.
</p>
<p>
Please note that you have to set the environment variable
<code>manager_server</code> to <code>false</code> before the application is
started to be able to do this. Or, don't start the application, but just use the
behaviour.
</p>

eastrisk's People

Contributors

bpuzon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.