README.md 1.92 KB
Newer Older
sergey's avatar
sergey committed
1
# ding-dong
Dmitriev Sergey's avatar
Dmitriev Sergey committed
2

3 4
[![Build Status](https://travis-ci.org/antirek/ding-dong.svg?branch=master)](https://travis-ci.org/antirek/ding-dong)

Dmitriev Sergey's avatar
Dmitriev Sergey committed
5
Create AGI server with ding-dong. Use with Asterisk for fast telephony apps. [Fork of node-agi](http://github.com/brianc/node-agi)
sergey's avatar
sergey committed
6 7

## install
sergey's avatar
sergey committed
8

sergey's avatar
sergey committed
9
```
sergey's avatar
sergey committed
10
npm install ding-dong [--save]
sergey's avatar
sergey committed
11 12 13 14
```

## API

sergey's avatar
sergey committed
15
### ding.createServer([listener])
sergey's avatar
sergey committed
16 17 18 19

Returns a new net.Server instance.  The _listener_ will be called on a new agi connection with a single __Context__ object as described below.

```js
sergey's avatar
sergey committed
20 21
var ding = require('ding-dong');
ding.createServer(function(context) {
sergey's avatar
sergey committed
22 23 24 25 26
  context.on('variables', function(vars) {
    console.log('received new call from: ' + vars.agi_callerid + ' with uniqueid: ' + vars.agi_uniqueid);
  });
}).listen(3000);
```
sergey's avatar
sergey committed
27 28 29 30 31
### Add to Asterisk extensions.conf
`````
[default]
exten = > 1000,1,AGI(agi://localhost:3000)
`````
sergey's avatar
sergey committed
32

sergey's avatar
sergey committed
33 34

### new ding.Context(stream)
sergey's avatar
sergey committed
35 36 37 38 39 40 41 42

Constructor to create a new instance of a context.  Supply a readable and writable stream to the constructor.  Commonly _stream_ will be a `net.Socket` instance.

### context.exec(command, [args], [callback])

Dispatches the `EXEC` AGI command to asterisk with supplied command name and arguments.  _callback_ is called with the result of the dispatch.

```js
sergey's avatar
sergey committed
43 44
context.exec('Dial', opt1, opt2, .., optN, function(err, res) {
  //the channel call app Dial with options
sergey's avatar
sergey committed
45 46 47 48 49 50 51
});

context.exec('RecieveFax', '/tmp/myfax.tif', function(err, res) {
  //fax has been recieved by asterisk and written to /tmp/myfax.tif
});
```

sergey's avatar
sergey committed
52
### context.hangup([callback])
sergey's avatar
sergey committed
53 54 55 56 57 58 59 60

Dispatches the 'HANGUP' AGI command to asterisk.  Does __not__ close the sockets automatically.  _callback_ is called with the result of the dispatch.

```js
context.hangup(function(err, res) {
  //the channel has now been hungup.
});
```
sergey's avatar
sergey committed
61 62 63 64


## Projects

Dmitriev Sergey's avatar
Dmitriev Sergey committed
65
[Voicer](http://github.com/antirek/voicer) - AGI yandex voice recognizer for Asterisk
sergey's avatar
sergey committed
66 67 68

## Links

Dmitriev Sergey's avatar
Dmitriev Sergey committed
69
[Asterisk AGI](https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+AGI+Commands)