|
|
|
@ -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(
|
|
|
|
|