Javascript SDK
A convenient way to interact with the Elarian APIs.
Install
You can install the package from npm by running:
$ npm install elarian
Usage
const { Client, Customer } = require('elarian');
<script src="dist/elarian.min.js"></script>
const { Client, Customer } = Elarian;
const client = await Client.newInstance({
apiKey: 'test_api_key',
authToken: 'test_auth_token',
orgId: 'test_org_id',
appId: 'test_app_id',
});
client.on('ussdSession', async (data, customer) => {
const {
input,
sessionId,
} = data;
const metadata = await customer.leaseMetadata('awesomeSurvey');
let {
name,
state = 'newbie',
} = metadata;
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.updateMetadata({
awesomeSurvey: {
state,
name,
},
});
return 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.