|
|
|
@ -36,6 +36,7 @@ const webhookBodyBuilder = (messageData, messageType) => {
|
|
|
|
|
createTime: new Date(new Date().getTime() + 8 * 60 * 60 * 1000).toISOString(), // GMT +8
|
|
|
|
|
domainName,
|
|
|
|
|
conversationid: messageData?.externalId || '',
|
|
|
|
|
whatsAppNo: messageData?.whatsAppNo || '',
|
|
|
|
|
waiMessage: {
|
|
|
|
|
...messageData,
|
|
|
|
|
...(messageData.updateTime ? { [timeField[messageData.status]]: messageData.updateTime } : {}),
|
|
|
|
@ -87,6 +88,8 @@ const setupConnectionHandler = () => {
|
|
|
|
|
},
|
|
|
|
|
{ connect_domain: domain, connect_name: domainName },
|
|
|
|
|
);
|
|
|
|
|
const webhookBody = webhookBodyBuilder({ ...connectionData, connection: 'open' }, 'creds:update');
|
|
|
|
|
await callWebhook(webhookBody);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
logger.error({ connectionData, error }, 'error add connection');
|
|
|
|
|
}
|
|
|
|
@ -104,6 +107,8 @@ const setupConnectionHandler = () => {
|
|
|
|
|
{ connect_domain: domain, connect_name: domainName, channel_id: connectionData.channelId },
|
|
|
|
|
);
|
|
|
|
|
// todo: 通知前端: 重新扫码
|
|
|
|
|
const webhookBody = webhookBodyBuilder({ ...connectionData, connection: 'offline' }, 'creds:update');
|
|
|
|
|
await callWebhook(webhookBody);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
logger.error({ connectionData, error }, 'error add connection');
|
|
|
|
|
}
|
|
|
|
@ -118,7 +123,7 @@ const setupCredsHandler = () => {
|
|
|
|
|
whatsappEvents.on('creds:update', async creds => {
|
|
|
|
|
logger.info('creds:update', creds);
|
|
|
|
|
try {
|
|
|
|
|
const webhookBody = webhookBodyBuilder({ ...creds }, eventName);
|
|
|
|
|
const webhookBody = webhookBodyBuilder({ ...creds, connection: '' }, 'creds:update');
|
|
|
|
|
await callWebhook(webhookBody);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
logger.error({ creds, error }, 'error update creds');
|
|
|
|
|