Comparing version 0.2.18 to 0.2.19
@@ -331,2 +331,8 @@ ## Classes | ||
* [.sendMessageByTag(tag, channelNumber, message)](#Elarian+sendMessageByTag) ⇒ <code>TagUpdateReply</code> | ||
* [.replayMessagingConsentUpdate(customerNumber, channelNumber, consent, updatedAt)](#Elarian+replayMessagingConsentUpdate) | ||
* [.replayMessageReactionUpdate(customerNumber, channelNumber, messageId, reaction, updatedAt)](#Elarian+replayMessageReactionUpdate) | ||
* [.replayMessagingSession(customerNumber, channelNumber, sessionUpdate)](#Elarian+replayMessagingSession) | ||
* [.replayMessageStatusUpdate(customerNumber, channelNumber, statusUpdate)](#Elarian+replayMessageStatusUpdate) | ||
* [.replayReceivedMessage(customerNumber, channelNumber, receivedMessage)](#Elarian+replayReceivedMessage) | ||
* [.replaySentMessage(customerNumber, channelNumber, sentMessage)](#Elarian+replaySentMessage) | ||
* [.initiatePayment(debitParty, creditParty, value)](#Elarian+initiatePayment) ⇒ <code>InitiatePaymentReply</code> | ||
@@ -380,2 +386,83 @@ * [.addCustomerReminderByTag(tag, reminder)](#Elarian+addCustomerReminderByTag) ⇒ <code>TagUpdateReply</code> | ||
<a name="Elarian+replayMessagingConsentUpdate"></a> | ||
### elarian.replayMessagingConsentUpdate(customerNumber, channelNumber, consent, updatedAt) | ||
<p>Replay a messaging consent update event</p> | ||
**Kind**: instance method of [<code>Elarian</code>](#Elarian) | ||
| Param | Type | | ||
| --- | --- | | ||
| customerNumber | <code>CustomerNumber</code> | | ||
| channelNumber | <code>MessagingChannel</code> | | ||
| consent | <code>string</code> | | ||
| updatedAt | <code>number</code> | | ||
<a name="Elarian+replayMessageReactionUpdate"></a> | ||
### elarian.replayMessageReactionUpdate(customerNumber, channelNumber, messageId, reaction, updatedAt) | ||
<p>Replay a message reaction update event</p> | ||
**Kind**: instance method of [<code>Elarian</code>](#Elarian) | ||
| Param | Type | | ||
| --- | --- | | ||
| customerNumber | <code>CustomerNumber</code> | | ||
| channelNumber | <code>MessagingChannel</code> | | ||
| messageId | <code>string</code> | | ||
| reaction | <code>string</code> | | ||
| updatedAt | <code>number</code> | | ||
<a name="Elarian+replayMessagingSession"></a> | ||
### elarian.replayMessagingSession(customerNumber, channelNumber, sessionUpdate) | ||
<p>Replay a messaging session event</p> | ||
**Kind**: instance method of [<code>Elarian</code>](#Elarian) | ||
| Param | Type | | ||
| --- | --- | | ||
| customerNumber | <code>CustomerNumber</code> | | ||
| channelNumber | <code>MessagingChannel</code> | | ||
| sessionUpdate | <code>MessageSessionUpdate</code> | | ||
<a name="Elarian+replayMessageStatusUpdate"></a> | ||
### elarian.replayMessageStatusUpdate(customerNumber, channelNumber, statusUpdate) | ||
<p>Replay a messaging status event</p> | ||
**Kind**: instance method of [<code>Elarian</code>](#Elarian) | ||
| Param | Type | | ||
| --- | --- | | ||
| customerNumber | <code>CustomerNumber</code> | | ||
| channelNumber | <code>MessagingChannel</code> | | ||
| statusUpdate | <code>MessageStatusUpdate</code> | | ||
<a name="Elarian+replayReceivedMessage"></a> | ||
### elarian.replayReceivedMessage(customerNumber, channelNumber, receivedMessage) | ||
<p>Replay a received message event</p> | ||
**Kind**: instance method of [<code>Elarian</code>](#Elarian) | ||
| Param | Type | | ||
| --- | --- | | ||
| customerNumber | <code>CustomerNumber</code> | | ||
| channelNumber | <code>MessagingChannel</code> | | ||
| receivedMessage | <code>ReceivedMessage</code> | | ||
<a name="Elarian+replaySentMessage"></a> | ||
### elarian.replaySentMessage(customerNumber, channelNumber, sentMessage) | ||
<p>Replay a sent message event</p> | ||
**Kind**: instance method of [<code>Elarian</code>](#Elarian) | ||
| Param | Type | | ||
| --- | --- | | ||
| customerNumber | <code>CustomerNumber</code> | | ||
| channelNumber | <code>MessagingChannel</code> | | ||
| sentMessage | <code>SentMessage</code> | | ||
<a name="Elarian+initiatePayment"></a> | ||
@@ -513,3 +600,3 @@ | ||
| sessionId | <code>string</code> | | ||
| parts | <code>Array.<SimulatorMessageBody></code> | | ||
| parts | <code>Array.<InboundMessageBody></code> | | ||
| cost | <code>Cash</code> | | ||
@@ -516,0 +603,0 @@ |
@@ -7,7 +7,13 @@ /* eslint-disable no-underscore-dangle */ | ||
addCustomer, | ||
addCashCost, | ||
getStatusString, | ||
makeMessageParts, | ||
addCustomerNumber, | ||
getChannelProvider, | ||
getMessageReaction, | ||
getChannelNumberProvider, | ||
getMessageDeliveryStatus, | ||
getMessageSessionEndReason, | ||
getMessageConsentUpdateAction, | ||
getMessageDeliveryStatusString, | ||
getChannelProvider, | ||
} = require('./utils'); | ||
@@ -19,2 +25,5 @@ | ||
const { | ||
Duration, | ||
Timestamp, | ||
StringValue, | ||
MessagingChannel, | ||
@@ -28,4 +37,10 @@ AppToServerCommand, | ||
AppToServerCommandReply, | ||
ReplaySentMessageCommand, | ||
MessagingConsentUpdateStatus, | ||
ReplayReceivedMessageCommand, | ||
UpdateMessagingConsentCommand, | ||
ReplayMessagingSessionCommand, | ||
ReplayMessageStatusUpdateCommand, | ||
ReplayMessageReactionUpdateCommand, | ||
ReplayMessagingConsentUpdateCommand, | ||
} = ElarianMessages; | ||
@@ -270,2 +285,392 @@ | ||
/** | ||
* Replay a messaging consent update event | ||
* @param {CustomerNumber} customerNumber | ||
* @param {MessagingChannel} channelNumber | ||
* @param {string} consent | ||
* @param {number} updatedAt | ||
*/ | ||
// eslint-disable-next-line max-len | ||
Elarian.prototype.replayMessagingConsentUpdate = function replayMessagingConsentUpdate(customerNumber, channelNumber, consent, updatedAt) { | ||
const socket = this.getSocket(); | ||
if (!customerNumber) { | ||
throw new Error('customerNumber is required'); | ||
} | ||
if (!channelNumber) { | ||
throw new Error('channelNumber is required'); | ||
} | ||
let cmd = new ReplayMessagingConsentUpdateCommand() | ||
.setUpdate(getMessageConsentUpdateAction(consent)) | ||
.setUpdatedAt(new Timestamp().setSeconds(Math.floor(updatedAt || 0))) | ||
.setChannelNumber( | ||
new MessagingChannelNumber() | ||
.setNumber(channelNumber.number) | ||
.setChannel(getChannelProvider(channelNumber.channel, MessagingChannel)), | ||
); | ||
cmd = addCustomerNumber(cmd, customerNumber); | ||
const req = new AppToServerCommand() | ||
.setReplayMessagingConsentUpdate(cmd); | ||
return new Promise((resolve, reject) => { | ||
socket | ||
.requestResponse({ | ||
data: Buffer.from(req.serializeBinary()), | ||
}) | ||
.subscribe({ | ||
onComplete: (value) => { | ||
try { | ||
const res = AppToServerCommandReply | ||
.deserializeBinary(value.data) | ||
.getUpdateCustomerState(); | ||
const result = { | ||
status: res.getStatus(), | ||
description: res.getDescription(), | ||
customerId: (res.getCustomerId() || { | ||
getValue: () => undefined, | ||
}).getValue(), | ||
}; | ||
resolve(result); | ||
} catch (ex) { | ||
reject(ex); | ||
} | ||
}, | ||
onError: (error) => reject(error), | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Replay a message reaction update event | ||
* @param {CustomerNumber} customerNumber | ||
* @param {MessagingChannel} channelNumber | ||
* @param {string} messageId | ||
* @param {string} reaction | ||
* @param {number} updatedAt | ||
*/ | ||
// eslint-disable-next-line max-len | ||
Elarian.prototype.replayMessageReactionUpdate = function replayMessageReactionUpdate(customerNumber, channelNumber, messageId, reaction, updatedAt) { | ||
const socket = this.getSocket(); | ||
if (!customerNumber) { | ||
throw new Error('customerNumber is required'); | ||
} | ||
if (!channelNumber) { | ||
throw new Error('channelNumber is required'); | ||
} | ||
let cmd = new ReplayMessageReactionUpdateCommand() | ||
.setReaction(getMessageReaction(reaction)) | ||
.setProviderMessageId(messageId) | ||
.setUpdatedAt(new Timestamp().setSeconds(Math.floor(updatedAt || 0))) | ||
.setChannelNumber( | ||
new MessagingChannelNumber() | ||
.setNumber(channelNumber.number) | ||
.setChannel(getChannelProvider(channelNumber.channel, MessagingChannel)), | ||
); | ||
cmd = addCustomerNumber(cmd, customerNumber); | ||
const req = new AppToServerCommand() | ||
.setReplayMessageReactionUpdate(cmd); | ||
return new Promise((resolve, reject) => { | ||
socket | ||
.requestResponse({ | ||
data: Buffer.from(req.serializeBinary()), | ||
}) | ||
.subscribe({ | ||
onComplete: (value) => { | ||
try { | ||
const res = AppToServerCommandReply | ||
.deserializeBinary(value.data) | ||
.getUpdateCustomerState(); | ||
const result = { | ||
status: res.getStatus(), | ||
description: res.getDescription(), | ||
customerId: (res.getCustomerId() || { | ||
getValue: () => undefined, | ||
}).getValue(), | ||
}; | ||
resolve(result); | ||
} catch (ex) { | ||
reject(ex); | ||
} | ||
}, | ||
onError: (error) => reject(error), | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Replay a messaging session event | ||
* @param {CustomerNumber} customerNumber | ||
* @param {MessagingChannel} channelNumber | ||
* @param {MessageSessionUpdate} sessionUpdate | ||
*/ | ||
// eslint-disable-next-line max-len | ||
Elarian.prototype.replayMessagingSession = function replayMessagingSession(customerNumber, channelNumber, sessionUpdate) { | ||
const socket = this.getSocket(); | ||
if (!customerNumber) { | ||
throw new Error('customerNumber is required'); | ||
} | ||
if (!channelNumber) { | ||
throw new Error('channelNumber is required'); | ||
} | ||
if (!sessionUpdate) { | ||
throw new Error('sessionUpdate is required'); | ||
} | ||
let cmd = new ReplayMessagingSessionCommand() | ||
.setProviderSessionId(sessionUpdate.sessionId) | ||
.setStartedAt(new Timestamp().setSeconds(Math.floor(sessionUpdate.startedAt || 0))) | ||
.setDuration(new Duration().setSeconds(sessionUpdate.duration)) | ||
.setEndReason(getMessageSessionEndReason(sessionUpdate.reason)) | ||
.setChannelNumber( | ||
new MessagingChannelNumber() | ||
.setNumber(channelNumber.number) | ||
.setChannel(getChannelProvider(channelNumber.channel, MessagingChannel)), | ||
); | ||
cmd = addCustomerNumber(cmd, customerNumber); | ||
cmd = addCashCost(cmd, sessionUpdate.cost); | ||
const req = new AppToServerCommand() | ||
.setReplayMessagingSession(cmd); | ||
return new Promise((resolve, reject) => { | ||
socket | ||
.requestResponse({ | ||
data: Buffer.from(req.serializeBinary()), | ||
}) | ||
.subscribe({ | ||
onComplete: (value) => { | ||
try { | ||
const res = AppToServerCommandReply | ||
.deserializeBinary(value.data) | ||
.getUpdateCustomerState(); | ||
const result = { | ||
status: res.getStatus(), | ||
description: res.getDescription(), | ||
customerId: (res.getCustomerId() || { | ||
getValue: () => undefined, | ||
}).getValue(), | ||
}; | ||
resolve(result); | ||
} catch (ex) { | ||
reject(ex); | ||
} | ||
}, | ||
onError: (error) => reject(error), | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Replay a messaging status event | ||
* @param {CustomerNumber} customerNumber | ||
* @param {MessagingChannel} channelNumber | ||
* @param {MessageStatusUpdate} statusUpdate | ||
*/ | ||
// eslint-disable-next-line max-len | ||
Elarian.prototype.replayMessageStatusUpdate = function replayMessageStatusUpdate(customerNumber, channelNumber, statusUpdate) { | ||
const socket = this.getSocket(); | ||
if (!customerNumber) { | ||
throw new Error('customerNumber is required'); | ||
} | ||
if (!channelNumber) { | ||
throw new Error('channelNumber is required'); | ||
} | ||
if (!statusUpdate) { | ||
throw new Error('statusUpdate is required'); | ||
} | ||
let cmd = new ReplayMessageStatusUpdateCommand() | ||
.setProviderMessageId(statusUpdate.messageId) | ||
.setUpdatedAt(new Timestamp().setSeconds(Math.floor(statusUpdate.updatedAt || 0))) | ||
.setStatus(getMessageDeliveryStatus(statusUpdate.status)) | ||
.setChannelNumber( | ||
new MessagingChannelNumber() | ||
.setNumber(channelNumber.number) | ||
.setChannel(getChannelProvider(channelNumber.channel, MessagingChannel)), | ||
); | ||
cmd = addCustomerNumber(cmd, customerNumber); | ||
cmd = addCashCost(cmd, statusUpdate.cost); | ||
const req = new AppToServerCommand() | ||
.setReplayMessageStatusUpdate(cmd); | ||
return new Promise((resolve, reject) => { | ||
socket | ||
.requestResponse({ | ||
data: Buffer.from(req.serializeBinary()), | ||
}) | ||
.subscribe({ | ||
onComplete: (value) => { | ||
try { | ||
const res = AppToServerCommandReply | ||
.deserializeBinary(value.data) | ||
.getUpdateCustomerState(); | ||
const result = { | ||
status: res.getStatus(), | ||
description: res.getDescription(), | ||
customerId: (res.getCustomerId() || { | ||
getValue: () => undefined, | ||
}).getValue(), | ||
}; | ||
resolve(result); | ||
} catch (ex) { | ||
reject(ex); | ||
} | ||
}, | ||
onError: (error) => reject(error), | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Replay a received message event | ||
* @param {CustomerNumber} customerNumber | ||
* @param {MessagingChannel} channelNumber | ||
* @param {ReceivedMessage} receivedMessage | ||
*/ | ||
// eslint-disable-next-line max-len | ||
Elarian.prototype.replayReceivedMessage = function replayReceivedMessage(customerNumber, channelNumber, receivedMessage) { | ||
const socket = this.getSocket(); | ||
if (!customerNumber) { | ||
throw new Error('customerNumber is required'); | ||
} | ||
if (!channelNumber) { | ||
throw new Error('channelNumber is required'); | ||
} | ||
if (!receivedMessage) { | ||
throw new Error('receivedMessage is required'); | ||
} | ||
let cmd = new ReplayReceivedMessageCommand() | ||
.setProviderMessageId(receivedMessage.messageId) | ||
.setProviderSessionId(new StringValue(receivedMessage.sessionId)) | ||
.setReceivedAt(new Timestamp().setSeconds(Math.floor(receivedMessage.receivedAt || 0))) | ||
.setInReplyTo(new StringValue(receivedMessage.inReplyTo)) | ||
.setProvider(getChannelNumberProvider(receivedMessage.provider)) | ||
.setChannelNumber( | ||
new MessagingChannelNumber() | ||
.setNumber(channelNumber.number) | ||
.setChannel(getChannelProvider(channelNumber.channel, MessagingChannel)), | ||
) | ||
.setPartsList(makeMessageParts(receivedMessage.parts)); | ||
cmd = addCustomerNumber(cmd, customerNumber); | ||
cmd = addCashCost(cmd, receivedMessage.cost); | ||
const req = new AppToServerCommand() | ||
.setReplayReceivedMessage(cmd); | ||
return new Promise((resolve, reject) => { | ||
socket | ||
.requestResponse({ | ||
data: Buffer.from(req.serializeBinary()), | ||
}) | ||
.subscribe({ | ||
onComplete: (value) => { | ||
try { | ||
const res = AppToServerCommandReply | ||
.deserializeBinary(value.data) | ||
.getUpdateCustomerState(); | ||
const result = { | ||
status: res.getStatus(), | ||
description: res.getDescription(), | ||
customerId: (res.getCustomerId() || { | ||
getValue: () => undefined, | ||
}).getValue(), | ||
}; | ||
resolve(result); | ||
} catch (ex) { | ||
reject(ex); | ||
} | ||
}, | ||
onError: (error) => reject(error), | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Replay a sent message event | ||
* @param {CustomerNumber} customerNumber | ||
* @param {MessagingChannel} channelNumber | ||
* @param {SentMessage} sentMessage | ||
*/ | ||
// eslint-disable-next-line max-len | ||
Elarian.prototype.replaySentMessage = function replaySentMessage(customerNumber, channelNumber, sentMessage) { | ||
const socket = this.getSocket(); | ||
if (!customerNumber) { | ||
throw new Error('customerNumber is required'); | ||
} | ||
if (!channelNumber) { | ||
throw new Error('channelNumber is required'); | ||
} | ||
if (!sentMessage) { | ||
throw new Error('sentMessage is required'); | ||
} | ||
let cmd = new ReplaySentMessageCommand() | ||
.setProviderMessageId(sentMessage.messageId) | ||
.setProviderSessionId(new StringValue(sentMessage.sessionId)) | ||
.setSentAt(new Timestamp().setSeconds(Math.floor(sentMessage.sentAt || 0))) | ||
.setInReplyTo(new StringValue(sentMessage.inReplyTo)) | ||
.setProvider(getChannelNumberProvider(sentMessage.provider)) | ||
.setStatus(getMessageDeliveryStatus(sentMessage.status)) | ||
.setChannelNumber( | ||
new MessagingChannelNumber() | ||
.setNumber(channelNumber.number) | ||
.setChannel(getChannelProvider(channelNumber.channel, MessagingChannel)), | ||
); | ||
cmd = addCustomerNumber(cmd, customerNumber); | ||
cmd = addCashCost(cmd, sentMessage.cost); | ||
cmd = addMessage(cmd, sentMessage.message); | ||
const req = new AppToServerCommand() | ||
.setReplaySentMessage(cmd); | ||
return new Promise((resolve, reject) => { | ||
socket | ||
.requestResponse({ | ||
data: Buffer.from(req.serializeBinary()), | ||
}) | ||
.subscribe({ | ||
onComplete: (value) => { | ||
try { | ||
const res = AppToServerCommandReply | ||
.deserializeBinary(value.data) | ||
.getUpdateCustomerState(); | ||
const result = { | ||
status: res.getStatus(), | ||
description: res.getDescription(), | ||
customerId: (res.getCustomerId() || { | ||
getValue: () => undefined, | ||
}).getValue(), | ||
}; | ||
resolve(result); | ||
} catch (ex) { | ||
reject(ex); | ||
} | ||
}, | ||
onError: (error) => reject(error), | ||
}); | ||
}); | ||
}; | ||
module.exports = Elarian; |
@@ -6,6 +6,5 @@ const Client = require('./client'); | ||
addCashValue, | ||
getMediaType, | ||
ElarianMessages, | ||
makeMessageParts, | ||
getChannelProvider, | ||
getCustomerEventDirection, | ||
} = require('./utils'); | ||
@@ -16,22 +15,9 @@ | ||
Duration, | ||
Timestamp, | ||
StringValue, | ||
PaymentStatus, | ||
PaymentChannel, | ||
VoiceCallStatus, | ||
UssdSessionStatus, | ||
MessagingChannel, | ||
MediaMessageBody, | ||
EmailMessageBody, | ||
InboundMessageBody, | ||
UssdInputMessageBody, | ||
LocationMessageBody, | ||
VoiceCallDialInput, | ||
VoiceCallQueueInput, | ||
PaymentChannelNumber, | ||
VoiceCallHangupCause, | ||
MessagingChannelNumber, | ||
CustomerEventDirection, | ||
SimulatorToServerCommand, | ||
VoiceCallInputMessageBody, | ||
SimulatorToServerCommandReply, | ||
@@ -70,3 +56,3 @@ ReceivePaymentSimulatorCommand, | ||
* @param {string} sessionId | ||
* @param {SimulatorMessageBody[]} parts | ||
* @param {InboundMessageBody[]} parts | ||
* @param {Cash} cost | ||
@@ -79,103 +65,2 @@ * @memberof Simulator | ||
const messageParts = parts.map((part) => { | ||
const keys = Object.keys(part); | ||
if (keys.includes('text')) { | ||
return new InboundMessageBody().setText(part.text); | ||
} | ||
if (keys.includes('ussd')) { | ||
const ussd = new UssdInputMessageBody() | ||
.setStatus(getStatus(part.ussd.status, UssdSessionStatus)) | ||
.setText(new StringValue().setValue(part.ussd.text)); | ||
return new InboundMessageBody().setUssd(ussd); | ||
} | ||
if (keys.includes('media')) { | ||
const mediaObj = new MediaMessageBody() | ||
.setUrl(part.media.url) | ||
.setMedia(getMediaType(part.media.type)); | ||
return new InboundMessageBody().setMedia(mediaObj); | ||
} | ||
if (keys.includes('location')) { | ||
const { | ||
label, | ||
address, | ||
latitude, | ||
longitude, | ||
} = part.location; | ||
const locationObj = new LocationMessageBody() | ||
.setLatitude(latitude) | ||
.setLongitude(longitude) | ||
.setLabel(new StringValue().setValue(label)) | ||
.setAddress(new StringValue().setValue(address)); | ||
return new InboundMessageBody().setLocation(locationObj); | ||
} | ||
if (keys.includes('email')) { | ||
const { email } = part; | ||
const emailObj = new EmailMessageBody() | ||
.setSubject(email.subject) | ||
.setBodyPlain(email.bodyPlain) | ||
.setBodyHtml(email.bodyHtml) | ||
.setCcListList(email.ccList) | ||
.setBccListList(email.bccList); | ||
return new InboundMessageBody().setEmail(emailObj); | ||
} | ||
if (keys.includes('voice')) { | ||
let dialObj; | ||
if (part.voice.dialData) { | ||
const { dialData } = part.voice; | ||
dialObj = new VoiceCallDialInput() | ||
.setDestinationNumber(dialData.destinationNumber) | ||
.setStartedAt(new Timestamp().setSeconds(Math.floor(dialData.startedAt))) | ||
.setDuration(new Duration().setSeconds(Math.floor(dialData.duration))); | ||
} | ||
let queueObj; | ||
if (part.queueData) { | ||
const { queueData } = part.voice; | ||
queueObj = new VoiceCallQueueInput() | ||
.setEnqueuedAt(new Timestamp().setSeconds(Math.floor(queueData.enqueuedAt))) | ||
.setDequeuedAt(new Timestamp().setSeconds(Math.floor(queueData.dequeuedAt))) | ||
.setDequeuedToNumber(new StringValue().setValue(queueData.dequeuedToNumber)) | ||
// eslint-disable-next-line max-len | ||
.setDequeuedToSessionId(new StringValue().setValue(queueData.dequeuedToSessionId)) | ||
.setQueueDuration(new Duration().setSeconds(Math.floor(queueData.duration))); | ||
} | ||
let voiceObj = new VoiceCallInputMessageBody() | ||
// eslint-disable-next-line max-len | ||
.setDirection(getCustomerEventDirection(part.voice.direction, CustomerEventDirection)) | ||
// eslint-disable-next-line max-len | ||
.setStartedAt(new Timestamp().setSeconds(Math.floor(part.voice.startedAt || (Date.now() / 1000)))) | ||
.setDialData(dialObj) | ||
.setQueueData(queueObj); | ||
if (part.voice.status) { | ||
voiceObj = voiceObj.setStatus(getStatus(part.voice.status, VoiceCallStatus)); | ||
} | ||
if (part.voice.hangupCause) { | ||
voiceObj = voiceObj.setHangupCause(getChannelProvider(part.voice.hangupCause, VoiceCallHangupCause, /^VOICE_CALL_HANGUP_CAUSE_/)); | ||
} | ||
if (part.voice.dtmfDigits) { | ||
// eslint-disable-next-line max-len | ||
voiceObj = voiceObj.setDtmlDigits(new StringValue().setValue(part.voice.dtmfDigits)); | ||
} | ||
if (part.voice.recordingUrl) { | ||
// eslint-disable-next-line max-len | ||
voiceObj = voiceObj.setRecordingUrl(new StringValue().setValue(part.voice.recordingUrl)); | ||
} | ||
return new InboundMessageBody().setVoice(voiceObj); | ||
} | ||
throw new Error(`Invalid message part: ${JSON.stringify(part)}`); | ||
}); | ||
const cmd = new ReceiveMessageSimulatorCommand() | ||
@@ -191,3 +76,3 @@ .setCustomerNumber(phoneNumber) | ||
) | ||
.setPartsList(messageParts); | ||
.setPartsList(makeMessageParts(parts)); | ||
@@ -194,0 +79,0 @@ const req = new SimulatorToServerCommand() |
@@ -33,4 +33,6 @@ const { RSocketClient } = require('rsocket-core'); | ||
PaymentChannel, | ||
VoiceCallStatus, | ||
OutboundMessage, | ||
VoiceCallAction, | ||
MessageReaction, | ||
CustomerReminder, | ||
@@ -41,3 +43,2 @@ RejectCallAction, | ||
DequeueCallAction, | ||
MessageReaction, | ||
MessagingChannel, | ||
@@ -47,2 +48,6 @@ TextToSpeechVoice, | ||
RedirectCallAction, | ||
InboundMessageBody, | ||
UssdSessionStatus, | ||
VoiceCallDialInput, | ||
VoiceCallQueueInput, | ||
GetDigitsCallAction, | ||
@@ -54,3 +59,6 @@ OutboundMessageBody, | ||
PaymentCounterParty, | ||
UssdInputMessageBody, | ||
VoiceCallHangupCause, | ||
PaymentChannelNumber, | ||
ChannelNumberProvider, | ||
MessageDeliveryStatus, | ||
@@ -66,2 +74,3 @@ CustomerEventDirection, | ||
PromptMessageMenuItemBody, | ||
VoiceCallInputMessageBody, | ||
PaymentWalletCounterParty, | ||
@@ -145,4 +154,10 @@ MessagingSessionEndReason, | ||
const getChannelNumberProvider = (string) => getChannelProvider(string, ChannelNumberProvider, /^CHANNEL_NUMBER_PROVIDER_/); | ||
const getChannelNumberProviderString = (provider) => getChannelProviderString(provider, ChannelNumberProvider, /^CHANNEL_NUMBER_PROVIDER_/); | ||
const getMessageDeliveryStatusString = (status) => getChannelProviderString(status, MessageDeliveryStatus, /^MESSAGE_DELIVERY_STATUS_/); | ||
const getMessageDeliveryStatus = (string) => getChannelProvider(string, MessageDeliveryStatus, /^MESSAGE_DELIVERY_STATUS_/); | ||
const getCustomerNumberProvider = (string) => getChannelProvider(string, CustomerNumberProvider, /^CUSTOMER_NUMBER_PROVIDER_/); | ||
@@ -161,4 +176,8 @@ | ||
const getMessageSessionEndReason = (string) => getChannelProvider(string, MessagingSessionEndReason, /^MESSAGING_SESSION_END_REASON_/); | ||
const getMessageReactionString = (action) => getChannelProviderString(action, MessageReaction, /^MESSAGE_REACTION_/); | ||
const getMessageReaction = (string) => getChannelProvider(string, MessageReaction, /^MESSAGE_REACTION_/); | ||
const getMediaTypeString = (type) => getChannelProviderString(type, MediaType, /^MEDIA_TYPE_/); | ||
@@ -238,2 +257,9 @@ | ||
const addCashCost = (req, { amount, currencyCode } = {}) => { | ||
const cashObj = new Cash() | ||
.setCurrencyCode(currencyCode) | ||
.setAmount(amount); | ||
return req.setCost(cashObj); | ||
}; | ||
const addPaymentCounterParty = (req, partyOpts, fn) => { | ||
@@ -277,3 +303,3 @@ const party = new PaymentCounterParty(); | ||
new PaymentChannelCounterParty() | ||
.setChannelCode(partyOpts.channelCode) | ||
.setChannelCode(partyOpts.code) | ||
.setChannel( | ||
@@ -511,2 +537,103 @@ getChannelProvider( | ||
const makeMessageParts = (parts = []) => parts.map((part) => { | ||
const keys = Object.keys(part); | ||
if (keys.includes('text')) { | ||
return new InboundMessageBody().setText(part.text); | ||
} | ||
if (keys.includes('ussd')) { | ||
const ussd = new UssdInputMessageBody() | ||
.setStatus(getStatus(part.ussd.status, UssdSessionStatus)) | ||
.setText(new StringValue().setValue(part.ussd.text)); | ||
return new InboundMessageBody().setUssd(ussd); | ||
} | ||
if (keys.includes('media')) { | ||
const mediaObj = new MediaMessageBody() | ||
.setUrl(part.media.url) | ||
.setMedia(getMediaType(part.media.type)); | ||
return new InboundMessageBody().setMedia(mediaObj); | ||
} | ||
if (keys.includes('location')) { | ||
const { | ||
label, | ||
address, | ||
latitude, | ||
longitude, | ||
} = part.location; | ||
const locationObj = new LocationMessageBody() | ||
.setLatitude(latitude) | ||
.setLongitude(longitude) | ||
.setLabel(new StringValue().setValue(label)) | ||
.setAddress(new StringValue().setValue(address)); | ||
return new InboundMessageBody().setLocation(locationObj); | ||
} | ||
if (keys.includes('email')) { | ||
const { email } = part; | ||
const emailObj = new EmailMessageBody() | ||
.setSubject(email.subject) | ||
.setBodyPlain(email.bodyPlain) | ||
.setBodyHtml(email.bodyHtml) | ||
.setCcListList(email.ccList) | ||
.setBccListList(email.bccList); | ||
return new InboundMessageBody().setEmail(emailObj); | ||
} | ||
if (keys.includes('voice')) { | ||
let dialObj; | ||
if (part.voice.dialData) { | ||
const { dialData } = part.voice; | ||
dialObj = new VoiceCallDialInput() | ||
.setDestinationNumber(dialData.destinationNumber) | ||
.setStartedAt(new Timestamp().setSeconds(Math.floor(dialData.startedAt))) | ||
.setDuration(new Duration().setSeconds(Math.floor(dialData.duration))); | ||
} | ||
let queueObj; | ||
if (part.queueData) { | ||
const { queueData } = part.voice; | ||
queueObj = new VoiceCallQueueInput() | ||
.setEnqueuedAt(new Timestamp().setSeconds(Math.floor(queueData.enqueuedAt))) | ||
.setDequeuedAt(new Timestamp().setSeconds(Math.floor(queueData.dequeuedAt))) | ||
.setDequeuedToNumber(new StringValue().setValue(queueData.dequeuedToNumber)) | ||
// eslint-disable-next-line max-len | ||
.setDequeuedToSessionId(new StringValue().setValue(queueData.dequeuedToSessionId)) | ||
.setQueueDuration(new Duration().setSeconds(Math.floor(queueData.duration))); | ||
} | ||
let voiceObj = new VoiceCallInputMessageBody() | ||
// eslint-disable-next-line max-len | ||
.setDirection(getCustomerEventDirection(part.voice.direction, CustomerEventDirection)) | ||
// eslint-disable-next-line max-len | ||
.setStartedAt(new Timestamp().setSeconds(Math.floor(part.voice.startedAt || (Date.now() / 1000)))) | ||
.setDialData(dialObj) | ||
.setQueueData(queueObj); | ||
if (part.voice.status) { | ||
voiceObj = voiceObj.setStatus(getStatus(part.voice.status, VoiceCallStatus)); | ||
} | ||
if (part.voice.hangupCause) { | ||
voiceObj = voiceObj.setHangupCause(getChannelProvider(part.voice.hangupCause, VoiceCallHangupCause, /^VOICE_CALL_HANGUP_CAUSE_/)); | ||
} | ||
if (part.voice.dtmfDigits) { | ||
// eslint-disable-next-line max-len | ||
voiceObj = voiceObj.setDtmlDigits(new StringValue().setValue(part.voice.dtmfDigits)); | ||
} | ||
if (part.voice.recordingUrl) { | ||
// eslint-disable-next-line max-len | ||
voiceObj = voiceObj.setRecordingUrl(new StringValue().setValue(part.voice.recordingUrl)); | ||
} | ||
return new InboundMessageBody().setVoice(voiceObj); | ||
} | ||
throw new Error(`Invalid message part: ${JSON.stringify(part)}`); | ||
}); | ||
const makeConnectionHandlerName = (kind) => { | ||
@@ -704,6 +831,7 @@ const name = kind.toLowerCase().replace(/_/, ''); | ||
getStatus, | ||
addMessage, | ||
addIndices, | ||
addReminder, | ||
addMessage, | ||
addCustomer, | ||
addCashCost, | ||
addCashValue, | ||
@@ -713,2 +841,3 @@ getMediaType, | ||
getStatusString, | ||
makeMessageParts, | ||
addOtherCustomer, | ||
@@ -719,10 +848,15 @@ addCustomerNumber, | ||
getMediaTypeString, | ||
getMessageReaction, | ||
addVoiceCallActions, | ||
addPaymentCounterParty, | ||
getValidCollectionKeys, | ||
addPaymentCounterParty, | ||
getMessageReactionString, | ||
getMessageDeliveryStatus, | ||
getChannelProviderString, | ||
getChannelNumberProvider, | ||
getCustomerEventDirection, | ||
getMessageSessionEndReason, | ||
getMessageConsentUpdateAction, | ||
getMessageDeliveryStatusString, | ||
getChannelNumberProviderString, | ||
getCustomerNumberProviderString, | ||
@@ -729,0 +863,0 @@ getCustomerEventDirectionString, |
@@ -1474,5 +1474,6 @@ // source: common_model.proto | ||
CUSTOMER_REQUEST_ORIGIN_API_REQUEST: 1, | ||
CUSTOMER_REQUEST_ORIGIN_CUSTOMER_TAG: 2 | ||
CUSTOMER_REQUEST_ORIGIN_CUSTOMER_TAG: 2, | ||
CUSTOMER_REQUEST_ORIGIN_REPLAY: 3 | ||
}; | ||
goog.object.extend(exports, proto.com.elarian.hera.proto); |
@@ -443,2 +443,46 @@ /* eslint-disable max-len */ | ||
/** | ||
* Replay recieved message | ||
* @typedef {Object} ReceivedMessage | ||
* @property {string} sessionId | ||
* @property {string} messageId | ||
* @property {number} receivedAt timestamp in seconds e.g 1615361861 | ||
* @property {InboundMessageBody[]} parts | ||
* @property {string} inReplyTo | ||
* @property {Cash} cost | ||
* @property {string} provider one of [at, twilio, mailgun, facebook, telegram] | ||
*/ | ||
/** | ||
* Replay sent message | ||
* @typedef {Object} SentMessage | ||
* @property {string} sessionId | ||
* @property {string} messageId | ||
* @property {number} sentAt timestamp in seconds e.g 1615361861 | ||
* @property {Message} message | ||
* @property {string} inReplyTo | ||
* @property {Cash} cost | ||
* @property {string} status 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, insufficient_credits, application_error] | ||
* @property {string} provider one of [at, twilio, mailgun, facebook, telegram] | ||
*/ | ||
/** | ||
* Replay message status update | ||
* @typedef {Object} MessageStatusUpdate | ||
* @property {string} messageId | ||
* @property {number} updatedAt timestamp in seconds e.g 1615361861 | ||
* @property {Cash} cost | ||
* @property {string} status 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, insufficient_credits, application_error] | ||
*/ | ||
/** | ||
* Replay message session update | ||
* @typedef {Object} MessageSessionUpdate | ||
* @property {string} sessionId | ||
* @property {number} startedAt timestamp in seconds e.g 1615361861 | ||
* @property {number} duration in seconds e.g. 67 | ||
* @property {Cash} cost | ||
* @property {string} reason one of [normal_clearing, inactivity, failure] | ||
*/ | ||
/** | ||
* An string representing an event. Must be one of: | ||
@@ -492,3 +536,3 @@ * <ul> | ||
* An object representing a message body | ||
* @typedef {Object} SimulatorMessageBody | ||
* @typedef {Object} InboundMessageBody | ||
* @property {string} [text] | ||
@@ -552,4 +596,6 @@ * @property {Media} [media] | ||
* @property {string} account | ||
* @property {NetworkCode} channelCode The telco's network code. | ||
* @property {PaymentChannelNumber} channelNumber | ||
* @property {string} source | ||
* @property {string} destination | ||
* @property {string} channel one of [cellular, airtime] | ||
* @property {NetworkCode} code The telco's network code. | ||
*/ | ||
@@ -556,0 +602,0 @@ |
{ | ||
"name": "elarian", | ||
"version": "0.2.18", | ||
"version": "0.2.19", | ||
"description": "Elarian JavaScript SDK", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -167,3 +167,3 @@ /** | ||
*/ | ||
receiveMessage(phoneNumber: string, channelNumber: MessagingChannelNumber, sessionId: string, parts: SimulatorMessageBody[], cost: Cash): void; | ||
receiveMessage(phoneNumber: string, channelNumber: MessagingChannelNumber, sessionId: string, parts: InboundMessageBody[], cost: Cash): void; | ||
/** | ||
@@ -654,3 +654,3 @@ * <p>Initiate payment request</p> | ||
*/ | ||
type SimulatorMessageBody = { | ||
type InboundMessageBody = { | ||
text?: string; | ||
@@ -657,0 +657,0 @@ media?: Media; |
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
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 too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10342393
176012