An open API service indexing awesome lists of open source software.

https://github.com/enniel/adonis-asterisk-ami

integration asterisk manager interface (AMI) in adonis-framework
https://github.com/enniel/adonis-asterisk-ami

adonis adonis-framework adonisjs ami asterisk asterisk-ami asterisk-manager-api

Last synced: about 1 month ago
JSON representation

integration asterisk manager interface (AMI) in adonis-framework

Awesome Lists containing this project

README

        

# Adonis Asterisk AMI

Easy control via [asterisk](http://www.asterisk.org/) manager interface (AMI).

Installation and configuration
----------------

Using npm:

```sh
npm i adonis-asterisk-ami --save
```
Using yarn:

```sh
yarn add adonis-asterisk-ami
```

Once it's installed, you can register the service providers in `bootsrap/app.js`:

```js
const providers = [
...
'adonis-asterisk-ami/providers/AsteriskAmiProvider',
...
]

...

const aceProviders = [
...
'adonis-asterisk-ami/providers/CommandsProvider',
...
]
```

Then add `ami.js` file in `config` folder with this code:

```js
'use strict'

const Env = use('Env')

module.exports = {
// client's parameters
reconnect: false,
maxAttemptsCount: 30,
attemptsDelay: 1000,
keepAlive: false,
keepAliveDelay: 1000,
emitEventsByTypes: true,
eventTypeToLowerCase: false,
emitResponsesById: true,
addTime: false,
eventFilter: null,
// connection parameters
host: Env.get('ASTERISK_AMI_HOST', '127.0.0.1'),
port: Env.get('ASTERISK_AMI_PORT', 5038),
username: Env.get('ASTERISK_AMI_USERNAME', ''),
secret: Env.get('ASTERISK_AMI_SECRET', ''),
dongle: {
sms: {
device: Env.get('ASTERISK_AMI_SMS_DEVICE', 'dongle1')
}
}
}
```
For more information abount client's parameters see [documentation](https://github.com/BelirafoN/asterisk-ami-client#clients-parameters).

Usage
----------------
**Connection options**

You are can specify connection parameters for all commands.

| Option | Description |
| --------- | ---------------------------- |
| --host | Asterisk AMI server host |
| --port | Asterisk AMI server port |
| --username | Asterisk AMI server username |
| --secret | Asterisk AMI server secret |

**Listen ami events**

```sh
./ace ami:listen
```
```js
// app/Listeners/AsteriskAmi.js
'use strict'

const AsteriskAmi = exports = module.exports = {}

AsteriskAmi.onEvent = function * (event) {
console.log(`${event.Event} handled`)
}

// bootsrap/events.js
...
Event.when('ami.events.*', 'AsteriskAmi.onEvent')
...
```
For more information about `event` property see [asterisk-ami-client](https://github.com/BelirafoN/asterisk-ami-client) documentation.

If would you like to see event log in the console use *debug* option
```sh
./ace ami:listen --debug
```

**Send ami action**

```sh
./ace ami:action --props=':;:' --id=
```

```js
const props = _.reduce({
: ,
:
}, (result, value, key) => {
if (result.length) {
result = `${result};`
}
result += `${key}:${value}`
return result
}, '')

// Foo:Bar,ActionID:
Ace.call('ami:action', [], {
props,
id:
});
```
Options `props` and `id` is not required.

**Send sms messages using chan dongle**

```sh
./ace ami:dongle:sms --id=
```

```js
Ace.call('ami:dongle:sms', [
,
,
,
], {
id:
});
```
For sending long messages use *pdu* mode.
```sh
./ace ami:dongle:sms --pdu --id=
```

```js
Ace.call('ami:dongle:sms', [
,
,
,
], {
pdu: true,
id:
});
```

Argument `device` and option `id` is not required.

**Send ussd commands using chan dongle**

```sh
./ace ami:dongle:ussd --id=
```

```js
Ace.call('ami:dongle:ussd', [
,

], {
id:
});
```

Option `id` is not required.

**Without Adonis App**

See [bin folder](https://github.com/enniel/adonis-asterisk-ami/tree/master/bin)

## Credits

- [Evgeni Razumov](https://github.com/enniel)

## Support

Having trouble? [Open an issue](https://github.com/enniel/adonis-asterisk-ami/issues/new)!

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.