发送消息, 同步的结果; 测试服务: externalId为负

dev/supplier-email-drawer
Lei OT 9 months ago
parent ba95206a7e
commit 644c3f4496

@ -9,7 +9,7 @@ function sleep(ms) {
}
exports.sendText = async ctx => {
const { from, to, msgcontent, content: _content } = ctx.request.body;
const { from, to, msgcontent, content: _content, actionId } = ctx.request.body;
const content = _content || msgcontent.body || '';
if (!from || !content) {
ctx.assert(from, 400, 'From and message are required');
@ -23,12 +23,13 @@ exports.sendText = async ctx => {
}
// return wsToSend;
try {
const sockMsg = await wsToSend.sendTextMessage(to, content);
const {
key: { id },
} = sockMsg;
console.log(JSON.stringify(sockMsg, undefined, 2));
await upsertOutboundMessage(null, { ...ctx.request.body, id });
wsToSend.sendTextMessage(to, content, actionId).then(sockMsg => {
const {
key: { id },
} = sockMsg;
upsertOutboundMessage(null, { ...ctx.request.body, id });
});
// const sockMsg = await wsToSend.sendTextMessage(to, content, actionId);
return 'Message sent successfully'; // { wsToSend, ret: 'Message sent successfully' };
} catch (error) {
console.error('Error sending message:', error);

@ -36,6 +36,7 @@ const webhookBodyBuilder = (messageData, messageType) => {
wamid: messageData.id,
direction: directionField[messageType],
// externalId: '-1', // todo:
externalId: `-${messageData.externalId || 1}`, // debug: 测试: 是负值
},
};
return message;
@ -80,7 +81,7 @@ const setupConnectionHandler = () => {
...objectMapper(connectionData, { whatsAppNo: [{ key: 'wa_id' }, { key: 'sesson_id' }], channelId: 'channel_id' }),
service_type: 'baileys',
},
{ connect_domain: domain },
{ connect_domain: domain, connect_name: domainName },
);
// todo: 通知前端: 重新扫码
} catch (error) {
@ -97,10 +98,10 @@ const setupMessageHandler = () => {
try {
const m = await getOutboundMessage({ id: messageData.id });
const webhookBody = webhookBodyBuilder({ ...messageData, actionId: m.actionId, externalId: m.externalId }, eventName);
const webhookBody = webhookBodyBuilder({ actionId: m.actionId || '', externalId: m.externalId || '', ...messageData }, eventName);
const { waiMessage } = webhookBody;
const upsert = await upsertOutboundMessage(m.sn, { ...waiMessage, msg_status: waiMessage.status });
const upsert = await upsertOutboundMessage(m.sn || null, { ...waiMessage, msg_status: waiMessage.status });
// console.log('upsert=========================', upsert);
await callWebhook(webhookBody);
} catch (error) {

@ -14,7 +14,7 @@ const getOutboundMessage = async msg => {
const r = await OutboundModelModel.findOne({
where: msg,
});
return r.toJSON();
return r;
};
/**

Loading…
Cancel
Save