Returns a new net.Server instance. The _listener_ will be called on a new agi connection with a single __Context__ object as described below.
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
`````
var ding = require('ding-dong');
var ding = require('ding-dong');
ding.createServer(function(context) {
ding.createServer(function(context) {
context.on('variables',function(vars){
context.onEvent('variables')
console.log('received new call from: '+vars.agi_callerid+' with uniqueid: '+vars.agi_uniqueid);
.then(function(vars) {
});
console.log('received new call from: ' + vars.agi_callerid + ' with uniqueid: ' + vars.agi_uniqueid);
})
.fail(console.log);
}).listen(3000);
}).listen(3000);
```
`````
### Add to Asterisk extensions.conf
### Add to Asterisk extensions.conf
`````
`````
[default]
[default]
exten = > 1000,1,AGI(agi://localhost:3000)
exten = > 1000,1,AGI(agi://localhost:3000)
`````
`````
attention: using javascript promises
### new ding.Context(stream)
### new ding.Context(stream)
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.
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])
### context.exec(command, [args])
Dispatches the `EXEC` AGI command to asterisk with supplied command name and arguments. _callback_ is called with the result of the dispatch.
Dispatches the `EXEC` AGI command to asterisk with supplied command name and arguments. _callback_ is called with the result of the dispatch.