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

dev/supplier-email-drawer
Lei OT 1 year ago
parent ba95206a7e
commit 644c3f4496

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

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

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

Loading…
Cancel
Save