Elarian
A convenient way to interact with the Elarian APIs.
Install
You can install the package from npm by running:
$ npm install elarian
Usage
const { Elarian } = require('elarian');
const client = await Elarian.newInstance({
apiKey: 'YOUR_API_KEY',
orgId: 'YOUR_ORG_ID',
appId: 'YOUR_APP_ID',
});
client.on('ussdSession', async ({ data, customer}, callback) => {
const {
input,
sessionId,
} = data;
const appData = await customer.leaseAppData();
let {
name,
state = 'newbie',
} = appData;
const menu = {
text: null,
isTerminal: true,
};
switch (state) {
case 'veteran':
if (name) {
menu.text = `Welcome back ${name}! What is your new name?`;
menu.isTerminal = false;
} else {
name = input.value;
menu.text = `Thank you for trying Elarian, ${name}!`;
menu.isTerminal = true;
await customer.sendMessage(
{ number: 'Elarian', provider: 'telco' },
{ text: `Hey ${name}! Thank you for trying out Elarian` },
);
}
break;
case 'newbie':
default:
menu.text = 'Hey there, welcome to Elarian! What\'s your name?';
menu.isTerminal = false;
state = 'veteran';
break;
}
await customer.updateAppData({ state, name });
callback(null, menu);
});
Documentation
Take a look at the API docs here. For detailed info on this SDK, see the documentation.
Development
Run all tests:
$ npm install
$ npm test
Issues
If you find a bug, please file an issue on our issue tracker on GitHub.