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

Dmitriev Sergey's avatar
Dmitriev Sergey committed
3
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
4 5

## install
sergey's avatar
sergey committed
6

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

## API

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

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
18 19
var ding = require('ding-dong');
ding.createServer(function(context) {
sergey's avatar
sergey committed
20 21 22 23 24
  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
25 26 27 28 29
### Add to Asterisk extensions.conf
`````
[default]
exten = > 1000,1,AGI(agi://localhost:3000)
`````
sergey's avatar
sergey committed
30

sergey's avatar
sergey committed
31 32

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

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
41 42
context.exec('Dial', opt1, opt2, .., optN, function(err, res) {
  //the channel call app Dial with options
sergey's avatar
sergey committed
43 44 45 46 47 48 49
});

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
50
### context.hangup([callback])
sergey's avatar
sergey committed
51 52 53 54 55 56 57 58

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
59 60 61 62


## Projects

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

## Links

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