70 lines
2.0 KiB
JavaScript
70 lines
2.0 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.smsHandler = void 0;
|
|
const uuid_1 = require("oak-domain/lib/utils/uuid");
|
|
const sms_1 = require("../sms");
|
|
const smsHandler = async (notification, context) => {
|
|
const { data, data1, id } = notification;
|
|
const [messageSystem] = await context.select('messageSystem', {
|
|
data: {
|
|
id: 1,
|
|
message: {
|
|
id: 1,
|
|
type: 1,
|
|
},
|
|
},
|
|
filter: {
|
|
id: notification.messageSystemId,
|
|
}
|
|
}, { dontCollect: true });
|
|
const { message } = messageSystem;
|
|
const { type } = message;
|
|
try {
|
|
const result = await (0, sms_1.sendSms)({
|
|
messageType: type,
|
|
templateParam: data.params,
|
|
mobile: data1.mobile,
|
|
}, context);
|
|
if (result?.success === true) {
|
|
await context.operate('notification', {
|
|
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
action: 'succeed',
|
|
data: {
|
|
data2: {
|
|
res: result?.res || {}
|
|
}
|
|
},
|
|
filter: {
|
|
id,
|
|
}
|
|
}, { dontCollect: true });
|
|
}
|
|
else {
|
|
await context.operate('notification', {
|
|
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
action: 'fail',
|
|
data: {
|
|
data2: {
|
|
res: result?.res || {}
|
|
}
|
|
},
|
|
filter: {
|
|
id,
|
|
}
|
|
}, { dontCollect: true });
|
|
}
|
|
}
|
|
catch (err) {
|
|
await context.operate('notification', {
|
|
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
action: 'fail',
|
|
data: {},
|
|
filter: {
|
|
id,
|
|
}
|
|
}, { dontCollect: true });
|
|
console.warn('发短信消息失败', err);
|
|
}
|
|
};
|
|
exports.smsHandler = smsHandler;
|