Answer a message on the session it arrived on
This commit is contained in:
+7
-5
@@ -89,9 +89,9 @@ export function createSms(input: SmsInput, handlers: SmsHandlers): Sms {
|
||||
from: input.from,
|
||||
message: input.message,
|
||||
pduObjs: input.pduObjs,
|
||||
sendDlr: status => sendDlr(sms, handlers, status),
|
||||
sendDlr: status => sendDlr(sms, input.session, handlers, status),
|
||||
sendResp: options => (input.answeredAs === undefined
|
||||
? sendResp(sms, answered, options ?? {}, handlers)
|
||||
? sendResp(sms, input.session, answered, options ?? {}, handlers)
|
||||
: answeredOnArrival(options ?? {}, handlers)),
|
||||
session: input.session,
|
||||
get smsId(): string {
|
||||
@@ -128,6 +128,7 @@ function answeredOnArrival(
|
||||
|
||||
async function sendResp(
|
||||
sms: Sms,
|
||||
session: Session,
|
||||
answered: { smsId: string },
|
||||
options: SendRespOptions,
|
||||
handlers: Pick<SmsHandlers, 'lostLink' | 'onAnswered'>,
|
||||
@@ -149,7 +150,7 @@ async function sendResp(
|
||||
return { err: new Error('The link this message arrived on is gone, so nothing would correlate the response') };
|
||||
}
|
||||
|
||||
const results = await Promise.all(sms.pduObjs.map((pduObj, index) => sms.session.sendReturn(
|
||||
const results = await Promise.all(sms.pduObjs.map((pduObj, index) => session.sendReturn(
|
||||
pduObj,
|
||||
options.status ?? 'ESME_ROK',
|
||||
respIdParams(pduObj.cmdName, segmentId(answered.smsId, index, total)),
|
||||
@@ -210,10 +211,11 @@ function collectReceipt(sent: Result<{ pduObj: PduObject }>[]): SendDlrResult {
|
||||
|
||||
async function sendDlr(
|
||||
sms: Sms,
|
||||
session: Session,
|
||||
handlers: Pick<SmsHandlers, 'send'>,
|
||||
status: MessageState = 'DELIVERED',
|
||||
): Promise<SendDlrResult> {
|
||||
if (!sms.session.bindAllows('deliver_sm')) {
|
||||
if (!session.bindAllows('deliver_sm')) {
|
||||
return {
|
||||
err: new Error('A transmitter-bound session does not carry deliver_sm'),
|
||||
pduObjs: [],
|
||||
@@ -236,7 +238,7 @@ async function sendDlr(
|
||||
short_message: receiptText(sms, smsId, status),
|
||||
source_addr: sms.to,
|
||||
},
|
||||
...(sms.session.acceptsOptionalParams() ? { tlvs: receiptTlvs(smsId, status) } : {}),
|
||||
...(session.acceptsOptionalParams() ? { tlvs: receiptTlvs(smsId, status) } : {}),
|
||||
});
|
||||
}));
|
||||
return collectReceipt(sent);
|
||||
|
||||
Reference in New Issue
Block a user