Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

elarian

Package Overview
Dependencies
Maintainers
2
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elarian - npm Package Compare versions

Comparing version 0.1.20 to 0.2.0

CHANGELOG

738

docs/README.md
## Classes
<dl>
<dt><a href="#Elarian">Elarian</a></dt>
<dt><a href="#Client">Client</a></dt>
<dd></dd>
<dt><a href="#Customer">Customer</a></dt>
<dd></dd>
<dt><a href="#Simulator">Simulator</a></dt>
<dt><a href="#Elarian">Elarian</a> ⇐ <code><a href="#Client">Client</a></code></dt>
<dd></dd>
<dt><a href="#Simulator">Simulator</a> ⇐ <code><a href="#Client">Client</a></code></dt>
<dd></dd>
</dl>
<a name="Elarian"></a>
<a name="Client"></a>
## Elarian
## Client
**Kind**: global class
* [Elarian](#Elarian)
* [new Elarian(config)](#new_Elarian_new)
* [.Customer](#Elarian+Customer)
* [new this.Customer()](#new_Elarian+Customer_new)
* [.generateAuthToken()](#Elarian+generateAuthToken) ⇒ <code>AuthToken</code>
* [.connect()](#Elarian+connect)
* [.isConnected()](#Elarian+isConnected)
* [.disconnect()](#Elarian+disconnect)
* [.sendMessage(customer, channelNumber, message)](#Elarian+sendMessage) ⇒ <code>MessageStatus</code>
* [.sendMessageByTag(tag, channelNumber, body)](#Elarian+sendMessageByTag) ⇒ <code>WorkStatus</code>
* [.replyToMessage(customer, replyToMessageId, body)](#Elarian+replyToMessage) ⇒ <code>MessageStatus</code>
* [.updateMessagingConsent(customer, channelNumber, action)](#Elarian+updateMessagingConsent) ⇒ <code>ConsentStatus</code>
* [.registerListerner(event, listener)](#Elarian+registerListerner)
* [.on(event, listener)](#Elarian+on)
* [.removeListener(event)](#Elarian+removeListener)
* [.off(event)](#Elarian+off)
* [.initiatePayment(debitParty, creditParty, value)](#Elarian+initiatePayment) ⇒ <code>PaymentStatus</code>
* [.getCustomerState(customer)](#Elarian+getCustomerState) ⇒ <code>CustomerState</code>
* [.adoptCustomerState(customer, otherCustomer)](#Elarian+adoptCustomerState) ⇒ <code>UpdateStatus</code>
* [.updateCustomerTag(customer, tags)](#Elarian+updateCustomerTag) ⇒ <code>UpdateStatus</code>
* [.deleteCustomerTag(customer, tags)](#Elarian+deleteCustomerTag) ⇒ <code>UpdateStatus</code>
* [.updateCustomerSecondaryId(customer, secondaryIds)](#Elarian+updateCustomerSecondaryId) ⇒ <code>UpdateStatus</code>
* [.deleteCustomerSecondaryId(customer, secondaryIds)](#Elarian+deleteCustomerSecondaryId) ⇒ <code>UpdateStatus</code>
* [.addCustomerReminder(customer, reminder)](#Elarian+addCustomerReminder) ⇒ <code>UpdateStatus</code>
* [.cancelCustomerReminder(customer, key)](#Elarian+cancelCustomerReminder) ⇒ <code>UpdateStatus</code>
* [.addCustomerReminderByTag(tag, reminder)](#Elarian+addCustomerReminderByTag) ⇒ <code>WorkStatus</code>
* [.cancelCustomerReminderByTag(tag, key)](#Elarian+cancelCustomerReminderByTag) ⇒ <code>WorkStatus</code>
* [.updateCustomerMetadata(customer, metadata)](#Elarian+updateCustomerMetadata) ⇒ <code>UpdateStatus</code>
* [.deleteCustomerMetadata(customer, keys)](#Elarian+deleteCustomerMetadata) ⇒ <code>UpdateStatus</code>
* [.updateCustomerAppData(customer, data)](#Elarian+updateCustomerAppData) ⇒ <code>UpdateStatus</code>
* [.leaseCustomerAppData(customer)](#Elarian+leaseCustomerAppData) ⇒ <code>LeasedAppData</code>
* [.deleteCustomerAppData(customer)](#Elarian+deleteCustomerAppData) ⇒ <code>UpdateStatus</code>
* [.updateCustomerActivity(customerNumber, channelNumber, activity)](#Elarian+updateCustomerActivity) ⇒ <code>UpdateStatus</code>
* [.makeVoiceCall(customer, channelNumber, actions)](#Elarian+makeVoiceCall) ⇒ <code>VoiceStatus</code>
* [Client](#Client)
* [new Client(config)](#new_Client_new)
* [.connect()](#Client+connect) ⇒ [<code>Elarian</code>](#Elarian)
* [.isConnected()](#Client+isConnected) ⇒ <code>boolean</code>
* [.disconnect()](#Client+disconnect)
* [.registerNotificationHandler(event, handler)](#Client+registerNotificationHandler) ⇒ [<code>Client</code>](#Client)
* [.on(event, handler)](#Client+on) ⇒ [<code>Client</code>](#Client)
<a name="new_Elarian_new"></a>
<a name="new_Client_new"></a>
### new Elarian(config)
### new Client(config)
<p>Instantiate an elarian client. You have to call connect() on then client to start using it</p>

@@ -60,95 +35,30 @@

| --- | --- |
| config | <code>ElarianConfig</code> |
| config | <code>ClientConfig</code> |
<a name="Elarian+Customer"></a>
<a name="Client+connect"></a>
### elarian.Customer
**Kind**: instance class of [<code>Elarian</code>](#Elarian)
<a name="new_Elarian+Customer_new"></a>
### client.connect() ⇒ [<code>Elarian</code>](#Elarian)
<p>Connecto to elarian servers</p>
#### new this.Customer()
<p>A customer object. @see [Customer](#Customer)</p>
**Kind**: instance method of [<code>Client</code>](#Client)
**Returns**: [<code>Elarian</code>](#Elarian) - <p>this instance</p>
<a name="Client+isConnected"></a>
<a name="Elarian+generateAuthToken"></a>
### elarian.generateAuthToken() ⇒ <code>AuthToken</code>
<p>Generate a short-lived auth token to use instead of apiKey. Used for browser and mobile clients.</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
<a name="Elarian+connect"></a>
### elarian.connect()
<p>Connect to the elarian server</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
<a name="Elarian+isConnected"></a>
### elarian.isConnected()
### client.isConnected() ⇒ <code>boolean</code>
<p>Check if client is connected</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
<a name="Elarian+disconnect"></a>
**Kind**: instance method of [<code>Client</code>](#Client)
<a name="Client+disconnect"></a>
### elarian.disconnect()
### client.disconnect()
<p>Disconnect from the elarian server</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
<a name="Elarian+sendMessage"></a>
**Kind**: instance method of [<code>Client</code>](#Client)
<a name="Client+registerNotificationHandler"></a>
### elarian.sendMessage(customer, channelNumber, message) ⇒ <code>MessageStatus</code>
<p>Send a message</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
| Param | Type |
| --- | --- |
| customer | [<code>Customer</code>](#Customer) |
| channelNumber | <code>MessagingChannelNumber</code> |
| message | <code>Message</code> |
<a name="Elarian+sendMessageByTag"></a>
### elarian.sendMessageByTag(tag, channelNumber, body) ⇒ <code>WorkStatus</code>
<p>Send message by tag</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
| Param | Type |
| --- | --- |
| tag | <code>Tag</code> |
| channelNumber | <code>MessagingChannelNumber</code> |
| body | <code>Message</code> |
<a name="Elarian+replyToMessage"></a>
### elarian.replyToMessage(customer, replyToMessageId, body) ⇒ <code>MessageStatus</code>
<p>Reply to a received message</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
| Param | Type |
| --- | --- |
| customer | [<code>Customer</code>](#Customer) |
| replyToMessageId | <code>string</code> |
| body | <code>Message</code> |
<a name="Elarian+updateMessagingConsent"></a>
### elarian.updateMessagingConsent(customer, channelNumber, action) ⇒ <code>ConsentStatus</code>
<p>Allow or block a customer from receiving messages from a channel</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
| Param | Type | Description |
| --- | --- | --- |
| customer | [<code>Customer</code>](#Customer) | |
| channelNumber | <code>MessagingChannelNumber</code> | |
| action | <code>string</code> | <p>allow or block</p> |
<a name="Elarian+registerListerner"></a>
### elarian.registerListerner(event, listener)
### client.registerNotificationHandler(event, handler) ⇒ [<code>Client</code>](#Client)
<p>Register a listener to watch out for events. Can also be called with <code>client.on(event,listener)</code></p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
**Kind**: instance method of [<code>Client</code>](#Client)
**Returns**: [<code>Client</code>](#Client) - <p>this instance</p>

@@ -158,10 +68,11 @@ | Param | Type | Description |

| event | <code>Event</code> | <p>The event whose listener to register</p> |
| listener | <code>EventListener</code> | <p>A function that reacts to events</p> |
| handler | <code>NotificationHandler</code> | <p>A function that reacts to events</p> |
<a name="Elarian+on"></a>
<a name="Client+on"></a>
### elarian.on(event, listener)
### client.on(event, handler) ⇒ [<code>Client</code>](#Client)
<p>Register a listener to watch out for events. Can also be called with <code>client.registerListerner(event,listener)</code></p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
**Kind**: instance method of [<code>Client</code>](#Client)
**Returns**: [<code>Client</code>](#Client) - <p>this instance</p>

@@ -171,304 +82,180 @@ | Param | Type | Description |

| event | <code>Event</code> | <p>The event whose listener to register</p> |
| listener | <code>EventListener</code> | <p>A function that reacts to events</p> |
| handler | <code>NotificationHandler</code> | <p>A function that reacts to events</p> |
<a name="Elarian+removeListener"></a>
<a name="Customer"></a>
### elarian.removeListener(event)
<p>Remove listener registered for event. Can also be called with <code>client.off(event)</code></p>
## Customer
**Kind**: global class
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
* [Customer](#Customer)
* [new Customer(params)](#new_Customer_new)
* [.getState()](#Customer+getState) ⇒ <code>CustomerState</code>
* [.adoptState(otherCustomer)](#Customer+adoptState) ⇒ <code>CustomerStateUpdateReply</code>
* [.sendMessage(channelNumber, message)](#Customer+sendMessage) ⇒ <code>MessageReply</code>
* [.replyToMessage(messageId, message)](#Customer+replyToMessage) ⇒ <code>MessageReply</code>
* [.updateActivity(channelNumber, activity)](#Customer+updateActivity) ⇒ <code>CustomerStateUpdateReply</code>
* [.updateMessagingConsent(channelNumber, action)](#Customer+updateMessagingConsent) ⇒ <code>ConsentUpdateReply</code>
* [.leaseAppData()](#Customer+leaseAppData) ⇒ <code>LeasedAppData</code>
* [.updateAppData(data)](#Customer+updateAppData) ⇒ <code>CustomerStateUpdateReply</code>
* [.deleteAppData()](#Customer+deleteAppData) ⇒ <code>CustomerStateUpdateReply</code>
* [.updateMetadata(metadata)](#Customer+updateMetadata) ⇒ <code>CustomerStateUpdateReply</code>
* [.deleteMetadata(keys)](#Customer+deleteMetadata) ⇒ <code>CustomerStateUpdateReply</code>
* [.updateSecondaryIds(secondaryIds)](#Customer+updateSecondaryIds) ⇒ <code>CustomerStateUpdateReply</code>
* [.deleteSecondaryIds(secondaryIds)](#Customer+deleteSecondaryIds) ⇒ <code>CustomerStateUpdateReply</code>
* [.updateTags(tags)](#Customer+updateTags) ⇒ <code>CustomerStateUpdateReply</code>
* [.deleteTags(tags)](#Customer+deleteTags) ⇒ <code>CustomerStateUpdateReply</code>
* [.addReminder(reminder)](#Customer+addReminder) ⇒ <code>CustomerStateUpdateReply</code>
* [.cancelReminder(key)](#Customer+cancelReminder) ⇒ <code>CustomerStateUpdateReply</code>
* [.getMetadata()](#Customer+getMetadata) ⇒ <code>Object</code>
| Param | Type | Description |
| --- | --- | --- |
| event | <code>Event</code> | <p>The event whose listener to remove</p> |
<a name="new_Customer_new"></a>
<a name="Elarian+off"></a>
### new Customer(params)
<p>A customer is your end-user, represented by a number (from a cellular, facebook or telegram)</p>
### elarian.off(event)
<p>Remove listener registered for event. Can also be called with <code>client.removeListener(event)</code></p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
| Param | Type | Description |
| --- | --- | --- |
| event | <code>Event</code> | <p>The event whose listener to remove</p> |
<a name="Elarian+initiatePayment"></a>
### elarian.initiatePayment(debitParty, creditParty, value) ⇒ <code>PaymentStatus</code>
<p>Initiate a payment transaction</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
| Param | Type |
| --- | --- |
| debitParty | <code>CustomerPayment</code> \| <code>Wallet</code> \| <code>Purse</code> |
| creditParty | <code>CustomerPayment</code> \| <code>Wallet</code> \| <code>Purse</code> |
| value | <code>Cash</code> |
| params | <code>CustomerParams</code> |
<a name="Elarian+getCustomerState"></a>
<a name="Customer+getState"></a>
### elarian.getCustomerState(customer) ⇒ <code>CustomerState</code>
### customer.getState() ⇒ <code>CustomerState</code>
<p>Fetch the customer's current state.</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
**Kind**: instance method of [<code>Customer</code>](#Customer)
<a name="Customer+adoptState"></a>
| Param | Type |
| --- | --- |
| customer | [<code>Customer</code>](#Customer) |
### customer.adoptState(otherCustomer) ⇒ <code>CustomerStateUpdateReply</code>
<p>Merge otherCustomer's state into this customer's state and discard otherCustomer</p>
<a name="Elarian+adoptCustomerState"></a>
**Kind**: instance method of [<code>Customer</code>](#Customer)
### elarian.adoptCustomerState(customer, otherCustomer) ⇒ <code>UpdateStatus</code>
<p>Adopt another customer's state</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
| Param | Type |
| --- | --- |
| customer | [<code>Customer</code>](#Customer) |
| otherCustomer | [<code>Customer</code>](#Customer) |
<a name="Elarian+updateCustomerTag"></a>
<a name="Customer+sendMessage"></a>
### elarian.updateCustomerTag(customer, tags) ⇒ <code>UpdateStatus</code>
<p>Update a customer's tag list</p>
### customer.sendMessage(channelNumber, message) ⇒ <code>MessageReply</code>
<p>Send a message to the customer from the specified channel number.</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
**Kind**: instance method of [<code>Customer</code>](#Customer)
| Param | Type |
| --- | --- |
| customer | [<code>Customer</code>](#Customer) |
| tags | <code>Array.&lt;Tag&gt;</code> |
| channelNumber | <code>MessagingChannelNumber</code> |
| message | <code>Message</code> |
<a name="Elarian+deleteCustomerTag"></a>
<a name="Customer+replyToMessage"></a>
### elarian.deleteCustomerTag(customer, tags) ⇒ <code>UpdateStatus</code>
<p>Remove tags from a customer</p>
### customer.replyToMessage(messageId, message) ⇒ <code>MessageReply</code>
<p>Reply to a message</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
**Kind**: instance method of [<code>Customer</code>](#Customer)
| Param | Type |
| --- | --- |
| customer | [<code>Customer</code>](#Customer) |
| tags | <code>Array.&lt;string&gt;</code> |
| messageId | <code>string</code> |
| message | <code>Message</code> |
<a name="Elarian+updateCustomerSecondaryId"></a>
<a name="Customer+updateActivity"></a>
### elarian.updateCustomerSecondaryId(customer, secondaryIds) ⇒ <code>UpdateStatus</code>
<p>Update a customer's secondary Ids</p>
### customer.updateActivity(channelNumber, activity) ⇒ <code>CustomerStateUpdateReply</code>
<p>Initiate a customer activity</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
**Kind**: instance method of [<code>Customer</code>](#Customer)
| Param | Type |
| --- | --- |
| customer | [<code>Customer</code>](#Customer) |
| secondaryIds | <code>Array.&lt;SecondaryId&gt;</code> |
| channelNumber | <code>ActivityChannelNumber</code> |
| activity | <code>Activity</code> |
<a name="Elarian+deleteCustomerSecondaryId"></a>
<a name="Customer+updateMessagingConsent"></a>
### elarian.deleteCustomerSecondaryId(customer, secondaryIds) ⇒ <code>UpdateStatus</code>
<p>Delete a customer's secondary Ids</p>
### customer.updateMessagingConsent(channelNumber, action) ⇒ <code>ConsentUpdateReply</code>
<p>Allow or block a customer from receiving messages from a channel</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
**Kind**: instance method of [<code>Customer</code>](#Customer)
| Param | Type |
| --- | --- |
| customer | [<code>Customer</code>](#Customer) |
| secondaryIds | <code>Array.&lt;SecondaryId&gt;</code> |
| Param | Type | Description |
| --- | --- | --- |
| channelNumber | <code>MessagingChannelNumber</code> | |
| action | <code>string</code> | <p>allow or block</p> |
<a name="Elarian+addCustomerReminder"></a>
<a name="Customer+leaseAppData"></a>
### elarian.addCustomerReminder(customer, reminder) ⇒ <code>UpdateStatus</code>
<p>Set a reminder to be triggered at the specified time for a particular customer</p>
### customer.leaseAppData() ⇒ <code>LeasedAppData</code>
<p>Fetches the customer's app data and lock it from fetching(for up to <b>90s</b>)
until next call to update app data.</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
**Kind**: instance method of [<code>Customer</code>](#Customer)
<a name="Customer+updateAppData"></a>
| Param | Type |
| --- | --- |
| customer | [<code>Customer</code>](#Customer) |
| reminder | <code>Reminder</code> |
### customer.updateAppData(data) ⇒ <code>CustomerStateUpdateReply</code>
<p>Sets some app data on the customer.
Values in the data object can either be strings or buffers,
depending on the set serializer. @see [ConnectionOptions](ConnectionOptions)</p>
<a name="Elarian+cancelCustomerReminder"></a>
**Kind**: instance method of [<code>Customer</code>](#Customer)
### elarian.cancelCustomerReminder(customer, key) ⇒ <code>UpdateStatus</code>
<p>Cancels a previously set reminder with the key <code>key</code> on the customer</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
| Param | Type |
| --- | --- |
| customer | [<code>Customer</code>](#Customer) |
| key | <code>string</code> |
| data | <code>Object</code> |
<a name="Elarian+addCustomerReminderByTag"></a>
<a name="Customer+deleteAppData"></a>
### elarian.addCustomerReminderByTag(tag, reminder) ⇒ <code>WorkStatus</code>
<p>Set a reminder to be triggered at the specified time for customers with the particular tag</p>
### customer.deleteAppData() ⇒ <code>CustomerStateUpdateReply</code>
<p>Remove customer's app data</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
**Kind**: instance method of [<code>Customer</code>](#Customer)
<a name="Customer+updateMetadata"></a>
| Param | Type |
| --- | --- |
| tag | <code>Tag</code> |
| reminder | <code>Reminder</code> |
<a name="Elarian+cancelCustomerReminderByTag"></a>
### elarian.cancelCustomerReminderByTag(tag, key) ⇒ <code>WorkStatus</code>
<p>Cancels a previously set reminder with tag <code>tag</code> and key <code>key</code></p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
| Param | Type |
| --- | --- |
| tag | <code>Tag</code> |
| key | <code>string</code> |
<a name="Elarian+updateCustomerMetadata"></a>
### elarian.updateCustomerMetadata(customer, metadata) ⇒ <code>UpdateStatus</code>
### customer.updateMetadata(metadata) ⇒ <code>CustomerStateUpdateReply</code>
<p>Sets some metadata on the customer.
Values in the metadata object can either be strings or buffers,
depending on your serializer. @see [Client](Client)</p>
depending on the set serializer</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
**Kind**: instance method of [<code>Customer</code>](#Customer)
| Param | Type |
| --- | --- |
| customer | [<code>Customer</code>](#Customer) |
| metadata | <code>Object</code> |
<a name="Elarian+deleteCustomerMetadata"></a>
<a name="Customer+deleteMetadata"></a>
### elarian.deleteCustomerMetadata(customer, keys) ⇒ <code>UpdateStatus</code>
<p>Remove some metadata from a customer.</p>
### customer.deleteMetadata(keys) ⇒ <code>CustomerStateUpdateReply</code>
<p>Remove some metadata from a customer. <code>keys</code> is an array of strings</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
**Kind**: instance method of [<code>Customer</code>](#Customer)
| Param | Type |
| --- | --- |
| customer | [<code>Customer</code>](#Customer) |
| keys | <code>Array.&lt;string&gt;</code> |
<a name="Elarian+updateCustomerAppData"></a>
<a name="Customer+updateSecondaryIds"></a>
### elarian.updateCustomerAppData(customer, data) ⇒ <code>UpdateStatus</code>
<p>Sets some app data on the customer.
Value of the data object can either be a string or a buffer,
depending on your serializer. @see [Client](Client)</p>
### customer.updateSecondaryIds(secondaryIds) ⇒ <code>CustomerStateUpdateReply</code>
<p>Update a customer's secondary Ids</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
**Kind**: instance method of [<code>Customer</code>](#Customer)
| Param | Type |
| --- | --- |
| customer | [<code>Customer</code>](#Customer) |
| data | <code>Object</code> |
| secondaryIds | <code>Array.&lt;SecondaryId&gt;</code> |
<a name="Elarian+leaseCustomerAppData"></a>
<a name="Customer+deleteSecondaryIds"></a>
### elarian.leaseCustomerAppData(customer) ⇒ <code>LeasedAppData</code>
<p>Fetches the customer's app data and lock it from fetching(for up to <b>90s</b>)
until next call to update app data.</p>
### customer.deleteSecondaryIds(secondaryIds) ⇒ <code>CustomerStateUpdateReply</code>
<p>Remove some secondary Ids from a customer</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
| Param | Type |
| --- | --- |
| customer | [<code>Customer</code>](#Customer) |
<a name="Elarian+deleteCustomerAppData"></a>
### elarian.deleteCustomerAppData(customer) ⇒ <code>UpdateStatus</code>
<p>Remove customer's app data.</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
| Param | Type |
| --- | --- |
| customer | [<code>Customer</code>](#Customer) |
<a name="Elarian+updateCustomerActivity"></a>
### elarian.updateCustomerActivity(customerNumber, channelNumber, activity) ⇒ <code>UpdateStatus</code>
<p>Initiate a customer activity</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
| Param | Type |
| --- | --- |
| customerNumber | <code>CustomerNumber</code> |
| channelNumber | <code>ActivityChannelNumber</code> |
| activity | <code>Activity</code> |
<a name="Elarian+makeVoiceCall"></a>
### elarian.makeVoiceCall(customer, channelNumber, actions) ⇒ <code>VoiceStatus</code>
<p>Initiate a voice call to customer from channelNumber</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
| Param | Type |
| --- | --- |
| customer | [<code>Customer</code>](#Customer) |
| channelNumber | <code>string</code> |
| actions | <code>Array.&lt;VoiceAction&gt;</code> |
<a name="Customer"></a>
## Customer
**Kind**: global class
* [Customer](#Customer)
* [new Customer(params)](#new_Customer_new)
* [.getState()](#Customer+getState) ⇒ <code>CustomerState</code>
* [.adoptState(otherCustomer)](#Customer+adoptState) ⇒ <code>UpdateStatus</code>
* [.updateTag(tags)](#Customer+updateTag) ⇒ <code>UpdateStatus</code>
* [.deleteTag(tags)](#Customer+deleteTag) ⇒ <code>UpdateStatus</code>
* [.updateSecondaryId(secondaryIds)](#Customer+updateSecondaryId) ⇒ <code>UpdateStatus</code>
* [.deleteSecondaryId(secondaryIds)](#Customer+deleteSecondaryId) ⇒ <code>UpdateStatus</code>
* [.addReminder(reminder)](#Customer+addReminder) ⇒ <code>UpdateStatus</code>
* [.cancelReminder(key)](#Customer+cancelReminder) ⇒ <code>UpdateStatus</code>
* [.getMetadata()](#Customer+getMetadata) ⇒ <code>Object</code>
* [.updateMetadata(metadata)](#Customer+updateMetadata) ⇒ <code>UpdateStatus</code>
* [.deleteMetadata(keys)](#Customer+deleteMetadata) ⇒ <code>UpdateStatus</code>
* [.updateAppData(data)](#Customer+updateAppData) ⇒ <code>UpdateStatus</code>
* [.leaseAppData()](#Customer+leaseAppData) ⇒ <code>LeasedAppData</code>
* [.deleteAppData()](#Customer+deleteAppData) ⇒ <code>UpdateStatus</code>
* [.sendMessage(channelNumber, body)](#Customer+sendMessage) ⇒ <code>MessageStatus</code>
* [.makeVoiceCall(channelNumber, actions)](#Customer+makeVoiceCall) ⇒ <code>MessageStatus</code>
* [.updateMessagingConsent(channelNumber, action)](#Customer+updateMessagingConsent) ⇒ <code>ConsentStatus</code>
* [.updateActivity(channelNumber, sessionId)](#Customer+updateActivity) ⇒ <code>UpdateStatus</code>
* [.requestPayment(source, destination, value)](#Customer+requestPayment) ⇒ <code>PaymentStatus</code>
<a name="new_Customer_new"></a>
### new Customer(params)
<p>A customer is your end-user, represented by a number (from a cellular, facebook or telegram)</p>
| Param | Type |
| --- | --- |
| params | <code>CustomerParams</code> |
<a name="Customer+getState"></a>
### customer.getState() ⇒ <code>CustomerState</code>
<p>Fetch the customer's current state.</p>
**Kind**: instance method of [<code>Customer</code>](#Customer)
<a name="Customer+adoptState"></a>
### customer.adoptState(otherCustomer) ⇒ <code>UpdateStatus</code>
<p>Merge otherCustomer's state into this customer's state and discard otherCustomer</p>
**Kind**: instance method of [<code>Customer</code>](#Customer)
| Param | Type |
| --- | --- |
| otherCustomer | [<code>Customer</code>](#Customer) |
| secondaryIds | <code>Array.&lt;SecondaryId&gt;</code> |
<a name="Customer+updateTag"></a>
<a name="Customer+updateTags"></a>
### customer.updateTag(tags) ⇒ <code>UpdateStatus</code>
### customer.updateTags(tags) ⇒ <code>CustomerStateUpdateReply</code>
<p>Update a customer's tag list.</p>

@@ -482,5 +269,5 @@

<a name="Customer+deleteTag"></a>
<a name="Customer+deleteTags"></a>
### customer.deleteTag(tags) ⇒ <code>UpdateStatus</code>
### customer.deleteTags(tags) ⇒ <code>CustomerStateUpdateReply</code>
<p>Remove some tags from a customer</p>

@@ -492,29 +279,7 @@

| --- | --- |
| tags | <code>Array.&lt;Tag&gt;</code> |
| tags | <code>Array.&lt;string&gt;</code> |
<a name="Customer+updateSecondaryId"></a>
### customer.updateSecondaryId(secondaryIds) ⇒ <code>UpdateStatus</code>
<p>Update a customer's secondary Ids</p>
**Kind**: instance method of [<code>Customer</code>](#Customer)
| Param | Type |
| --- | --- |
| secondaryIds | <code>Array.&lt;SecondaryId&gt;</code> |
<a name="Customer+deleteSecondaryId"></a>
### customer.deleteSecondaryId(secondaryIds) ⇒ <code>UpdateStatus</code>
<p>Remove some secondary Ids from a customer</p>
**Kind**: instance method of [<code>Customer</code>](#Customer)
| Param | Type |
| --- | --- |
| secondaryIds | <code>Array.&lt;SecondaryId&gt;</code> |
<a name="Customer+addReminder"></a>
### customer.addReminder(reminder) ⇒ <code>UpdateStatus</code>
### customer.addReminder(reminder) ⇒ <code>CustomerStateUpdateReply</code>
<p>Set a reminder to be triggered at the specified time for a particular customer</p>

@@ -530,3 +295,3 @@

### customer.cancelReminder(key) ⇒ <code>UpdateStatus</code>
### customer.cancelReminder(key) ⇒ <code>CustomerStateUpdateReply</code>
<p>Cancels a previously set reminder with the key <code>key</code> on the customer</p>

@@ -546,123 +311,159 @@

**Kind**: instance method of [<code>Customer</code>](#Customer)
<a name="Customer+updateMetadata"></a>
<a name="Elarian"></a>
### customer.updateMetadata(metadata) ⇒ <code>UpdateStatus</code>
<p>Sets some metadata on the customer.
Values in the metadata object can either be strings or buffers,
depending on the set serializer</p>
## Elarian ⇐ [<code>Client</code>](#Client)
**Kind**: global class
**Extends**: [<code>Client</code>](#Client)
**Kind**: instance method of [<code>Customer</code>](#Customer)
* [Elarian](#Elarian) ⇐ [<code>Client</code>](#Client)
* [new Elarian(config)](#new_Elarian_new)
* [.Customer](#Elarian+Customer)
* [new this.Customer()](#new_Elarian+Customer_new)
* [.generateAuthToken()](#Elarian+generateAuthToken) ⇒ <code>AuthToken</code>
* [.sendMessageByTag(tag, channelNumber, message)](#Elarian+sendMessageByTag) ⇒ <code>TagUpdateReply</code>
* [.initiatePayment(debitParty, creditParty, value)](#Elarian+initiatePayment) ⇒ <code>InitiatePaymentReply</code>
* [.addCustomerReminderByTag(tag, reminder)](#Elarian+addCustomerReminderByTag) ⇒ <code>TagUpdateReply</code>
* [.cancelCustomerReminderByTag(tag, key)](#Elarian+cancelCustomerReminderByTag) ⇒ <code>TagUpdateReply</code>
* [.connect()](#Client+connect) ⇒ [<code>Elarian</code>](#Elarian)
* [.isConnected()](#Client+isConnected) ⇒ <code>boolean</code>
* [.disconnect()](#Client+disconnect)
* [.registerNotificationHandler(event, handler)](#Client+registerNotificationHandler) ⇒ [<code>Client</code>](#Client)
* [.on(event, handler)](#Client+on) ⇒ [<code>Client</code>](#Client)
<a name="new_Elarian_new"></a>
### new Elarian(config)
<p>Instantiate an elarian client. You have to call connect() on then client to start using it</p>
| Param | Type |
| --- | --- |
| metadata | <code>Object</code> |
| config | <code>ClientConfig</code> |
<a name="Customer+deleteMetadata"></a>
<a name="Elarian+Customer"></a>
### customer.deleteMetadata(keys) ⇒ <code>UpdateStatus</code>
<p>Remove some metadata from a customer. <code>keys</code> is an array of strings</p>
### elarian.Customer
**Kind**: instance class of [<code>Elarian</code>](#Elarian)
<a name="new_Elarian+Customer_new"></a>
**Kind**: instance method of [<code>Customer</code>](#Customer)
#### new this.Customer()
<p>A customer object. @see [Customer](#Customer)</p>
| Param | Type |
| --- | --- |
| keys | <code>Array.&lt;string&gt;</code> |
<a name="Elarian+generateAuthToken"></a>
<a name="Customer+updateAppData"></a>
### elarian.generateAuthToken() ⇒ <code>AuthToken</code>
<p>Generate a short-lived auth token to use instead of apiKey. Used for browser and mobile clients.</p>
### customer.updateAppData(data) ⇒ <code>UpdateStatus</code>
<p>Sets some app data on the customer.
Values in the data object can either be strings or buffers,
depending on the set serializer</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
<a name="Elarian+sendMessageByTag"></a>
**Kind**: instance method of [<code>Customer</code>](#Customer)
### elarian.sendMessageByTag(tag, channelNumber, message) ⇒ <code>TagUpdateReply</code>
<p>Send message by tag</p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
| Param | Type |
| --- | --- |
| data | <code>Object</code> |
| tag | <code>Tag</code> |
| channelNumber | <code>MessagingChannelNumber</code> |
| message | <code>Message</code> |
<a name="Customer+leaseAppData"></a>
<a name="Elarian+initiatePayment"></a>
### customer.leaseAppData() ⇒ <code>LeasedAppData</code>
<p>Fetches the customer's app data and lock it from fetching(for up to <b>90s</b>)
until next call to update app data.</p>
### elarian.initiatePayment(debitParty, creditParty, value) ⇒ <code>InitiatePaymentReply</code>
<p>Initiate a payment transaction</p>
**Kind**: instance method of [<code>Customer</code>](#Customer)
<a name="Customer+deleteAppData"></a>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
### customer.deleteAppData() ⇒ <code>UpdateStatus</code>
<p>Remove customer's app data</p>
| Param | Type |
| --- | --- |
| debitParty | <code>CustomerPayment</code> \| <code>Wallet</code> \| <code>Purse</code> |
| creditParty | <code>CustomerPayment</code> \| <code>Wallet</code> \| <code>Purse</code> |
| value | <code>Cash</code> |
**Kind**: instance method of [<code>Customer</code>](#Customer)
<a name="Customer+sendMessage"></a>
<a name="Elarian+addCustomerReminderByTag"></a>
### customer.sendMessage(channelNumber, body) ⇒ <code>MessageStatus</code>
<p>Send a message to the customer from the specified channel number.</p>
### elarian.addCustomerReminderByTag(tag, reminder) ⇒ <code>TagUpdateReply</code>
<p>Set a reminder to be triggered at the specified time for customers with the particular tag</p>
**Kind**: instance method of [<code>Customer</code>](#Customer)
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
| Param | Type |
| --- | --- |
| channelNumber | <code>MessagingChannelNumber</code> |
| body | <code>Body</code> |
| tag | <code>Tag</code> |
| reminder | <code>Reminder</code> |
<a name="Customer+makeVoiceCall"></a>
<a name="Elarian+cancelCustomerReminderByTag"></a>
### customer.makeVoiceCall(channelNumber, actions) ⇒ <code>MessageStatus</code>
<p>Initiate a voice call to the customer</p>
### elarian.cancelCustomerReminderByTag(tag, key) ⇒ <code>TagUpdateReply</code>
<p>Cancels a previously set reminder with tag <code>tag</code> and key <code>key</code></p>
**Kind**: instance method of [<code>Customer</code>](#Customer)
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
| Param | Type |
| --- | --- |
| channelNumber | <code>string</code> |
| actions | <code>Array.&lt;VoiceAction&gt;</code> |
| tag | <code>Tag</code> |
| key | <code>string</code> |
<a name="Customer+updateMessagingConsent"></a>
<a name="Client+connect"></a>
### customer.updateMessagingConsent(channelNumber, action) ⇒ <code>ConsentStatus</code>
<p>Allow or block a customer from receiving messages from a channel</p>
### elarian.connect() ⇒ [<code>Elarian</code>](#Elarian)
<p>Connecto to elarian servers</p>
**Kind**: instance method of [<code>Customer</code>](#Customer)
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
**Returns**: [<code>Elarian</code>](#Elarian) - <p>this instance</p>
<a name="Client+isConnected"></a>
| Param | Type | Description |
| --- | --- | --- |
| channelNumber | <code>MessagingChannelNumber</code> | |
| action | <code>string</code> | <p>allow or block</p> |
### elarian.isConnected() ⇒ <code>boolean</code>
<p>Check if client is connected</p>
<a name="Customer+updateActivity"></a>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
<a name="Client+disconnect"></a>
### customer.updateActivity(channelNumber, sessionId) ⇒ <code>UpdateStatus</code>
<p>Initiate a customer activity</p>
### elarian.disconnect()
<p>Disconnect from the elarian server</p>
**Kind**: instance method of [<code>Customer</code>](#Customer)
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
<a name="Client+registerNotificationHandler"></a>
| Param | Type |
| --- | --- |
| channelNumber | <code>ActivityChannelNumber</code> |
| sessionId | <code>Activity</code> |
### elarian.registerNotificationHandler(event, handler) ⇒ [<code>Client</code>](#Client)
<p>Register a listener to watch out for events. Can also be called with <code>client.on(event,listener)</code></p>
<a name="Customer+requestPayment"></a>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
**Returns**: [<code>Client</code>](#Client) - <p>this instance</p>
### customer.requestPayment(source, destination, value) ⇒ <code>PaymentStatus</code>
<p>Initiate a payment transaction</p>
| Param | Type | Description |
| --- | --- | --- |
| event | <code>Event</code> | <p>The event whose listener to register</p> |
| handler | <code>NotificationHandler</code> | <p>A function that reacts to events</p> |
**Kind**: instance method of [<code>Customer</code>](#Customer)
<a name="Client+on"></a>
| Param | Type |
| --- | --- |
| source | <code>PaymentChannelNumber</code> \| <code>Wallet</code> |
| destination | <code>Wallet</code> \| <code>Purse</code> |
| value | <code>Cash</code> |
### elarian.on(event, handler) ⇒ [<code>Client</code>](#Client)
<p>Register a listener to watch out for events. Can also be called with <code>client.registerListerner(event,listener)</code></p>
**Kind**: instance method of [<code>Elarian</code>](#Elarian)
**Returns**: [<code>Client</code>](#Client) - <p>this instance</p>
| Param | Type | Description |
| --- | --- | --- |
| event | <code>Event</code> | <p>The event whose listener to register</p> |
| handler | <code>NotificationHandler</code> | <p>A function that reacts to events</p> |
<a name="Simulator"></a>
## Simulator
## Simulator ⇐ [<code>Client</code>](#Client)
**Kind**: global class
**Extends**: [<code>Client</code>](#Client)
* [Simulator](#Simulator)
* [Simulator](#Simulator) ⇐ [<code>Client</code>](#Client)
* [new Simulator(config)](#new_Simulator_new)
* [.receiveMessage(customerNumber, channelNumber, sessionId, messageParts)](#Simulator+receiveMessage)
* [.receiveMessage(phoneNumber, channelNumber, sessionId, parts)](#Simulator+receiveMessage)
* [.receivePayment(transactionId, customerNumber, channelNumber, value, status)](#Simulator+receivePayment)
* [.updatePaymentStatus(transactionId, status)](#Simulator+updatePaymentStatus)
* [.connect()](#Client+connect) ⇒ [<code>Elarian</code>](#Elarian)
* [.isConnected()](#Client+isConnected) ⇒ <code>boolean</code>
* [.disconnect()](#Client+disconnect)
* [.registerNotificationHandler(event, handler)](#Client+registerNotificationHandler) ⇒ [<code>Client</code>](#Client)
* [.on(event, handler)](#Client+on) ⇒ [<code>Client</code>](#Client)

@@ -677,7 +478,7 @@ <a name="new_Simulator_new"></a>

| --- | --- |
| config | <code>ElarianConfig</code> |
| config | <code>ClientConfig</code> |
<a name="Simulator+receiveMessage"></a>
### simulator.receiveMessage(customerNumber, channelNumber, sessionId, messageParts)
### simulator.receiveMessage(phoneNumber, channelNumber, sessionId, parts)
<p>Initiate a message request</p>

@@ -689,6 +490,6 @@

| --- | --- |
| customerNumber | <code>string</code> |
| phoneNumber | <code>string</code> |
| channelNumber | <code>MessagingChannelNumber</code> |
| sessionId | <code>string</code> |
| messageParts | <code>Array.&lt;SimulatorMessageBody&gt;</code> |
| parts | <code>Array.&lt;SimulatorMessageBody&gt;</code> |

@@ -722,1 +523,46 @@ <a name="Simulator+receivePayment"></a>

<a name="Client+connect"></a>
### simulator.connect() ⇒ [<code>Elarian</code>](#Elarian)
<p>Connecto to elarian servers</p>
**Kind**: instance method of [<code>Simulator</code>](#Simulator)
**Returns**: [<code>Elarian</code>](#Elarian) - <p>this instance</p>
<a name="Client+isConnected"></a>
### simulator.isConnected() ⇒ <code>boolean</code>
<p>Check if client is connected</p>
**Kind**: instance method of [<code>Simulator</code>](#Simulator)
<a name="Client+disconnect"></a>
### simulator.disconnect()
<p>Disconnect from the elarian server</p>
**Kind**: instance method of [<code>Simulator</code>](#Simulator)
<a name="Client+registerNotificationHandler"></a>
### simulator.registerNotificationHandler(event, handler) ⇒ [<code>Client</code>](#Client)
<p>Register a listener to watch out for events. Can also be called with <code>client.on(event,listener)</code></p>
**Kind**: instance method of [<code>Simulator</code>](#Simulator)
**Returns**: [<code>Client</code>](#Client) - <p>this instance</p>
| Param | Type | Description |
| --- | --- | --- |
| event | <code>Event</code> | <p>The event whose listener to register</p> |
| handler | <code>NotificationHandler</code> | <p>A function that reacts to events</p> |
<a name="Client+on"></a>
### simulator.on(event, handler) ⇒ [<code>Client</code>](#Client)
<p>Register a listener to watch out for events. Can also be called with <code>client.registerListerner(event,listener)</code></p>
**Kind**: instance method of [<code>Simulator</code>](#Simulator)
**Returns**: [<code>Client</code>](#Client) - <p>this instance</p>
| Param | Type | Description |
| --- | --- | --- |
| event | <code>Event</code> | <p>The event whose listener to register</p> |
| handler | <code>NotificationHandler</code> | <p>A function that reacts to events</p> |

@@ -1,2 +0,2 @@

const Elarian = require('./client');
const Elarian = require('./elarian');

@@ -3,0 +3,0 @@ const { ElarianMessages } = require('./utils');

@@ -0,12 +1,44 @@

/* eslint-disable max-len */
/* global window */
/* eslint-disable no-underscore-dangle */
const validate = require('validate.js');
const { Single } = require('rsocket-flowable');
const Customer = require('./customer');
const {
ElarianMessages,
addMessage,
getStatusString,
getMediaTypeString,
getChannelProviderString,
getMessageReactionString,
getCustomerEventDirectionString,
getCustomerNumberProviderString,
getMessageSessionEndReasonString,
getMessageConsentUpdateActionString,
} = require('./utils');
const {
AppDataUpdate,
DataMapValue,
PaymentStatus,
PaymentChannel,
ActivityChannel,
MessagingChannel,
VoiceCallStatus,
VoiceCallHangupCause,
MessageDeliveryStatus,
ServerToAppNotification,
MessagingConsentUpdateStatus,
ServerToAppNotificationReply,
ServerToSimulatorNotification,
ServerToSimulatorNotificationReply,
} = ElarianMessages;
const { connectRSocket } = require('./utils');
const defaultConfigOptions = {
resumable: false,
lifetime: 60000,
keepAlive: 1000,
resumable: false,
notificationTimeout: 5000,
serializer: {

@@ -27,5 +59,5 @@ type: 'text',

* @class
* @param {ElarianConfig} config
* @param {ClientConfig} config
*/
function Elarian(config) {
function Client(config) {
const opts = {

@@ -71,2 +103,4 @@ ...config,

this._client = null;
this._socket = null;
this.options = opts;

@@ -79,5 +113,8 @@ const configOpts = opts.options || {};

serializer: configOpts.serializer || defaultConfigOptions.serializer,
// eslint-disable-next-line max-len
notificationTimeout: configOpts.notificationTimeout || defaultConfigOptions.notificationTimeout,
};
this.eventListeners = {
// debug
data: null,

@@ -91,36 +128,7 @@

connecting: null,
// Simulator
sendMessage: null,
makeVoiceCall: null,
checkoutPayment: null,
sendChannelPayment: null,
sendCustomerPayment: null,
// App (core)
reminder: null,
messageStatus: null,
paymentStatus: null,
receivedPayment: null,
receivedMessage: null,
customerActivity: null,
sentMessageReaction: null,
walletPaymentStatus: null,
messagingSessionEnded: null,
messagingConsentUpdate: null,
messagingSessionStarted: null,
messagingSessionRenewed: null,
// App (virtual)
voiceCall: null,
ussdSession: null,
receivedSms: null,
receivedEmail: null,
receivedWhatsapp: null,
receivedTelegram: null,
receivedMessenger: null,
};
/**
* Connect to the elarian server
* Connecto to elarian servers
* @returns {Elarian} this instance
*/

@@ -151,3 +159,3 @@ this.connect = function connect() {

}),
notificationHandler: this.notificationHandler(this),
notificationHandler: this._notificationHandler(this),
}).then(({ client, socket }) => {

@@ -176,5 +184,6 @@ this._client = client;

* Check if client is connected
* @returns {boolean}
*/
this.isConnected = function isConnected() {
return this._client && this._socket;
return this._client !== null && this._socket !== null;
};

@@ -208,11 +217,373 @@

}
Customer.prototype.client = this;
/**
* A customer object. @see {@link Customer}
* @class
*/
this.Customer = Customer;
}
module.exports = Elarian;
const cleanUpNotificationPayload = (event, data) => {
/* eslint-disable no-param-reassign */
switch (event) {
// App
case 'reminder':
data.reminder.payload = data.reminder.payload.value;
data.reminder.remindAt = data.reminder.remindAt.seconds;
data.reminder.interval = data.reminder.interval ? data.reminder.interval.seconds : undefined;
break;
case 'messagingSessionStarted':
case 'messagingSessionRenewed':
case 'messagingSessionEnded':
data.sessionId = data.sessionId.value;
data.channelNumber = {
number: data.channelNumber.number,
channel: getChannelProviderString(data.channelNumber.channel, MessagingChannel),
};
if (data.expiresAt) {
data.expiresAt = data.expiresAt.seconds;
}
if (data.duration) {
data.duration = data.duration.seconds;
}
if (data.reason) {
data.reason = getMessageSessionEndReasonString(data.reason);
}
break;
case 'messageStatus':
data.messageId = data.messageId ? data.messageId.value : undefined;
data.status = getStatusString(data.status, MessageDeliveryStatus);
break;
case 'receivedMessage':
data.messageId = data.messageId ? data.messageId.value : undefined;
data.sessionId = data.sessionId ? data.sessionId.value : undefined;
data.inReplyTo = data.inReplyTo ? data.inReplyTo.value : undefined;
data.parts = data.partsList.map((part) => ({
...part,
ussd: part.ussd ? part.ussd.value : undefined,
location: part.location ? {
...part.location,
label: part.location.label ? part.location.label.value : undefined,
address: part.location.address ? part.location.address.value : undefined,
} : undefined,
media: part.media ? {
...part.media,
type: getMediaTypeString(part.media.type),
} : undefined,
voice: part.voice ? {
...part.voice,
dtmfDigits: part.voice.dtmfDigits ? part.voice.dtmfDigits.value : undefined,
startedAt: part.voice.startedAt ? part.voice.startedAt.seconds : undefined,
recordingUrl: part.voice.recordingUrl ? part.voice.recordingUrl.value : undefined,
status: getStatusString(part.voice.status, VoiceCallStatus),
direction: getCustomerEventDirectionString(part.voice.direction),
hangupCause: getChannelProviderString(part.voice.hangupCause || 0, VoiceCallHangupCause, /^VOICE_CALL_HANGUP_CAUSE_/),
} : undefined,
}));
data.channelNumber = {
number: data.channelNumber.number,
channel: getChannelProviderString(data.channelNumber.channel, MessagingChannel),
};
switch (data.channelNumber.channel) {
case 'ussd':
data.input = data.parts.map((i) => i.ussd);
data.input = data.input.length > 0 ? data.input.pop() : data.input;
break;
case 'voice':
data.voice = data.parts.map((i) => i.voice);
data.voice = data.voice.length > 0 ? data.voice.pop() : data.voice;
break;
case 'sms':
case 'whatsapp':
case 'telegram':
case 'messenger':
data.text = data.parts.map((i) => i.text);
data.text = data.text.length > 0 ? data.text.pop() : data.text;
data.media = data.parts.map((i) => i.media);
data.media = data.media.length > 0 ? data.media.pop() : data.media;
data.location = data.parts.map((i) => i.location);
data.location = data.location.length > 0 ? data.location.pop() : data.location;
break;
case 'email':
data.email = data.parts.map((i) => i.email);
data.email = data.email.length > 0 ? data.email.pop() : data.email;
break;
default:
break;
}
delete data.parts;
delete data.partsList;
break;
case 'paymentStatus':
data.status = getStatusString(data.status, PaymentStatus);
break;
case 'receivedPayment':
data.status = getStatusString(data.status, PaymentStatus);
data.channelNumber = {
number: data.channelNumber.number,
channel: getChannelProviderString(data.channelNumber.channel, PaymentChannel),
};
break;
case 'walletPaymentStatus':
data.status = getStatusString(data.status, PaymentStatus);
break;
case 'messagingConsentUpdate':
data.sessionId = data.sessionId.value;
data.status = getStatusString(data.status, MessagingConsentUpdateStatus);
data.update = getMessageConsentUpdateActionString(data.update);
data.channelNumber = {
number: data.channelNumber.number,
channel: getChannelProviderString(data.channelNumber.channel, MessagingChannel),
};
break;
case 'customerActivity':
data.sessionId = data.sessionId.value;
data.channelNumber = {
number: data.channelNumber.number,
channel: getChannelProviderString(data.channelNumber.channel, ActivityChannel),
};
break;
case 'sentMessageReaction':
data.messageId = data.messageId.value;
data.channelNumber = {
number: data.channelNumber.number,
channel: getChannelProviderString(data.channelNumber.channel, MessagingChannel),
};
data.reaction = getMessageReactionString(data.reaction);
break;
// Simulator
case 'sendMessage':
case 'makeVoiceCall':
if (data.sessionId) {
data.sessionId = data.sessionId.value;
}
data.channelNumber = {
number: data.channelNumber.number,
channel: getChannelProviderString(data.channelNumber.channel, MessagingChannel),
};
break;
case 'checkoutPayment':
case 'sendChannelPayment':
case 'sendCustomerPayment':
data.transactionId = data.transactionId.value;
data.channelNumber = {
number: data.channelNumber.number,
channel: getChannelProviderString(data.channelNumber.channel, PaymentChannel),
};
break;
default:
break;
}
if (data.customerNumber) {
data.customerNumber = {
number: data.customerNumber.number,
provider: getCustomerNumberProviderString(data.customerNumber.provider),
partition: data.customerNumber.partition ? data.customerNumber.partition.value : undefined,
};
}
/* eslint-enable no-param-reassign */
return data;
};
// eslint-disable-next-line no-underscore-dangle
Client.prototype._notificationHandler = (client) => (incomingPayload) => {
let event;
const { log } = client.platform;
const { isSimulator, notificationTimeout = 5000 } = client.options;
let response = isSimulator ? new ServerToSimulatorNotificationReply() : new ServerToAppNotificationReply();
const handlePayload = async () => {
let notif = isSimulator
? ServerToSimulatorNotification.deserializeBinary(incomingPayload.data).toObject()
: ServerToAppNotification.deserializeBinary(incomingPayload.data).toObject();
if (!isSimulator) {
notif = notif.customer || notif.purse;
}
const events = Object.keys(notif);
event = events.find((i) => !['orgId', 'appId', 'createdAt', 'customerId', 'purseId', 'appData'].includes(i) && notif[i]);
const data = cleanUpNotificationPayload(event, { ...notif[event] });
if (!isSimulator) {
data.orgId = notif.orgId;
data.appId = notif.appId;
if (notif.purseId) { data.purseId = notif.purseId; }
data.customerId = notif.customerId;
data.createdAt = notif.createdAt ? notif.createdAt.seconds : undefined;
}
const globalListener = client.eventListeners.data;
if (globalListener) {
await globalListener(event, data, notif);
}
let channel;
if (event === 'receivedMessage') { // Split messaging into multiple events
channel = data.channelNumber.channel;
switch (channel) {
case 'voice':
event = 'voiceCall';
break;
case 'ussd':
event = 'ussdSession';
break;
case 'sms':
event = 'receivedSms';
break;
case 'messenger':
event = 'receivedFbMessenger';
break;
case 'telegram':
event = 'receivedTelegram';
break;
case 'whatsapp':
event = 'receivedWhatsapp';
break;
case 'email':
event = 'receivedEmail';
break;
default:
break;
}
}
const listener = client.eventListeners[event];
let incomingAppData = notif.appData || {};
const { serializer } = client.configOptions;
incomingAppData = serializer.type === 'text' ? incomingAppData.stringVal : incomingAppData.bytesVal;
incomingAppData = incomingAppData ? serializer.deserialize(incomingAppData) : undefined;
let outgoingAppData = incomingAppData;
if (listener) {
let customer;
if (notif.customerId && !isSimulator) {
customer = new client.Customer({
id: notif.customerId || data.customerId,
number: data.customerNumber ? data.customerNumber.number : undefined,
provider: data.customerNumber ? data.customerNumber.provider : undefined,
partition: data.customerNumber ? data.customerNumber.partition : undefined,
});
if (!customer.customerNumber) {
customer
.getState()
.catch((err) => log.warn(`${event}: Failed to fetch customer state ${customer.customerId} `, err));
}
}
// eslint-disable-next-line no-async-promise-executor
const listenerExec = new Promise(async (resolve, reject) => {
try {
const cb = (payload, appData) => {
resolve({
payload,
appData,
});
};
await listener(data, customer, incomingAppData, cb);
} catch (ex) {
reject(ex);
}
});
const { payload, appData } = await Promise.race([
listenerExec,
new Promise((resolve) => {
setTimeout(() => resolve(false), notificationTimeout);
}),
]);
if (appData) { outgoingAppData = appData; }
if (payload) {
switch (channel) {
case 'voice':
// payload is actions[]
response = addMessage(response, {
body: {
voice: payload,
},
});
break;
case 'ussd':
// payload is { text, isTerminal }
response = addMessage(response, {
body: {
ussd: payload,
},
});
break;
default:
response = addMessage(response, payload);
break;
}
}
}
if (outgoingAppData) {
const appDataUpdate = new DataMapValue();
const serializedValue = serializer.serialize(outgoingAppData);
switch (serializer.type) {
case 'text':
appDataUpdate.setStringVal(serializedValue);
break;
case 'binary':
appDataUpdate.setBytesValue(serializedValue);
break;
default:
throw new Error('Invalid serializer type');
}
response = response.setDataUpdate(
new AppDataUpdate()
.setData(appDataUpdate),
);
}
return response;
};
return new Single((subscriber) => {
subscriber.onSubscribe();
handlePayload()
.then((data) => {
try {
subscriber.onComplete({ data: Buffer.from(data.serializeBinary()) });
} catch (error) {
log.error(`NotificationReplyError::${event}: `, error.message || error);
}
})
.catch((error) => {
// FIXME: This returns a valid response to avoid retries...
// ideally subscriber.onError(error) should be the response
try {
log.error(`NotificationError::${event}: `, error.message || error);
subscriber.onComplete({ data: Buffer.from(response.serializeBinary()) });
} catch (ex) {
log.error(`NotificationError::${event}: `, ex.message || ex);
}
});
});
};
/**
* Register a listener to watch out for events. Can also be called with <code>client.on(event,listener)</code>
* @param {Event} event The event whose listener to register
* @param {NotificationHandler} handler A function that reacts to events
* @returns {Client} this instance
*/
Client.prototype.registerNotificationHandler = function registerNotificationHandler(event, handler) {
const events = Object.keys(this.eventListeners);
if (!events.includes(event)) {
throw new Error(`Unexpected event ${event}. Must be one of ${events}`);
}
this.eventListeners[event] = handler;
return this;
};
/**
* Register a listener to watch out for events. Can also be called with <code>client.registerListerner(event,listener)</code>
* @param {Event} event The event whose listener to register
* @param {NotificationHandler} handler A function that reacts to events
* @returns {Client} this instance
*/
Client.prototype.on = function on(event, handler) { return this.registerNotificationHandler(event, handler); };
module.exports = Client;

@@ -0,1 +1,2 @@

/* eslint-disable no-underscore-dangle */
const validate = require('validate.js');

@@ -17,13 +18,13 @@

const constraints = {
customerId: {
id: {
type: 'string',
},
'customerNumber.number': {
number: {
type: 'string',
},
'customerNumber.provider': {
provider: {
type: 'string',
inclusion: getValidCollectionKeys(CustomerNumberProvider),
},
'customerNumber.partition': {
partition: {
type: 'string',

@@ -42,4 +43,11 @@ },

this.customerId = params.customerId;
this.customerNumber = params.customerNumber;
this.customerNumber = null;
this.customerId = params.id;
if (params.number) {
this.customerNumber = {
number: params.number,
provider: params.provider,
partition: params.partition,
};
}

@@ -57,9 +65,11 @@ this.identityState = {};

this.getState = async () => {
const data = await this.client.getCustomerState(this);
const data = await this.client._getCustomerState(this);
this.customerId = data.customerId;
const numbers = [
...(data.messagingState ? data.messagingState.channels : [])
.map((i) => Object.keys(i)
.map((ki) => (i[ki] ? i[ki].customerNumber : null))).flat(),
...(data.paymentState ? data.paymentState.customerNumbers : []).map((i) => ({ ...i, state: 'payment' })),
.map((i) => Object.keys(i).map((ki) => (i[ki] ? i[ki].customerNumber : null)))
.flat()
.filter((j) => j !== null),
...(data.paymentState ? data.paymentState.customerNumbers : []),
...(data.activityState ? data.activityState.customerNumbers : []),
];

@@ -82,58 +92,63 @@ if (numbers.length && !this.customerNumber) {

* @param {Customer} otherCustomer
* @returns {UpdateStatus}
* @returns {CustomerStateUpdateReply}
*/
this.adoptState = async (otherCustomer) => this.client.adoptCustomerState(this, otherCustomer);
this.adoptState = async (otherCustomer) => this.client._adoptCustomerState(this, otherCustomer);
/**
* Update a customer's tag list.
* @param {Tag[]} tags
* @returns {UpdateStatus}
* Send a message to the customer from the specified channel number.
* @param {MessagingChannelNumber} channelNumber
* @param {Message} message
* @returns {MessageReply}
*/
this.updateTag = async (tags) => this.client.updateCustomerTag(this, tags);
// eslint-disable-next-line max-len
this.sendMessage = async (channelNumber, message) => this.client._sendMessage(this, channelNumber, message);
/**
* Remove some tags from a customer
* @param {Tag[]} tags
* @returns {UpdateStatus}
* Reply to a message
* @param {string} messageId
* @param {Message} message
* @returns {MessageReply}
*/
this.deleteTag = async (tags) => this.client.deleteCustomerTag(this, tags);
// eslint-disable-next-line max-len
this.replyToMessage = async (messageId, message) => this.client._replyToMessage(this, messageId, message);
/**
* Update a customer's secondary Ids
* @param {SecondaryId[]} secondaryIds
* @returns {UpdateStatus}
* Initiate a customer activity
* @param {ActivityChannelNumber} channelNumber
* @param {Activity} activity
* @returns {CustomerStateUpdateReply}
*/
// eslint-disable-next-line max-len
this.updateSecondaryId = async (secondaryIds) => this.client.updateCustomerSecondaryId(this, secondaryIds);
this.updateActivity = async (channelNumber, activity) => this.client._updateCustomerActivity(this.customerNumber, channelNumber, activity);
/**
* Remove some secondary Ids from a customer
* @param {SecondaryId[]} secondaryIds
* @returns {UpdateStatus}
* Allow or block a customer from receiving messages from a channel
* @param {MessagingChannelNumber} channelNumber
* @param {string} action allow or block
* @returns {ConsentUpdateReply}
*/
// eslint-disable-next-line max-len
this.deleteSecondaryId = async (secondaryIds) => this.client.deleteCustomerSecondaryId(this, secondaryIds);
this.updateMessagingConsent = async (channelNumber, action) => this.client._updateMessagingConsent(this, channelNumber, action);
/**
* Set a reminder to be triggered at the specified time for a particular customer
* @param {Reminder} reminder
* @returns {UpdateStatus}
* Fetches the customer's app data and lock it from fetching(for up to <b>90s</b>)
* until next call to update app data.
* @returns {LeasedAppData}
*/
this.addReminder = async (reminder) => this.client.addCustomerReminder(this, reminder);
this.leaseAppData = async () => this.client._leaseCustomerAppData(this);
/**
* Cancels a previously set reminder with the key <code>key</code> on the customer
* @param {string} key
* @returns {UpdateStatus}
* Sets some app data on the customer.
* Values in the data object can either be strings or buffers,
* depending on the set serializer. @see {@link ConnectionOptions}
* @param {Object} data
* @returns {CustomerStateUpdateReply}
*/
this.cancelReminder = async (key) => this.client.cancelCustomerReminder(this, key);
this.updateAppData = async (data) => this.client._updateCustomerAppData(this, data);
/**
* Fetch customer metadata
* @returns {Object}
* Remove customer's app data
* @returns {CustomerStateUpdateReply}
*/
this.getMetadata = async () => {
const state = await this.getState();
return (state.identityState || {}).metadata || {};
};
this.deleteAppData = async () => this.client._deleteCustomerAppData(this);

@@ -145,5 +160,5 @@ /**

* @param {Object} metadata
* @returns {UpdateStatus}
* @returns {CustomerStateUpdateReply}
*/
this.updateMetadata = async (metadata) => this.client.updateCustomerMetadata(this, metadata);
this.updateMetadata = async (metadata) => this.client._updateCustomerMetadata(this, metadata);

@@ -153,93 +168,76 @@ /**

* @param {string[]} keys
* @returns {UpdateStatus}
* @returns {CustomerStateUpdateReply}
*/
this.deleteMetadata = async (keys) => this.client.deleteCustomerMetadata(this, keys);
this.deleteMetadata = async (keys) => this.client._deleteCustomerMetadata(this, keys);
/**
* Sets some app data on the customer.
* Values in the data object can either be strings or buffers,
* depending on the set serializer
* @param {Object} data
* @returns {UpdateStatus}
* Update a customer's secondary Ids
* @param {SecondaryId[]} secondaryIds
* @returns {CustomerStateUpdateReply}
*/
this.updateAppData = async (data) => this.client.updateCustomerAppData(this, data);
// eslint-disable-next-line max-len
this.updateSecondaryIds = async (secondaryIds) => this.client._updateCustomerSecondaryIds(this, secondaryIds);
/**
* Fetches the customer's app data and lock it from fetching(for up to <b>90s</b>)
* until next call to update app data.
* @returns {LeasedAppData}
* Remove some secondary Ids from a customer
* @param {SecondaryId[]} secondaryIds
* @returns {CustomerStateUpdateReply}
*/
this.leaseAppData = async () => this.client.leaseCustomerAppData(this);
// eslint-disable-next-line max-len
this.deleteSecondaryIds = async (secondaryIds) => this.client._deleteCustomerSecondaryIds(this, secondaryIds);
/**
* Remove customer's app data
* @returns {UpdateStatus}
* Update a customer's tag list.
* @param {Tag[]} tags
* @returns {CustomerStateUpdateReply}
*/
this.deleteAppData = async () => this.client.deleteCustomerAppData(this);
this.updateTags = async (tags) => this.client._updateCustomerTags(this, tags);
/**
* Send a message to the customer from the specified channel number.
* @param {MessagingChannelNumber} channelNumber
* @param {Body} body
* @returns {MessageStatus}
* Remove some tags from a customer
* @param {string[]} tags
* @returns {CustomerStateUpdateReply}
*/
// eslint-disable-next-line max-len
this.sendMessage = async (channelNumber, body) => this.client.sendMessage(this, channelNumber, body);
this.deleteTags = async (keys) => this.client._deleteCustomerTags(this, keys);
/**
* Initiate a voice call to the customer
* @param {string} channelNumber
* @param {VoiceAction[]} actions
* @returns {MessageStatus}
* Set a reminder to be triggered at the specified time for a particular customer
* @param {Reminder} reminder
* @returns {CustomerStateUpdateReply}
*/
// eslint-disable-next-line max-len
this.makeVoiceCall = async (channelNumber, actions = []) => this.client.makeVoiceCall(this, channelNumber, actions);
this.addReminder = async (reminder) => this.client._addCustomerReminder(this, reminder);
/**
* Allow or block a customer from receiving messages from a channel
* @param {MessagingChannelNumber} channelNumber
* @param {string} action allow or block
* @returns {ConsentStatus}
* Cancels a previously set reminder with the key <code>key</code> on the customer
* @param {string} key
* @returns {CustomerStateUpdateReply}
*/
// eslint-disable-next-line max-len
this.updateMessagingConsent = async (channelNumber, action) => this.client.updateMessagingConsent(this, channelNumber, action);
this.cancelReminder = async (key) => this.client._cancelCustomerReminder(this, key);
/**
* Initiate a customer activity
* @param {ActivityChannelNumber} channelNumber
* @param {Activity} sessionId
* @returns {UpdateStatus}
* Initiate a voice call to customer from channelNumber
* @param {MessagingChannelNumber} channelNumber
* @param {VoiceAction[]} actions
*/
// eslint-disable-next-line max-len
this.updateActivity = async (channelNumber, activity) => this.client.updateCustomerActivity(this.customerNumber, channelNumber, activity);
/* eslint-enable no-use-before-define */
/*
this.makeVoiceCall = async (channelNumber, actions = []) => {
if (channelNumber.channel !== 'voice') {
throw new Error('Invalid channel number. Channel must be voice');
}
const { customerNumber } = this;
if (!customerNumber) {
// FIXME: Have Elarian return the customer number on fetch state?
throw new Error('customerNumber is not setup on this customer');
}
return this.sendMessage(channelNumber, { body: { voice: actions } });
};
*/
/**
* Initiate a payment transaction
* @param {PaymentChannelNumber|Wallet} source
* @param {Wallet|Purse} destination
* @param {Cash} value
* @returns {PaymentStatus}
* Fetch customer metadata
* @returns {Object}
*/
this.requestPayment = async (source, destination, value) => {
if (!this.customerId && (source.walletId || destination.walletId)) {
const state = await this.getState();
this.customerId = state.customerId;
}
let debitParty = source;
if (debitParty.number) {
debitParty = {
customerNumber: this.customerNumber,
channelNumber: source,
};
} else if (debitParty.walletId) {
debitParty.customerId = this.customerId;
}
const creditParty = destination;
if (creditParty.walletId) {
creditParty.customerId = this.customerId;
}
return this.client.initiatePayment(debitParty, creditParty, value);
this.getMetadata = async () => {
const state = await this.getState();
return (state.identityState || {}).metadata || {};
};

@@ -246,0 +244,0 @@ }

/* eslint-disable global-require */
/* eslint-disable import/no-dynamic-require */
require('./state');
require('./voice');
require('./payment');
require('./messaging');
require('./notification');
require('./authentication');
const Elarian = require('./client');
const Client = require('./client');
const Elarian = require('./elarian');
const Simulator = require('./simulator');
module.exports = (conf) => {
Elarian.prototype.platform = conf;
Client.prototype.platform = conf;
return {

@@ -16,0 +15,0 @@ Elarian,

@@ -1,2 +0,2 @@

const { RSocketTlsClient } = require('rsocket-tcp-client/build/RSocketTcpClient'); // FIXME: don't rely on build folder
const { RSocketTlsClient } = require('rsocket-tcp-client');
const { RSocketResumableTransport, BufferEncoders } = require('rsocket-core');

@@ -3,0 +3,0 @@

@@ -0,1 +1,2 @@

/* eslint-disable no-underscore-dangle */
const {

@@ -9,6 +10,7 @@ ElarianMessages,

getMessageConsentUpdateAction,
getMessageDeliveryStatusString,
getChannelProvider,
} = require('./utils');
const Elarian = require('./client');
const Elarian = require('./elarian');
const Customer = require('./customer');

@@ -30,21 +32,13 @@

/**
* Send a message
* @param {Customer} customer
* Send message by tag
* @param {Tag} tag
* @param {MessagingChannelNumber} channelNumber
* @param {Message} message
* @returns {MessageStatus}
* @memberof Elarian
* @returns {TagUpdateReply}
*/
Elarian.prototype.sendMessage = function sendMessage(customer, channelNumber, message) {
Elarian.prototype.sendMessageByTag = function sendMessageByTag(tag, channelNumber, message) {
const socket = this.getSocket();
if (!(customer instanceof Customer)) {
throw new Error('Invalid customer');
}
if (!customer.customerNumber) {
throw new Error('sendMessage() requires a customer with customerNumber');
}
let cmd = new SendMessageCommand()
let cmd = new SendMessageTagCommand()
.setChannelNumber(

@@ -55,6 +49,6 @@ new MessagingChannelNumber()

);
cmd = addCustomer(cmd, customer);
cmd = addTag(cmd, tag);
cmd = addMessage(cmd, message);
const req = new AppToServerCommand()
.setSendMessage(cmd);
.setSendMessageTag(cmd);

@@ -71,12 +65,9 @@ return new Promise((resolve, reject) => {

.deserializeBinary(value.data)
.getSendMessage();
.getTagCommand();
const result = {
status: getStatusString(res.getStatus(), MessageDeliveryStatus),
status: res.getStatus(),
description: res.getDescription(),
customerId: (res.getCustomerId() || {
workId: (res.getWorkId() || {
getValue: () => undefined,
}).getValue(),
messageId: (res.getMessageId() || {
getValue: () => undefined,
}).getValue(),
};

@@ -94,13 +85,21 @@ resolve(result);

/**
* Send message by tag
* @param {Tag} tag
* Send a message
* @param {Customer} customer
* @param {MessagingChannelNumber} channelNumber
* @param {Message} body
* @memberof Elarian
* @returns {WorkStatus}
* @param {Message} message
* @returns {MessageReply}
* @ignore
*/
Elarian.prototype.sendMessageByTag = function sendMessageByTag(tag, channelNumber, message) {
Elarian.prototype._sendMessage = function sendMessage(customer, channelNumber, message) {
const socket = this.getSocket();
let cmd = new SendMessageTagCommand()
if (!(customer instanceof Customer)) {
throw new Error('Invalid customer');
}
if (!customer.customerNumber) {
throw new Error('sendMessage() requires a customer with customerNumber');
}
let cmd = new SendMessageCommand()
.setChannelNumber(

@@ -111,6 +110,6 @@ new MessagingChannelNumber()

);
cmd = addTag(cmd, tag);
cmd = addCustomer(cmd, customer);
cmd = addMessage(cmd, message);
const req = new AppToServerCommand()
.setSendMessageTag(cmd);
.setSendMessage(cmd);

@@ -127,9 +126,15 @@ return new Promise((resolve, reject) => {

.deserializeBinary(value.data)
.getTagCommand();
.getSendMessage();
const result = {
status: res.getStatus(),
status: getMessageDeliveryStatusString(res.getStatus()),
description: res.getDescription(),
workId: (res.getWorkId() || {
sessionId: (res.getSessionId() || {
getValue: () => undefined,
}).getValue(),
customerId: (res.getCustomerId() || {
getValue: () => undefined,
}).getValue(),
messageId: (res.getMessageId() || {
getValue: () => undefined,
}).getValue(),
};

@@ -151,7 +156,7 @@ resolve(result);

* @param {Message} body
* @returns {MessageStatus}
* @memberof Elarian
* @returns {MessageReply}
* @ignore
*/
// eslint-disable-next-line max-len
Elarian.prototype.replyToMessage = async function replyToMessage(customer, replyToMessageId, message) {
Elarian.prototype._replyToMessage = async function replyToMessage(customer, replyToMessageId, message) {
const socket = this.getSocket();

@@ -213,7 +218,7 @@

* @param {string} action allow or block
* @returns {ConsentStatus}
* @memberof Elarian
* @returns {ConsentUpdateReply}
* @ignore
*/
// eslint-disable-next-line max-len
Elarian.prototype.updateMessagingConsent = function updateMessagingConsent(customer, channelNumber, action) {
Elarian.prototype._updateMessagingConsent = function updateMessagingConsent(customer, channelNumber, action) {
const socket = this.getSocket();

@@ -220,0 +225,0 @@

@@ -8,3 +8,3 @@ const {

const Elarian = require('./client');
const Elarian = require('./elarian');

@@ -23,3 +23,3 @@ const {

* @param {Cash} value
* @returns {PaymentStatus}
* @returns {InitiatePaymentReply}
* @memberof Elarian

@@ -26,0 +26,0 @@ */

@@ -1,2 +0,2 @@

const Elarian = require('./client');
const Client = require('./client');

@@ -6,2 +6,3 @@ const {

addCashValue,
getMediaType,
ElarianMessages,

@@ -20,3 +21,6 @@ getChannelProvider,

MessagingChannel,
MediaMessageBody,
EmailMessageBody,
InboundMessageBody,
LocationMessageBody,
VoiceCallDialInput,

@@ -39,23 +43,34 @@ VoiceCallQueueInput,

* @class
* @param {ElarianConfig} config
* @extends Client
* @param {ClientConfig} config
*/
function Simulator(config) {
Elarian.call(this, { ...config, isSimulator: true });
Client.call(this, { ...config, isSimulator: true });
this.eventListeners = {
...this.eventListeners,
sendMessage: null,
makeVoiceCall: null,
checkoutPayment: null,
sendChannelPayment: null,
sendCustomerPayment: null,
};
}
Simulator.prototype = Object.create(Elarian.prototype, { constructor: Simulator });
Simulator.prototype = Object.create(Client.prototype, { constructor: Simulator });
/**
* Initiate a message request
* @param {string} customerNumber
* @param {string} phoneNumber
* @param {MessagingChannelNumber} channelNumber
* @param {string} sessionId
* @param {SimulatorMessageBody[]} messageParts
* @param {SimulatorMessageBody[]} parts
* @memberof Simulator
*/
// eslint-disable-next-line max-len
Simulator.prototype.receiveMessage = function receiveMessage(customerNumber, channelNumber, sessionId, messageParts = []) {
Simulator.prototype.receiveMessage = function receiveMessage(phoneNumber, channelNumber, sessionId, parts = []) {
const socket = this.getSocket();
const parts = messageParts.map((part) => {
const messageParts = parts.map((part) => {
let voiceObj;

@@ -110,7 +125,41 @@ if (part.voice) {

let mediaObj;
if (part.media) {
mediaObj = new MediaMessageBody()
.setUrl(part.media.url)
.setMedia(getMediaType(part.media.type));
}
let locationObj;
if (part.location) {
const {
label,
address,
latitude,
longitude,
} = part.location;
locationObj = new LocationMessageBody()
.setLatitude(latitude)
.setLongitude(longitude)
.setLabel(new StringValue().setValue(label))
.setAddress(new StringValue().setValue(address));
}
let emailObj;
if (part.email) {
const { email } = part;
emailObj = new EmailMessageBody()
.setSubject(email.subject)
.setBodyPlain(email.bodyPlain)
.setBodyHtml(email.bodyHtml)
.setCcListList(email.ccList)
.setBccListList(email.bccList)
.setAttachmentsList(email.attachments);
}
const obj = new InboundMessageBody()
.setText(part.text)
.setMedia(part.media)
.setLocation(part.location)
.setEmail(part.email)
.setMedia(mediaObj)
.setLocation(locationObj)
.setEmail(emailObj)
.setUssd(new StringValue().setValue(part.ussd))

@@ -121,4 +170,5 @@ .setVoice(voiceObj);

});
const cmd = new ReceiveMessageSimulatorCommand()
.setCustomerNumber(customerNumber)
.setCustomerNumber(phoneNumber)
.setSessionId(new StringValue().setValue(sessionId))

@@ -130,3 +180,3 @@ .setChannelNumber(

)
.setPartsList(parts);
.setPartsList(messageParts);

@@ -133,0 +183,0 @@ const req = new SimulatorToServerCommand()

@@ -1,2 +0,3 @@

const Elarian = require('./client');
/* eslint-disable no-underscore-dangle */
const Elarian = require('./elarian');
const Customer = require('./customer');

@@ -48,8 +49,104 @@

/**
* Set a reminder to be triggered at the specified time for customers with the particular tag
* @param {Tag} tag
* @param {Reminder} reminder
* @returns {TagUpdateReply}
* @memberof Elarian
*/
Elarian.prototype.addCustomerReminderByTag = function addCustomerReminderByTag(tag, reminder) {
const socket = this.getSocket();
if (!reminder || !tag) {
throw new Error('reminder and tag are required');
}
let cmd = new AddCustomerReminderTagCommand();
cmd = addTag(cmd, tag);
cmd = addReminder(cmd, reminder);
const req = new AppToServerCommand()
.setAddCustomerReminderTag(cmd);
return new Promise((resolve, reject) => {
socket
.requestResponse({
data: Buffer.from(req.serializeBinary()),
})
.subscribe({
onComplete: (value) => {
try {
const res = AppToServerCommandReply
.deserializeBinary(value.data)
.getTagCommand();
const result = {
status: res.getStatus(),
description: res.getDescription(),
workId: (res.getWorkId() || {
getValue: () => undefined,
}).getValue(),
};
resolve(result);
} catch (ex) {
reject(ex);
}
},
onError: (error) => reject(error),
});
});
};
/**
* Cancels a previously set reminder with tag <code>tag</code> and key <code>key</code>
* @param {Tag} tag
* @param {string} key
* @returns {TagUpdateReply}
* @memberof Elarian
*/
Elarian.prototype.cancelCustomerReminderByTag = function cancelCustomerReminderByTag(tag, key) {
const socket = this.getSocket();
if (!key || !tag) {
throw new Error('key and tag are required');
}
let cmd = new CancelCustomerReminderTagCommand()
.setKey(key);
cmd = addTag(cmd, tag);
const req = new AppToServerCommand()
.setCancelCustomerReminderTag(cmd);
return new Promise((resolve, reject) => {
socket
.requestResponse({
data: Buffer.from(req.serializeBinary()),
})
.subscribe({
onComplete: (value) => {
try {
const res = AppToServerCommandReply
.deserializeBinary(value.data)
.getTagCommand();
const result = {
status: res.getStatus(),
description: res.getDescription(),
workId: (res.getWorkId() || {
getValue: () => undefined,
}).getValue(),
};
resolve(result);
} catch (ex) {
reject(ex);
}
},
onError: (error) => reject(error),
});
});
};
/**
* Fetch the customer's current state.
* @param {Customer} customer
* @returns {CustomerState}
* @memberof Elarian
* @ignore
*/
Elarian.prototype.getCustomerState = function getCustomerState(customer) {
Elarian.prototype._getCustomerState = function getCustomerState(customer) {
if (!(customer instanceof Customer)) {

@@ -90,4 +187,2 @@ throw new Error('Invalid customer');

// TODO: Clean up paymentState, messagingState, identityState
// eslint-disable-next-line max-len

@@ -119,3 +214,4 @@ if (result.data.identityState && Object.keys(result.data.identityState).length) {

if (result.data.paymentState) {
// eslint-disable-next-line max-len
if (result.data.paymentState && Object.keys(result.data.paymentState).length) {
const entry = result.data.paymentState;

@@ -129,5 +225,7 @@ result.data.paymentState = {

provider: getCustomerNumberProviderString(i.provider),
partition: i.partition ? i.partition.value : undefined,
})),
channelNumbers: entry.channelNumbersList.map((i) => ({
number: i.number,
// eslint-disable-next-line max-len
channel: getChannelProviderString(i.channel, PaymentChannel),

@@ -138,3 +236,4 @@ })),

if (result.data.messagingState) {
// eslint-disable-next-line max-len
if (result.data.messagingState && Object.keys(result.data.messagingState).length) {
result.data.messagingState = {

@@ -150,3 +249,2 @@ channels: result.data.messagingState.channelsList.map((ch) => {

if (state[key]) {
// customer+channel numbers
state[key].customerNumber = state[key].customerNumber

@@ -158,2 +256,4 @@ ? {

),
// eslint-disable-next-line max-len
partition: state[key].customerNumber.partition ? state[key].customerNumber.partition.value : undefined,
}

@@ -173,2 +273,55 @@ : undefined;

if (state.active) {
state.active = {
customerNumber: state.active.customerNumber,
channelNumber: state.active.customerNumber,
messages: state.active.messagesList,
sessions: state.active.sessionsList,
replyToken: state.active.replyToken ? {
token: state.active.replyToken.token,
// eslint-disable-next-line max-len
expiresAt: state.active.replyToken.expiresAt.seconds,
} : undefined,
// eslint-disable-next-line max-len
allowedAt: state.active.allowedAt ? state.active.allowedAt.seconds : undefined,
};
}
if (state.blocked) {
state.blocked = {
customerNumber: state.blocked.customerNumber,
channelNumber: state.blocked.customerNumber,
messages: state.blocked.messagesList,
sessions: state.blocked.sessionsList,
replyToken: state.blocked.replyToken ? {
token: state.blocked.replyToken.token,
// eslint-disable-next-line max-len
expiresAt: state.blocked.replyToken.expiresAt.seconds,
} : undefined,
};
}
if (state.inSession) {
state.inSession = {
appIds: state.inSession.appIdsList,
sessionId: state.inSession.sessionId,
customerNumber: state.inSession.customerNumber,
channelNumber: state.inSession.customerNumber,
messages: state.inSession.messagesList,
sessions: state.inSession.sessionsList,
replyToken: state.inSession.replyToken ? {
token: state.inSession.replyToken.token,
// eslint-disable-next-line max-len
expiresAt: state.inSession.replyToken.expiresAt.seconds,
} : undefined,
// eslint-disable-next-line max-len
allowedAt: state.inSession.allowedAt ? state.inSession.allowedAt.seconds : undefined,
// eslint-disable-next-line max-len
startedAt: state.inSession.startedAt ? state.inSession.startedAt.seconds : undefined,
// eslint-disable-next-line max-len
expiresAt: state.inSession.expiresAt ? state.inSession.expiresAt.seconds : undefined,
};
}
return state;

@@ -179,2 +332,46 @@ }),

// eslint-disable-next-line max-len
if (result.data.activityState && Object.keys(result.data.activityState).length) {
const entry = result.data.activityState;
result.data.activityState = {
sessions: (entry.sessionsList || []).map((sess) => ({
appId: sess.appId,
sessionId: sess.sessionId,
activities: (sess.activitiesList || []).map((i) => ({
key: i.key,
properties: i.propertiesMap.map((j) => ({
[j[0]]: j[1], // FIXME: What are the actual values?
})),
createdAt: i.createdAt ? i.createdAt.seconds : undefined,
})),
createdAt: sess.createdAt.seconds,
updatedAt: sess.updatedAt.seconds,
customerNumber: sess.customerNumber ? {
number: sess.customerNumber.number,
provider: getCustomerNumberProviderString(
sess.customerNumber.provider,
),
// eslint-disable-next-line max-len
partition: sess.customerNumber.partition ? sess.customerNumber.partition.value : undefined,
} : undefined,
channelNumber: sess.channelNumber ? {
number: sess.channelNumber.number,
channel: getChannelProviderString(
sess.channelNumber.channel,
ActivityChannel,
),
} : undefined,
})),
customerNumbers: (entry.customerNumbersList || []).map((num) => ({
number: num.number,
provider: getCustomerNumberProviderString(
num.provider,
),
// eslint-disable-next-line max-len
partition: num.partition ? num.partition.value : undefined,
})),
};
}
resolve(result.data);

@@ -194,6 +391,6 @@ } catch (ex) {

* @param {Customer} otherCustomer
* @returns {UpdateStatus}
* @memberof Elarian
* @returns {CustomerStateUpdateReply}
* @ignore
*/
Elarian.prototype.adoptCustomerState = async function adoptCustomerState(customer, otherCustomer) {
Elarian.prototype._adoptCustomerState = async function adoptCustomerState(customer, otherCustomer) {
const socket = this.getSocket();

@@ -254,6 +451,6 @@

* @param {Tag[]} tags
* @returns {UpdateStatus}
* @memberof Elarian
* @returns {CustomerStateUpdateReply}
* @ignore
*/
Elarian.prototype.updateCustomerTag = function updateCustomerTag(customer, tags) {
Elarian.prototype._updateCustomerTags = function updateCustomerTags(customer, tags) {
const socket = this.getSocket();

@@ -310,7 +507,7 @@

* @param {Customer} customer
* @param {string[]} tags
* @returns {UpdateStatus}
* @memberof Elarian
* @param {string[]} keys
* @returns {CustomerStateUpdateReply}
* @ignore
*/
Elarian.prototype.deleteCustomerTag = async function deleteCustomerTag(customer, tags) {
Elarian.prototype._deleteCustomerTags = async function deleteCustomerTags(customer, keys) {
const socket = this.getSocket();

@@ -322,3 +519,3 @@

if (!tags || !tags.length) {
if (!keys || !keys.length) {
throw new Error('tags is required');

@@ -328,3 +525,3 @@ }

let cmd = new DeleteCustomerTagCommand()
.setDeletionsList(tags);
.setDeletionsList(keys);
cmd = addCustomer(cmd, customer);

@@ -370,7 +567,7 @@ const req = new AppToServerCommand()

* @param {SecondaryId[]} secondaryIds
* @returns {UpdateStatus}
* @memberof Elarian
* @returns {CustomerStateUpdateReply}
* @ignore
*/
// eslint-disable-next-line max-len
Elarian.prototype.updateCustomerSecondaryId = async function updateCustomerSecondaryId(customer, secondaryIds) {
Elarian.prototype._updateCustomerSecondaryIds = async function updateCustomerSecondaryIds(customer, secondaryIds) {
const socket = this.getSocket();

@@ -428,7 +625,7 @@

* @param {SecondaryId[]} secondaryIds
* @returns {UpdateStatus}
* @memberof Elarian
* @returns {CustomerStateUpdateReply}
* @ignore
*/
// eslint-disable-next-line max-len
Elarian.prototype.deleteCustomerSecondaryId = function deleteCustomerSecondaryId(customer, secondaryIds) {
Elarian.prototype._deleteCustomerSecondaryIds = function deleteCustomerSecondaryIds(customer, secondaryIds) {
const socket = this.getSocket();

@@ -486,6 +683,6 @@

* @param {Reminder} reminder
* @returns {UpdateStatus}
* @memberof Elarian
* @returns {CustomerStateUpdateReply}
* @ignore
*/
Elarian.prototype.addCustomerReminder = function addCustomerReminder(customer, reminder) {
Elarian.prototype._addCustomerReminder = function addCustomerReminder(customer, reminder) {
const socket = this.getSocket();

@@ -544,5 +741,5 @@

* @returns {UpdateStatus}
* @memberof Elarian
* @ignore
*/
Elarian.prototype.cancelCustomerReminder = function cancelCustomerReminder(customer, key) {
Elarian.prototype._cancelCustomerReminder = function cancelCustomerReminder(customer, key) {
const socket = this.getSocket();

@@ -597,98 +794,2 @@

/**
* Set a reminder to be triggered at the specified time for customers with the particular tag
* @param {Tag} tag
* @param {Reminder} reminder
* @returns {WorkStatus}
* @memberof Elarian
*/
Elarian.prototype.addCustomerReminderByTag = function addCustomerReminderByTag(tag, reminder) {
const socket = this.getSocket();
if (!reminder || !tag) {
throw new Error('reminder and tag are required');
}
let cmd = new AddCustomerReminderTagCommand();
cmd = addTag(cmd, tag);
cmd = addReminder(cmd, reminder);
const req = new AppToServerCommand()
.setAddCustomerReminderTag(cmd);
return new Promise((resolve, reject) => {
socket
.requestResponse({
data: Buffer.from(req.serializeBinary()),
})
.subscribe({
onComplete: (value) => {
try {
const res = AppToServerCommandReply
.deserializeBinary(value.data)
.getTagCommand();
const result = {
status: res.getStatus(),
description: res.getDescription(),
workId: (res.getWorkId() || {
getValue: () => undefined,
}).getValue(),
};
resolve(result);
} catch (ex) {
reject(ex);
}
},
onError: (error) => reject(error),
});
});
};
/**
* Cancels a previously set reminder with tag <code>tag</code> and key <code>key</code>
* @param {Tag} tag
* @param {string} key
* @returns {WorkStatus}
* @memberof Elarian
*/
Elarian.prototype.cancelCustomerReminderByTag = function cancelCustomerReminderByTag(tag, key) {
const socket = this.getSocket();
if (!key || !tag) {
throw new Error('key and tag are required');
}
let cmd = new CancelCustomerReminderTagCommand()
.setKey(key);
cmd = addTag(cmd, tag);
const req = new AppToServerCommand()
.setCancelCustomerReminderTag(cmd);
return new Promise((resolve, reject) => {
socket
.requestResponse({
data: Buffer.from(req.serializeBinary()),
})
.subscribe({
onComplete: (value) => {
try {
const res = AppToServerCommandReply
.deserializeBinary(value.data)
.getTagCommand();
const result = {
status: res.getStatus(),
description: res.getDescription(),
workId: (res.getWorkId() || {
getValue: () => undefined,
}).getValue(),
};
resolve(result);
} catch (ex) {
reject(ex);
}
},
onError: (error) => reject(error),
});
});
};
/**
* Sets some metadata on the customer.

@@ -699,6 +800,6 @@ * Values in the metadata object can either be strings or buffers,

* @param {Object} metadata
* @returns {UpdateStatus}
* @memberof Elarian
* @returns {CustomerStateUpdateReply}
* @ignore
*/
Elarian.prototype.updateCustomerMetadata = function updateCustomerMetadata(customer, metadata) {
Elarian.prototype._updateCustomerMetadata = function updateCustomerMetadata(customer, metadata) {
const socket = this.getSocket();

@@ -770,6 +871,6 @@ const { serializer } = this.configOptions;

* @param {string[]} keys
* @returns {UpdateStatus}
* @memberof Elarian
* @returns {CustomerStateUpdateReply}
* @ignore
*/
Elarian.prototype.deleteCustomerMetadata = function deleteCustomerMetadata(customer, keys) {
Elarian.prototype._deleteCustomerMetadata = function deleteCustomerMetadata(customer, keys) {
const socket = this.getSocket();

@@ -822,9 +923,9 @@

* Value of the data object can either be a string or a buffer,
* depending on your serializer. @see {@link Client}
* depending on your serializer. @see {@link ConnectionOptions}
* @param {Customer} customer
* @param {Object} data
* @returns {UpdateStatus}
* @memberof Elarian
* @returns {CustomerStateUpdateReply}
* @ignore
*/
Elarian.prototype.updateCustomerAppData = function updateCustomerAppData(customer, data) {
Elarian.prototype._updateCustomerAppData = function updateCustomerAppData(customer, data) {
const socket = this.getSocket();

@@ -893,5 +994,5 @@ const { serializer } = this.configOptions;

* @returns {LeasedAppData}
* @memberof Elarian
* @ignore
*/
Elarian.prototype.leaseCustomerAppData = function leaseCustomerAppData(customer) {
Elarian.prototype._leaseCustomerAppData = function leaseCustomerAppData(customer) {
const socket = this.getSocket();

@@ -950,6 +1051,6 @@ const { serializer } = this.configOptions;

* @param {Customer} customer
* @returns {UpdateStatus}
* @memberof Elarian
* @returns {CustomerStateUpdateReply}
* @ignore
*/
Elarian.prototype.deleteCustomerAppData = function deleteCustomerAppData(customer) {
Elarian.prototype._deleteCustomerAppData = function deleteCustomerAppData(customer) {
const socket = this.getSocket();

@@ -999,7 +1100,7 @@

* @param {Activity} activity
* @returns {UpdateStatus}
* @memberof Elarian
* @returns {CustomerStateUpdateReply}
* @ignore
*/
// eslint-disable-next-line max-len
Elarian.prototype.updateCustomerActivity = function updateCustomerActivity(customerNumber, channelNumber, activity) {
Elarian.prototype._updateCustomerActivity = function updateCustomerActivity(customerNumber, channelNumber, activity) {
const socket = this.getSocket();

@@ -1006,0 +1107,0 @@

@@ -127,3 +127,3 @@ const { RSocketClient } = require('rsocket-core');

if (!key) {
throw new Error(`Invalid key ${provider}. Must be one of [${getValidCollectionKeys(ChannelEnum, channelRegex)}]`);
throw new Error(`${provider} is an invalid channel or provider. Expecing one of [${getValidCollectionKeys(ChannelEnum, channelRegex)}]`);
}

@@ -135,3 +135,3 @@ return ChannelEnum[key];

const key = Object.keys(ChannelEnum).find((i) => ChannelEnum[i] === channel);
if (!key) throw new Error(`Invalid value ${channel}. Must be one of [${Object.values(ChannelEnum)}]`);
if (!key) throw new Error(`${channel} is an invalid value. Expectinng one of [${Object.values(ChannelEnum)}]`);
return key.replace(filter, '').toLocaleLowerCase();

@@ -439,8 +439,13 @@ };

if (location) {
const { latitude, longitude } = location;
const {
label,
address,
latitude,
longitude,
} = location;
const locationObj = new LocationMessageBody()
.setLatitude(latitude)
.setLongitude(longitude)
.setLabel(new StringValue().setValue(location.label))
.setAddress(new StringValue().setValue(location.address));
.setLabel(new StringValue().setValue(label))
.setAddress(new StringValue().setValue(address));
bodyObj = bodyObj.setLocation(locationObj);

@@ -554,3 +559,6 @@ } else if (media) {

errorHandler: (error) => {
log.error(error);
log.debug('Connection Error ', error);
if (getConnectionHandlers().error) {
getConnectionHandlers().error(error);
}
},

@@ -628,2 +636,3 @@ });

addCashValue,
getMediaType,
connectRSocket,

@@ -630,0 +639,0 @@ getStatusString,

{
"name": "elarian",
"version": "0.1.20",
"version": "0.2.0",
"description": "Elrian JavaScript SDK",

@@ -40,7 +40,7 @@ "main": "index.js",

"dependencies": {
"google-protobuf": "^3.15.3",
"rsocket-core": "0.0.23",
"rsocket-flowable": "0.0.23",
"rsocket-tcp-client": "0.0.23",
"rsocket-websocket-client": "0.0.23",
"google-protobuf": "^3.15.5",
"rsocket-core": "0.0.25",
"rsocket-flowable": "0.0.25",
"rsocket-tcp-client": "0.0.25",
"rsocket-websocket-client": "0.0.25",
"validate.js": "^0.13.1"

@@ -53,3 +53,3 @@ },

"eslint-plugin-import": "^2.22.1",
"eslint-plugin-mocha": "^8.0.0",
"eslint-plugin-mocha": "^8.1.0",
"eslint-plugin-security": "^1.4.0",

@@ -60,3 +60,3 @@ "ink-docstrap": "^1.3.2",

"lodash": "^4.17.21",
"mocha": "^8.3.0",
"mocha": "^8.3.1",
"node-fetch": ">=2.6.1",

@@ -66,5 +66,5 @@ "nyc": "^15.1.0",

"tsd-jsdoc": "^2.5.0",
"webpack": "^5.24.2",
"webpack": "^5.24.4",
"webpack-cli": "^4.5.0"
}
}

@@ -30,3 +30,3 @@ # Elarian

const client = new Elarian({
const elarian = new Elarian({
apiKey: 'YOUR_API_KEY', // or authToken: 'YOUR_AUTH_TOKEN'

@@ -37,3 +37,3 @@ orgId: 'YOUR_ORG_ID',

client.on('ussdSession', async ({ notification, customer, appData }, callback) => {
elarian.on('ussdSession', async (notification, customer, appData, callback) => {
const {

@@ -65,3 +65,3 @@ input,

{ number: 'Elarian', provider: 'telco' },
{ text: { body: `Hey ${name}! Thank you for trying out Elarian` } },
{ body: { text: `Hey ${name}! Thank you for trying out Elarian` } },
);

@@ -77,7 +77,6 @@ }

}
callback(null, menu, { state, name });
callback(menu, { state, name });
});
client
.connect()
elarian
.on('connected', () => {

@@ -88,3 +87,4 @@ console.log('App is running!')

console.error(error);
});
})
.connect();
```

@@ -96,3 +96,3 @@

Take a look at the [API docs here](http://docs.elarian.com). For detailed info on this SDK, see the [documentation](https://elarianltd.github.io/javascript-sdk/Elarian.html).
Take a look at the [API docs here](http://docs.elarian.com). For detailed info on this SDK, see the [reference](docs/).

@@ -108,4 +108,6 @@ ## Development

See [SDK Spec](https://github.com/ElarianLtd/sdk-spec) for reference.
## Issues
If you find a bug, please file an issue on [our issue tracker on GitHub](https://github.com/ElarianLtd/javascript-sdk/issues).
/**
* <p>Instantiate an elarian client. You have to call connect() on then client to start using it</p>
*/
declare class Elarian {
constructor(config: ElarianConfig);
declare class Client {
constructor(config: ClientConfig);
/**
* <p>Generate a short-lived auth token to use instead of apiKey. Used for browser and mobile clients.</p>
* <p>Connecto to elarian servers</p>
* @returns <p>this instance</p>
*/
generateAuthToken(): AuthToken;
connect(): Elarian;
/**
* <p>Connect to the elarian server</p>
*/
connect(): void;
/**
* <p>Check if client is connected</p>
*/
isConnected(): void;
isConnected(): boolean;
/**

@@ -23,164 +20,96 @@ * <p>Disconnect from the elarian server</p>

/**
* <p>Send a message</p>
*/
sendMessage(customer: Customer, channelNumber: MessagingChannelNumber, message: Message): MessageStatus;
/**
* <p>Send message by tag</p>
*/
sendMessageByTag(tag: Tag, channelNumber: MessagingChannelNumber, body: Message): WorkStatus;
/**
* <p>Reply to a received message</p>
*/
replyToMessage(customer: Customer, replyToMessageId: string, body: Message): MessageStatus;
/**
* <p>Allow or block a customer from receiving messages from a channel</p>
* @param action - <p>allow or block</p>
*/
updateMessagingConsent(customer: Customer, channelNumber: MessagingChannelNumber, action: string): ConsentStatus;
/**
* <p>Register a listener to watch out for events. Can also be called with <code>client.on(event,listener)</code></p>
* @param event - <p>The event whose listener to register</p>
* @param listener - <p>A function that reacts to events</p>
* @param handler - <p>A function that reacts to events</p>
* @returns <p>this instance</p>
*/
registerListerner(event: Event, listener: EventListener): void;
registerNotificationHandler(event: Event, handler: NotificationHandler): Client;
/**
* <p>Register a listener to watch out for events. Can also be called with <code>client.registerListerner(event,listener)</code></p>
* @param event - <p>The event whose listener to register</p>
* @param listener - <p>A function that reacts to events</p>
* @param handler - <p>A function that reacts to events</p>
* @returns <p>this instance</p>
*/
on(event: Event, listener: EventListener): void;
on(event: Event, handler: NotificationHandler): Client;
}
/**
* <p>A customer is your end-user, represented by a number (from a cellular, facebook or telegram)</p>
*/
declare class Customer {
constructor(params: CustomerParams);
/**
* <p>Remove listener registered for event. Can also be called with <code>client.off(event)</code></p>
* @param event - <p>The event whose listener to remove</p>
*/
removeListener(event: Event): void;
/**
* <p>Remove listener registered for event. Can also be called with <code>client.removeListener(event)</code></p>
* @param event - <p>The event whose listener to remove</p>
*/
off(event: Event): void;
/**
* <p>Initiate a payment transaction</p>
*/
initiatePayment(debitParty: CustomerPayment | Wallet | Purse, creditParty: CustomerPayment | Wallet | Purse, value: Cash): PaymentStatus;
/**
* <p>Fetch the customer's current state.</p>
*/
getCustomerState(customer: Customer): CustomerState;
getState(): CustomerState;
/**
* <p>Adopt another customer's state</p>
* <p>Merge otherCustomer's state into this customer's state and discard otherCustomer</p>
*/
adoptCustomerState(customer: Customer, otherCustomer: Customer): UpdateStatus;
adoptState(otherCustomer: Customer): CustomerStateUpdateReply;
/**
* <p>Update a customer's tag list</p>
* <p>Send a message to the customer from the specified channel number.</p>
*/
updateCustomerTag(customer: Customer, tags: Tag[]): UpdateStatus;
sendMessage(channelNumber: MessagingChannelNumber, message: Message): MessageReply;
/**
* <p>Remove tags from a customer</p>
* <p>Reply to a message</p>
*/
deleteCustomerTag(customer: Customer, tags: string[]): UpdateStatus;
replyToMessage(messageId: string, message: Message): MessageReply;
/**
* <p>Update a customer's secondary Ids</p>
* <p>Initiate a customer activity</p>
*/
updateCustomerSecondaryId(customer: Customer, secondaryIds: SecondaryId[]): UpdateStatus;
updateActivity(channelNumber: ActivityChannelNumber, activity: Activity): CustomerStateUpdateReply;
/**
* <p>Delete a customer's secondary Ids</p>
* <p>Allow or block a customer from receiving messages from a channel</p>
* @param action - <p>allow or block</p>
*/
deleteCustomerSecondaryId(customer: Customer, secondaryIds: SecondaryId[]): UpdateStatus;
updateMessagingConsent(channelNumber: MessagingChannelNumber, action: string): ConsentUpdateReply;
/**
* <p>Set a reminder to be triggered at the specified time for a particular customer</p>
* <p>Fetches the customer's app data and lock it from fetching(for up to <b>90s</b>)
* until next call to update app data.</p>
*/
addCustomerReminder(customer: Customer, reminder: Reminder): UpdateStatus;
leaseAppData(): LeasedAppData;
/**
* <p>Cancels a previously set reminder with the key <code>key</code> on the customer</p>
* <p>Sets some app data on the customer.
* Values in the data object can either be strings or buffers,
* depending on the set serializer. @see {@link ConnectionOptions}</p>
*/
cancelCustomerReminder(customer: Customer, key: string): UpdateStatus;
updateAppData(data: any): CustomerStateUpdateReply;
/**
* <p>Set a reminder to be triggered at the specified time for customers with the particular tag</p>
* <p>Remove customer's app data</p>
*/
addCustomerReminderByTag(tag: Tag, reminder: Reminder): WorkStatus;
deleteAppData(): CustomerStateUpdateReply;
/**
* <p>Cancels a previously set reminder with tag <code>tag</code> and key <code>key</code></p>
*/
cancelCustomerReminderByTag(tag: Tag, key: string): WorkStatus;
/**
* <p>Sets some metadata on the customer.
* Values in the metadata object can either be strings or buffers,
* depending on your serializer. @see {@link Client}</p>
* depending on the set serializer</p>
*/
updateCustomerMetadata(customer: Customer, metadata: any): UpdateStatus;
updateMetadata(metadata: any): CustomerStateUpdateReply;
/**
* <p>Remove some metadata from a customer.</p>
* <p>Remove some metadata from a customer. <code>keys</code> is an array of strings</p>
*/
deleteCustomerMetadata(customer: Customer, keys: string[]): UpdateStatus;
deleteMetadata(keys: string[]): CustomerStateUpdateReply;
/**
* <p>Sets some app data on the customer.
* Value of the data object can either be a string or a buffer,
* depending on your serializer. @see {@link Client}</p>
* <p>Update a customer's secondary Ids</p>
*/
updateCustomerAppData(customer: Customer, data: any): UpdateStatus;
updateSecondaryIds(secondaryIds: SecondaryId[]): CustomerStateUpdateReply;
/**
* <p>Fetches the customer's app data and lock it from fetching(for up to <b>90s</b>)
* until next call to update app data.</p>
* <p>Remove some secondary Ids from a customer</p>
*/
leaseCustomerAppData(customer: Customer): LeasedAppData;
deleteSecondaryIds(secondaryIds: SecondaryId[]): CustomerStateUpdateReply;
/**
* <p>Remove customer's app data.</p>
*/
deleteCustomerAppData(customer: Customer): UpdateStatus;
/**
* <p>Initiate a customer activity</p>
*/
updateCustomerActivity(customerNumber: CustomerNumber, channelNumber: ActivityChannelNumber, activity: Activity): UpdateStatus;
/**
* <p>Initiate a voice call to customer from channelNumber</p>
*/
makeVoiceCall(customer: Customer, channelNumber: string, actions: VoiceAction[]): VoiceStatus;
}
declare namespace Elarian {
/**
* <p>A customer object. @see {@link Customer}</p>
*/
class Customer {
}
}
/**
* <p>A customer is your end-user, represented by a number (from a cellular, facebook or telegram)</p>
*/
declare class Customer {
constructor(params: CustomerParams);
/**
* <p>Fetch the customer's current state.</p>
*/
getState(): CustomerState;
/**
* <p>Merge otherCustomer's state into this customer's state and discard otherCustomer</p>
*/
adoptState(otherCustomer: Customer): UpdateStatus;
/**
* <p>Update a customer's tag list.</p>
*/
updateTag(tags: Tag[]): UpdateStatus;
updateTags(tags: Tag[]): CustomerStateUpdateReply;
/**
* <p>Remove some tags from a customer</p>
*/
deleteTag(tags: Tag[]): UpdateStatus;
deleteTags(tags: string[]): CustomerStateUpdateReply;
/**
* <p>Update a customer's secondary Ids</p>
*/
updateSecondaryId(secondaryIds: SecondaryId[]): UpdateStatus;
/**
* <p>Remove some secondary Ids from a customer</p>
*/
deleteSecondaryId(secondaryIds: SecondaryId[]): UpdateStatus;
/**
* <p>Set a reminder to be triggered at the specified time for a particular customer</p>
*/
addReminder(reminder: Reminder): UpdateStatus;
addReminder(reminder: Reminder): CustomerStateUpdateReply;
/**
* <p>Cancels a previously set reminder with the key <code>key</code> on the customer</p>
*/
cancelReminder(key: string): UpdateStatus;
cancelReminder(key: string): CustomerStateUpdateReply;
/**

@@ -190,48 +119,37 @@ * <p>Fetch customer metadata</p>

getMetadata(): any;
}
/**
* <p>Instantiate an elarian client. You have to call connect() on then client to start using it</p>
*/
declare class Elarian extends Client {
constructor(config: ClientConfig);
/**
* <p>Sets some metadata on the customer.
* Values in the metadata object can either be strings or buffers,
* depending on the set serializer</p>
* <p>Generate a short-lived auth token to use instead of apiKey. Used for browser and mobile clients.</p>
*/
updateMetadata(metadata: any): UpdateStatus;
generateAuthToken(): AuthToken;
/**
* <p>Remove some metadata from a customer. <code>keys</code> is an array of strings</p>
* <p>Send message by tag</p>
*/
deleteMetadata(keys: string[]): UpdateStatus;
sendMessageByTag(tag: Tag, channelNumber: MessagingChannelNumber, message: Message): TagUpdateReply;
/**
* <p>Sets some app data on the customer.
* Values in the data object can either be strings or buffers,
* depending on the set serializer</p>
* <p>Initiate a payment transaction</p>
*/
updateAppData(data: any): UpdateStatus;
initiatePayment(debitParty: CustomerPayment | Wallet | Purse, creditParty: CustomerPayment | Wallet | Purse, value: Cash): InitiatePaymentReply;
/**
* <p>Fetches the customer's app data and lock it from fetching(for up to <b>90s</b>)
* until next call to update app data.</p>
* <p>Set a reminder to be triggered at the specified time for customers with the particular tag</p>
*/
leaseAppData(): LeasedAppData;
addCustomerReminderByTag(tag: Tag, reminder: Reminder): TagUpdateReply;
/**
* <p>Remove customer's app data</p>
* <p>Cancels a previously set reminder with tag <code>tag</code> and key <code>key</code></p>
*/
deleteAppData(): UpdateStatus;
cancelCustomerReminderByTag(tag: Tag, key: string): TagUpdateReply;
}
declare namespace Elarian {
/**
* <p>Send a message to the customer from the specified channel number.</p>
* <p>A customer object. @see {@link Customer}</p>
*/
sendMessage(channelNumber: MessagingChannelNumber, body: Body): MessageStatus;
/**
* <p>Initiate a voice call to the customer</p>
*/
makeVoiceCall(channelNumber: string, actions: VoiceAction[]): MessageStatus;
/**
* <p>Allow or block a customer from receiving messages from a channel</p>
* @param action - <p>allow or block</p>
*/
updateMessagingConsent(channelNumber: MessagingChannelNumber, action: string): ConsentStatus;
/**
* <p>Initiate a customer activity</p>
*/
updateActivity(channelNumber: ActivityChannelNumber, sessionId: Activity): UpdateStatus;
/**
* <p>Initiate a payment transaction</p>
*/
requestPayment(source: PaymentChannelNumber | Wallet, destination: Wallet | Purse, value: Cash): PaymentStatus;
class Customer {
}
}

@@ -242,8 +160,8 @@

*/
declare class Simulator {
constructor(config: ElarianConfig);
declare class Simulator extends Client {
constructor(config: ClientConfig);
/**
* <p>Initiate a message request</p>
*/
receiveMessage(customerNumber: string, channelNumber: MessagingChannelNumber, sessionId: string, messageParts: SimulatorMessageBody[]): void;
receiveMessage(phoneNumber: string, channelNumber: MessagingChannelNumber, sessionId: string, parts: SimulatorMessageBody[]): void;
/**

@@ -260,24 +178,46 @@ * <p>Initiate payment request</p>

/**
* <p>An object representing a tag. Tags can be used to group customers based on some similarities. e.g. loan defaulters, etc.</p>
* <p>An object representing client params</p>
* @property [authToken] - <p>received from an client that authenticated with the API key. @see {@link Elarian.generateAuthToken}</p>
* @property [isSimulator] - <p>Run this client as a simulator</p>
* @property [allowNotifications] - <p>allow this non-simulator client to receive notifications or not</p>
* @property [options] - <p>setup connection options</p>
*/
declare type Tag = {
key: string;
value: string;
expiresAt?: number;
declare type ClientConfig = {
apiKey: string;
appId: string;
orgId: string;
authToken?: string;
isSimulator?: boolean;
allowNotifications?: boolean;
options?: ConnectionOptions;
};
/**
* <p>An object representing a secondary id. Secondary Ids can be used to add some more unique identities to a customer. e.g. driver's license, etc.</p>
* <p>An object representing serializer</p>
*/
declare type SecondaryId = {
key: string;
value: string;
declare type Serializer = {
type: text | binary;
serialize: (...params: any[]) => any;
deserialize: (...params: any[]) => any;
};
/**
* <p>An object representing a customer number.</p>
* <p>An object representing config options</p>
* @property [serializer] - <p>used to (de)serialize your metadata</p>
*/
declare type CustomerNumber = {
declare type ConnectionOptions = {
lifetime?: number;
keepAlive?: number;
resumable?: boolean;
notificationTimeout?: number;
serializer?: Serializer;
};
/**
* <p>An object representing customer params</p>
*/
declare type CustomerParams = {
customerId: string;
number: string;
provider: cellular | telegram | facebook | email | web;
provider?: string;
partition?: string;

@@ -287,43 +227,64 @@ };

/**
* <p>An object representing a messaging channel number</p>
* <p>An object representing a tag. Tags can be used to group customers based on some similarities. e.g. loan defaulters, etc.</p>
* @property [expiresAt] - <p>timestamp in seconds. e.g. 1615361861</p>
*/
declare type MessagingChannelNumber = {
number: string;
channel: sms | telegram | whatsapp | email | messenger | voice;
declare type Tag = {
key: string;
value: string;
expiresAt?: number;
};
/**
* <p>An object representing media</p>
* <p>An object representing a reminder</p>
* @property remindAt - <p>timestamp in seconds e.g 1615361861</p>
* @property [interval] - <p>duration in seconds e.g. 60</p>
*/
declare type Media = {
url: string;
type: image | video | audio | document | voice | sticker | contact;
declare type Reminder = {
key: string;
remindAt: number;
payload: string;
interval?: number;
};
/**
* <p>An object representing location</p>
* <p>An object representing auth token</p>
* @property lifetime - <p>in seconds</p>
*/
declare type Location = {
latitude: double;
longitude: double;
label: string;
address: string;
declare type AuthToken = {
token: string;
lifetime: number;
};
/**
* <p>An object representing email</p>
* <p>An obkect representing a paymennt reply</p>
*/
declare type Email = {
subject: string;
bodyPlain: string;
bodyHtml: string;
ccList: string[];
bccList: string[];
attachments: string[];
declare type InitiatePaymentReply = {
status: number;
description: string;
transactionId: string;
debitCustomerId: string;
creditCustomerId: string;
};
declare type TagUpdateReply = {
status: boolean;
description: string;
workId: string;
};
/**
* <p>An object representing a message</p>
*/
declare type Message = {
body: MessageBody;
labels?: string[];
providerTag?: string;
replyToken?: string;
replyPrompt?: ReplyPrompt;
};
/**
* <p>An object representing a message body</p>
*/
declare type Body = {
declare type MessageBody = {
text?: string;

@@ -340,50 +301,10 @@ template?: Template;

/**
* <p>An object representing a message body</p>
* <p>An object representing a ussd menu</p>
*/
declare type SimulatorMessageBody = {
text?: string;
media?: Media;
location?: Location;
email?: Email;
ussd?: string;
voice?: VoiceCallInput;
declare type UssdMenu = {
text: string;
isTerminal: boolean;
};
/**
* <p>An object representing a voice call input</p>
* @property direction - <p>outbound or inbound</p>
*/
declare type VoiceCallInput = {
direction: string;
status: string;
startedAt: number;
hangupCause: string;
dtmfDigits: string;
recordingUrl: string;
dialData: VoiceCallDialInput;
queueData: VoiceCallQueueInput;
};
/**
* <p>An object representing a voice call dial input</p>
*/
declare type VoiceCallDialInput = {
destinationNumber: string;
startedAt: number;
duration: number;
};
/**
* <p>An object representing a voice call queue input</p>
*/
declare type VoiceCallQueueInput = {
destinationNumber: string;
enqueuedAt: number;
dequeuedAt: number;
dequeuedToNumber: string;
dequeuedToSessionId: string;
queueDuration: number;
};
/**
* <p>An object representing a message reply prompt</p>

@@ -414,56 +335,48 @@ */

/**
* <p>An object representing a message body</p>
* <p>An object representing a secondary id. Secondary Ids can be used to add some more unique identities to a customer. e.g. driver's license, etc.</p>
*/
declare type Message = {
body: Body;
labels?: string[];
providerTag?: string;
replyToken?: string;
replyPrompt?: ReplyPrompt;
declare type SecondaryId = {
key: string;
value: string;
};
/**
* <p>An object representing a customer activity</p>
* <p>An object representing a customer number.</p>
* @property provider - <p>one of [cellular|telegram|facebook|email|web]</p>
*/
declare type Activity = {
sessionId: string;
key: string;
properties?: any;
declare type CustomerNumber = {
number: string;
provider: string;
partition?: string;
};
/**
* <p>An object representing client params</p>
* @property [authToken] - <p>received from an client that authenticated with the API key. @see Elarian.generateAuthToken()</p>
* @property [isSimulator] - <p>Run this client as a simulator</p>
* @property [allowNotifications] - <p>allow this non-simulator client to receive notifications or not</p>
* @property [options] - <p>setup connection options</p>
* <p>An object representing media</p>
* @property type - <p>one of [image|video|audio|document|voice|sticker|contact]</p>
*/
declare type ElarianConfig = {
apiKey: string;
appId: string;
orgId: string;
authToken?: string;
isSimulator?: boolean;
allowNotifications?: boolean;
options?: ConfigOptions;
declare type Media = {
url: string;
type: string;
};
/**
* <p>An object representing serializer</p>
* <p>An object representing location</p>
*/
declare type Serializer = {
type: text | binary;
serialize: (...params: any[]) => any;
deserialize: (...params: any[]) => any;
declare type Location = {
latitude: double;
longitude: double;
label: string;
address: string;
};
/**
* <p>An object representing config options</p>
* @property [serializer] - <p>used to (de)serialize your metadata</p>
* <p>An object representing email</p>
*/
declare type ConfigOptions = {
lifetime?: number;
keepAlive?: number;
resumable?: boolean;
serializer?: Serializer;
declare type Email = {
subject: string;
bodyPlain: string;
bodyHtml: string;
ccList: string[];
bccList: string[];
attachments: string[];
};

@@ -475,3 +388,3 @@

declare type Cash = {
amount: double;
amount: number;
currencyCode: string;

@@ -481,100 +394,2 @@ };

/**
* <p>An object representing wallet</p>
*/
declare type Wallet = {
customerId: string;
walletId: string;
};
/**
* <p>An object representing purse</p>
*/
declare type Purse = {
purseId: string;
};
/**
* <p>An object representing a payment channel</p>
* @property channel - <p>number provider. Must be one of ['cellular']</p>
*/
declare type PaymentChannelNumber = {
number: string;
channel: string;
};
/**
* <p>An object representing an activity channel number</p>
* @property channel - <p>channel type. Must be one of ['web','modile']</p>
*/
declare type ActivityChannelNumber = {
number: string;
channel: string;
};
/**
* <p>An object representing a payment transaction</p>
*/
declare type PaymentTransaction = {
transactionId: string;
appId: string;
creditParty: CustomerPayment | Wallet | Purse;
debitParty: CustomerPayment | Wallet | Purse;
value: Cash;
status: number;
createdAt: number;
updatedAt: number;
};
/**
* <p>An object representing a voice channel</p>
*/
declare type VoiceChannelNumber = {
number: string;
channel: string;
};
/**
* <p>An object representing a ussd channel</p>
*/
declare type UssdChannelNumber = {
number: string;
channel: string;
};
/**
* <p>An object representing a customer's payment source or destination</p>
*/
declare type CustomerPayment = {
customerNumber: CustomerNumber;
channelNumber: PaymentChannelNumber;
};
/**
* <p>An object representing customer params</p>
*/
declare type CustomerParams = {
customerNumber: CustomerNumber;
customerId?: string;
};
/**
* <p>An object representing a reminder</p>
* @property remindAt - <p>timestamp in seconds</p>
*/
declare type Reminder = {
key: string;
remindAt: number;
payload: string;
interval?: number;
};
/**
* <p>An object representing a ussd menu</p>
*/
declare type UssdMenu = {
text: string;
isTerminal: boolean;
};
/**
* <p>An object representing a 'say' voice action</p>

@@ -672,7 +487,9 @@ */

/**
* <p>Notification data</p>
* <p>An object representing the notification data</p>
*/
declare type Notification = {
data: any;
customer: Customer;
orgId: string;
appId: string;
customerId: string;
createdAt: long;
};

@@ -683,3 +500,3 @@

*/
declare type NotificationCallback = (error: Error, message: Message | UssdMenu | VoiceAction[], appData: any) => void;
declare type NotificationCallback = (message?: MessageBody, appData?: any) => void;

@@ -690,93 +507,253 @@ /**

*/
declare type EventListener = (notification: Notification, callback?: NotificationCallback) => void;
declare type NotificationHandler = (notification: Notification, customer: Customer, callback?: NotificationCallback) => void;
/**
* <p>Reminder notification</p>
*/
declare type ReminderNotification = Notification;
/**
* <p>Voice call notification</p>
*/
declare type VoiceCallNotification = Notification;
/**
* <p>Message status notification</p>
* @property status - <p>one of [queued, sent, delivered, read, received, session_initiated, failed, no_consent, no_capability, expired, no_session_in_progress, other_session_in_progress, invalid_reply_token, invalid_channel_number, not_supported, invalid_reply_to_message_id, invalid_customer_id, duplicate_request , tag_not_found, customer_number_not_found, decommissioned_customerid, rejected, invalid_request, application_error]</p>
*/
declare type MessageStatusNotification = Notification;
/**
* <p>USSD session notification</p>
*/
declare type UssdSessionNotification = Notification;
/**
* <p>SMS notification</p>
*/
declare type ReceivedSmsNotification = Notification;
/**
* <p>Whatsapp, telegram or email notification</p>
*/
declare type ReceivedMediaNotification = Notification;
/**
* <p>Payment status notification</p>
* @property status - <p>one of [queued, pending_confirmation, pending_validation, validated, invalid_request, not_supported, insufficient_funds, application_error, not_allowed, duplicate_request, invalid_purse, invalid_wallet, decommissioned_customer_id, success, pass_through, failed, throttled, expired, rejected, reversed]</p>
*/
declare type PaymentStatusNotification = Notification;
/**
* <p>Payment status notification</p>
* @property status - <p>one of [queued, pending_confirmation, pending_validation, validated, invalid_request, not_supported, insufficient_funds, application_error, not_allowed, duplicate_request, invalid_purse, invalid_wallet, decommissioned_customer_id, success, pass_through, failed, throttled, expired, rejected, reversed]</p>
*/
declare type ReceivedPaymentNotification = Notification;
/**
* <p>Wallet payment status notification</p>
* @property status - <p>one of [queued, pending_confirmation, pending_validation, validated, invalid_request, not_supported, insufficient_funds, application_error, not_allowed, duplicate_request, invalid_purse, invalid_wallet, decommissioned_customer_id, success, pass_through, failed, throttled, expired, rejected, reversed]</p>
*/
declare type WalletPaymentStatusNotification = Notification;
/**
* <p>Custoer activity notification</p>
*/
declare type CustomerActivityNotification = Notification;
/**
* <p>Message reaction notification</p>
* @property reaction - <p>one of [clicked, unsubscribed, complained]</p>
*/
declare type SentMessageReactionNotification = Notification;
/**
* <p>Messaging session ended notification</p>
* @property duration - <p>in seconds</p>
* @property reason - <p>one of [normal_clearing, inactivity, failure]</p>
*/
declare type MessagingSessionEndedNotification = Notification;
/**
* <p>Messaging session initialized notification</p>
* @property expiresAt - <p>timestamp in seconds</p>
*/
declare type MessagingSessionInitializedNotification = Notification;
/**
* <p>Messaging consent update notification</p>
* @property update - <p>one of [allow, block]</p>
* @property status - <p>one of [queued, completed, invalid_channel_number, decommissioned_customer_id, application_error]</p>
*/
declare type MessagingConsentUpdateNotification = Notification;
/**
* <p>An string representing an event. Must be one of:</p>
* <ul>
* <li>data</li>
* <li>-- Connection Events--</li>
* <li>error</li>
* <li>closed</li>
* <li>pending</li>
* <li>connected</li>
* <li>connecting</li>
* <li>-- Simulator Events --</li>
* <li>sendMessage</li>
* <li>makeVoiceCall</li>
* <li>sendCustomerPayment</li>
* <li>sendChannelPayment</li>
* <li>checkoutPayment<li>
* <li>-- Customer Events --</li>
* <li>reminder</li>
* <li>voiceCall</li>
* <li>messageStatus</li>
* <li>ussdSession</li>
* <li>receivedSms</li>
* <li>receivedEmail</li>
* <li>receivedMessenger</li>
* <li>receivedTelegram</li>
* <li>receivedWhatsapp</li>
* <li>paymentStatus</li>
* <li>receivedPayment</li>
* <li>receivedMessage</li>
* <li>customerActivity</li>
* <li>walletPaymentStatus</li>
* <li>sentMessageReaction</li>
* <li>messagingSessionEnded</li>
* <li>messagingConsentUpdate</li>
* <li>messagingSessionStarted</li>
* <li>messagingSessionRenewed</li>
* <li>Connection Events:
* <ul>
* <li><b>error</b>: Emitted on connection error</li>
* <li><b>closed</b>: Emitted on connection closed</li>
* <li><b>pending</b>: Emitted when not connected</li>
* <li><b>connected</b>: Emitted on connection success</li>
* <li><b>connecting</b>: Emitted when connecting </li>
* </ul>
* </li>
* <li>App Events
* <ul>
* <li><b>reminder</b>: @see {@link ReminderNotification}</li>
* <li><b>voiceCall</b>: @see {@link VoiceCallNotification}</li>
* <li><b>messageStatus</b>: @see {@link MessageStatusNotification}</li>
* <li><b>ussdSession</b>: @see {@link UssdSessionNotification}</li>
* <li><b>receivedSms</b>: @see {@link ReceivedSmsNotification}</li>
* <li><b>receivedEmail</b>: @see {@link ReceivedMediaNotification}</li>
* <li><b>receivedFbMessenger</b>: @see {@link ReceivedMediaNotification}</li>
* <li><b>receivedTelegram</b>: @see {@link ReceivedMediaNotification}</li>
* <li><b>receivedWhatsapp</b>: @see {@link ReceivedMediaNotification}</li>
* <li><b>paymentStatus</b>: @see {@link PaymentStatusNotification}</li>
* <li><b>receivedPayment</b>: @see {@link ReceivedPaymentNotification}</li>
* <li><b>customerActivity</b>: @see {@link CustomerActivityNotification}</li>
* <li><b>walletPaymentStatus</b>: @see {@link WalletPaymentStatusNotification}</li>
* <li><b>sentMessageReaction</b>: @see {@link SentMessageReactionNotification}</li>
* <li><b>messagingSessionEnded</b>: @see {@link MessagingSessionEndedNotification}</li>
* <li><b>messagingConsentUpdate</b>: @see {@link MessagingConsentUpdateNotification}</li>
* <li><b>messagingSessionStarted</b>: @see {@link MessagingSessionInitializedNotification}</li>
* <li><b>messagingSessionRenewed</b>: @see {@link MessagingSessionInitializedNotification}</li>
* </ul>
* </li>
* <li>Sandbox Events
* <ul>
* <li><b>sendMessage</b>: @see {@link SendMessageSimulatorNotification}</li>
* <li><b>makeVoiceCall</b>: @see {@link MakeVoiceCallSimulatorNotification}</li>
* <li><b>sendCustomerPayment</b>: @see {@link CustomerPaymentSimulatorNotification}</li>
* <li><b>sendChannelPayment</b>: @see {@link SendChannelPaymentSimulatorNotification}</li>
* <li><b>checkoutPayment</b>: @see {@link CustomerPaymentSimulatorNotification}</li>
* </ul>
* </li>
* </ul>
*/
declare type Event = string;
declare type UpdateStatus = {
customerId: string;
status: boolean;
description: string;
/**
* <p>An object representing a message body</p>
*/
declare type SimulatorMessageBody = {
text?: string;
media?: Media;
location?: Location;
email?: Email;
ussd?: string;
voice?: VoiceCallInput;
};
declare type WorkStatus = {
status: boolean;
description: string;
workId: string;
/**
* <p>An object representing a voice call input</p>
* @property direction - <p>one of [outbound, inbound]</p>
* @property status - <p>one of [queued, answered, ringing, active, dialing, dial_completed, bridged, enqueued, dequeued, transferred, transfer_completed, completed, insufficient_credit, not_answered, invalid_phone_number, destination_not_supported, decommissioned_customerid, expired, invalid_channel_number, application_error]</p>
* @property hangupCause - <p>one of [unallocated_number, user_busy, normal_clearing, no_user_response, no_answer, subscriber_absent, call_rejected, normal_unspecified, normal_temporary_failure, service_unavailable, recovery_on_timer_expire, originator_cancel, lose_race, user_not_registered]</p>
*/
declare type VoiceCallInput = {
direction: string;
status: string;
startedAt: number;
hangupCause: string;
dtmfDigits: string;
recordingUrl: string;
dialData: VoiceCallDialInput;
queueData: VoiceCallQueueInput;
};
declare type MessageStatus = {
status: string;
description: string;
customerId: string;
messageId: string;
/**
* <p>An object representing a voice call dial input</p>
*/
declare type VoiceCallDialInput = {
destinationNumber: string;
startedAt: number;
duration: number;
};
declare type ConsentStatus = {
status: string;
description: string;
/**
* <p>An object representing a voice call queue input</p>
*/
declare type VoiceCallQueueInput = {
destinationNumber: string;
enqueuedAt: number;
dequeuedAt: number;
dequeuedToNumber: string;
dequeuedToSessionId: string;
queueDuration: number;
};
/**
* <p>An object representing a customer's payment source or destination</p>
*/
declare type CustomerPayment = {
customerNumber: CustomerNumber;
channelNumber: PaymentChannelNumber;
};
/**
* <p>An object representing wallet</p>
*/
declare type Wallet = {
customerId: string;
walletId: string;
};
declare type LeasedAppData = string | any;
/**
* <p>An object representing purse</p>
*/
declare type Purse = {
purseId: string;
};
/**
* @property lifetime - <p>in seconds</p>
* <p>An object representing a payment channel</p>
* @property channel - <p>number provider. Must be one of ['cellular']</p>
*/
declare type AuthToken = {
token: string;
lifetime: number;
declare type PaymentChannelNumber = {
number: string;
channel: string;
};
declare type PaymentStatus = {
status: number;
/**
* <p>An object representing a messaging channel number</p>
* @property channel - <p>one of [sms,telegram,whatsapp,email,messenger,voice]</p>
*/
declare type MessagingChannelNumber = {
number: string;
channel: string;
};
/**
* <p>An object representing an activity channel number</p>
* @property channel - <p>channel type. Must be one of ['web','modile']</p>
*/
declare type ActivityChannelNumber = {
number: string;
channel: string;
};
declare type CustomerStateUpdateReply = {
customerId: string;
status: boolean;
description: string;
transactionId: string;
debitCustomerId: string;
creditCustomerId: string;
};
declare type VoiceStatus = {
status: number;
declare type ConsentUpdateReply = {
status: string;
description: string;
sessionId: string;
customerId: string;
};
/**
* @property status - <p>one of [queued, sent, delivered, read, received, session_initiated, failed, no_consent, no_capability, expired, no_session_in_progress, other_session_in_progress, invalid_reply_token, invalid_channel_number, not_supported, invalid_reply_to_message_id, invalid_customer_id, duplicate_request , tag_not_found, customer_number_not_found, decommissioned_customerid, rejected, invalid_request, application_error]</p>
*/
declare type MessageReply = {
status: string;
description: string;
customerId: string;
sessionId: string;
messageId: string;
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc