From 8757d5df542b942f8c06447114ddacd18fd793a5 Mon Sep 17 00:00:00 2001 From: Lei OT Date: Thu, 7 Mar 2024 14:42:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E8=A7=A3=E6=9E=90=E7=9A=84=E6=B6=88?= =?UTF-8?q?=E6=81=AF,=20=E6=98=BE=E7=A4=BA=E4=B8=BA=E4=B8=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/msgUtils.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/lib/msgUtils.js b/src/lib/msgUtils.js index 89c3ef1..382a45a 100644 --- a/src/lib/msgUtils.js +++ b/src/lib/msgUtils.js @@ -334,7 +334,11 @@ export const whatsappMsgTypeMapped = { }), }, // unsupported: { type: 'system', data: (msg) => ({ text: 'Message type is currently not supported.' }) }, - unsupported: { type: 'text', data: (msg) => ({ text: `[暂不支持此消息类型](${msg.id})` }) }, + unsupported: { + type: 'text', + data: (msg) => ({ id: msg.wamid, text: `[暂不支持此消息类型](${msg.wamid})` }), + renderForReply: (msg) => ({ id: msg.wamid, text: `[Message type unsupported](${msg.wamid})` }), + }, reaction: { type: 'text', data: (msg) => ({ id: msg.wamid, text: msg.reaction?.emoji || '' }), @@ -359,8 +363,8 @@ export const whatsappMsgTypeMapped = { id: msg.wamid, meetingID: msg.wamid, title: msg.contacts.length === 1 ? `联系人` : `${msg.contacts.length} 位联系人`, - text: msg.contacts.map(ele => `${ele.name.formatted_name}: ${ele.phones[0].wa_id}`).join('\n'), - data: msg.contacts.map(ele => ({ id: ele.phones[0].wa_id, wa_id: ele.phones[0].wa_id, name: ele.name.formatted_name })), + text: msg.contacts.map((ele) => `${ele.name.formatted_name}: ${ele.phones[0].wa_id}`).join('\n'), + data: msg.contacts.map((ele) => ({ id: ele.phones[0].wa_id, wa_id: ele.phones[0].wa_id, name: ele.name.formatted_name })), }), }, location: { @@ -398,13 +402,14 @@ export const whatsappMsgTypeMapped = { */ export const parseRenderMessageItem = (msg) => { console.log('parseRenderMessageItem', msg); + const thisMsgType = Object.keys(receivedMsgTypeMapped).incluses(msg.type) ? msg.type : 'unsupported'; return { msgOrigin: msg, date: msg?.sendTime || msg?.createTime || '', - ...(whatsappMsgTypeMapped?.[msg.type]?.data(msg) || {}), + ...(whatsappMsgTypeMapped?.[thisMsgType]?.data(msg) || {}), conversationid: msg.conversationid, - ...(typeof whatsappMsgTypeMapped[msg.type].type === 'function' ? whatsappMsgTypeMapped[msg.type].type(msg) : { type: whatsappMsgTypeMapped[msg.type].type || 'text' }), - // type: whatsappMsgTypeMapped?.[msg.type]?.type || 'text', + ...(typeof whatsappMsgTypeMapped[thisMsgType].type === 'function' ? whatsappMsgTypeMapped[thisMsgType].type(msg) : { type: whatsappMsgTypeMapped[thisMsgType].type || 'text' }), + // type: whatsappMsgTypeMapped?.[thisMsgType]?.type || 'text', from: msg.from, sender: msg.from, senderName: msg?.customerProfile?.name || msg.from, @@ -421,8 +426,8 @@ export const parseRenderMessageItem = (msg) => { * reply: { message: msg.messageorigin, title: 'React from', titleColor: '#1ba784' } */ title: msg.messageorigin?.customerProfile?.name || 'me', - ...(typeof whatsappMsgTypeMapped[msg?.messageorigin?.type]?.renderForReply === 'function' - ? whatsappMsgTypeMapped[msg.messageorigin.type].renderForReply(msg.messageorigin) + ...(typeof whatsappMsgTypeMapped[(msg?.messageorigin?.type || 'unsupported')]?.renderForReply === 'function' + ? whatsappMsgTypeMapped[(msg?.messageorigin?.type || 'unsupported')].renderForReply(msg.messageorigin) : {}), titleColor: msg.messageorigin?.customerProfile?.name ? '#a791ff' : "#128c7e", },