diff --git a/src/channel/bubbleMsgUtils.js b/src/channel/bubbleMsgUtils.js index cab1361..2e36da9 100644 --- a/src/channel/bubbleMsgUtils.js +++ b/src/channel/bubbleMsgUtils.js @@ -550,7 +550,7 @@ export const whatsappMsgTypeMapped = { width: 'auto', height: 200, alt: msg.image?.caption || '', - message: msg.image?.caption || '', + message: msg.image?.caption || '[图片]', }), }, sticker: { diff --git a/wai-server/core/handler/whatsappHandler.js b/wai-server/core/handler/whatsappHandler.js index 674cc5c..bb6ecfb 100644 --- a/wai-server/core/handler/whatsappHandler.js +++ b/wai-server/core/handler/whatsappHandler.js @@ -8,7 +8,7 @@ const { sessionStore } = require('..'); const { createWhatsApp } = require('../../core/baileys'); const { updateConnection, addCurrentConnection, resetConnection, getConnection } = require('../../services/connections.service'); const { getOutboundMessage, upsertOutboundMessage } = require('../../services/outbound_messages.service'); -const { objectMapper, pick } = require('../../utils/commons.util'); +const { objectMapper, pick, isEmpty } = require('../../utils/commons.util'); const { logger, getUserLogger } = require('../../utils/logger.util'); const { DbData, waiContentToDB, uploadMediaFile } = require('../../helper/wai.msg.helper'); @@ -50,7 +50,7 @@ const webhookBodyBuilder = (messageData, messageType) => { id: uniqueMsgId(messageData) || messageData.id || generateId(), wamid: messageData.id || '', // direction: directionField[messageType], - status: statusMapped?.[messageData.status] || messageData.status || '', + status: messageData.direction === 'inbound' ? '' : statusMapped?.[messageData.status] || messageData.status || '', externalId: messageData?.externalId || '', }, }; @@ -170,12 +170,12 @@ const setupMessageHandler = () => { upsertFields.evt_id = webhookBody.id; const pusher = { customerProfile_id: waiMessage.customerProfile?.id || '', customerProfile_name: waiMessage.customerProfile?.name || '' }; const record = objectMapper(waiMessage, { from: 'from', to: 'to', status: 'msg_status', type: 'msgtype' }, false); - const waiContentFieldsToDB = waiContentToDB(messageData); - if (['image', 'sticker', 'audio', 'video', 'document'].includes(waiMessage.type)) { + const waiContentFieldsToDB = messageData.type ? waiContentToDB(messageData) : {}; + if (isEmpty(savedMsg.IVADS_link) && ['image', 'sticker', 'audio', 'video', 'document'].includes(waiMessage.type)) { // 存储文件 const filePath = messageData[messageData.type].filePath; const webLink = await uploadMediaFile(filePath); - waiContentFieldsToDB.link = webLink; + waiContentFieldsToDB.IVADS_link = webLink; } const msgRow = await upsertOutboundMessage( diff --git a/wai-server/helper/wai.msg.helper.js b/wai-server/helper/wai.msg.helper.js index 2a33152..3548913 100644 --- a/wai-server/helper/wai.msg.helper.js +++ b/wai-server/helper/wai.msg.helper.js @@ -62,7 +62,7 @@ const mediaMsg = { filename: row.IVADS_filename, }, type: row.msgtype, - ...(row.context_id ? { context: { message_id: row.context_id, from: row.context_from } } : {}), + ...(row.context_id ? { context: { id: row.context_id, from: row.context_from } } : {}), }), }; @@ -103,7 +103,7 @@ const waiMsgTypeMapped = { DbData: row => ({ type: 'text', text: { body: row.text_body, preview_url: row.text_preview_url }, - ...(row.context_id ? { context: { message_id: row.context_id, from: row.context_from } } : {}), + ...(row.context_id ? { context: { id: row.context_id, from: row.context_from } } : {}), }), }, image: {