You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.1 KiB
JavaScript
112 lines
3.1 KiB
JavaScript
1 year ago
|
export const sentMsgTypeMapped = {
|
||
|
text: {
|
||
|
type: 'text',
|
||
|
contentToSend: (msg) => ({ type: 'text', from: '+8617607730395', to: '', text: { body: msg.text } }),
|
||
|
contentToRender: (msg) => ({...msg}),
|
||
|
},
|
||
|
whatsappTemplate: {
|
||
|
type: 'template',
|
||
|
contentToSend: (msg) => ({
|
||
|
template: {
|
||
|
namespace: msg.whatsappTemplate.namespace,
|
||
|
language: msg.whatsappTemplate.language,
|
||
|
type: msg.whatsappTemplate.type,
|
||
|
components: msg.whatsappTemplate.components,
|
||
|
},
|
||
|
}),
|
||
|
},
|
||
|
};
|
||
|
export const whatsappMsgMapped = {
|
||
|
'whatsapp.inbound_message.received': {
|
||
|
getMsg: (result) => {
|
||
|
console.log('whatsapp.inbound_message.received', result);
|
||
|
return result?.whatsappInboundMessage || null;
|
||
|
},
|
||
|
contentToRender: (result) => {
|
||
|
console.log( 'whatsapp.inbound_message.received', result);
|
||
|
const contentObj = result?.whatsappInboundMessage || result; // debug:
|
||
|
return parseRenderMessageItem(contentObj);
|
||
|
},
|
||
|
},
|
||
|
};
|
||
|
export const whatsappMsgTypeMapped = {
|
||
|
text: { type: 'text', data: (msg) => ({ text: msg.text.body }) },
|
||
|
image: {
|
||
|
type: 'photo',
|
||
|
data: (msg) => ({
|
||
|
data: {
|
||
|
uri: msg.image.link,
|
||
|
width: 200,
|
||
|
height: 200,
|
||
|
alt: '',
|
||
|
},
|
||
|
onOpen: () => {
|
||
|
console.log('Open image', msg.image.link);
|
||
|
},
|
||
|
}),
|
||
|
},
|
||
|
sticker: {
|
||
|
type: 'photo',
|
||
|
data: (msg) => ({
|
||
|
data: {
|
||
|
uri: msg.sticker.link,
|
||
|
width: 150,
|
||
|
height: 120,
|
||
|
alt: '',
|
||
|
},
|
||
|
}),
|
||
|
},
|
||
|
video: {
|
||
|
type: 'video',
|
||
|
data: (msg) => ({
|
||
|
data: {
|
||
|
videoURL: msg.video.link,
|
||
|
status: {
|
||
|
click: true,
|
||
|
loading: 0,
|
||
|
download: true,
|
||
|
},
|
||
|
},
|
||
|
}),
|
||
|
},
|
||
|
audio: {
|
||
|
type: 'audio',
|
||
|
data: (msg) => ({
|
||
|
data: {
|
||
|
audioURL: msg.audio.link,
|
||
|
},
|
||
|
}),
|
||
|
},
|
||
|
'unsupported': { type: 'system', data: (msg) => ({ text: 'Message type is currently not supported.' }) },
|
||
|
// 'unsupported': { type: 'text', data: (msg) => ({ text: 'Message type is currently not supported.' }) }
|
||
|
// file: 'file',
|
||
|
// location: 'location',
|
||
|
// contact: 'contact',
|
||
|
// 'contact-card': 'contact-card',
|
||
|
// 'contact-card-with-photo': 'contact-card-with-photo',
|
||
|
// 'contact-card-with-photo-and-label': 'contact-card-with-photo-and-label',
|
||
|
};
|
||
|
export const parseRenderMessageItem = (msg) => {
|
||
|
console.log(msg, '[[[[');
|
||
|
return {
|
||
|
...(whatsappMsgTypeMapped?.[msg.type]?.data(msg) || {}),
|
||
|
id: msg.id,
|
||
|
sender: msg.from,
|
||
|
type: whatsappMsgTypeMapped?.[msg.type]?.type || 'text',
|
||
|
// title: msg.customerProfile.name,
|
||
|
date: msg.sendTime,
|
||
|
};
|
||
|
};
|
||
|
export const parseRenderMessageList = (messages) => {
|
||
|
return messages.map((msg) => {
|
||
|
return {
|
||
|
...(whatsappMsgTypeMapped?.[msg.type]?.data(msg) || {}),
|
||
|
id: msg.id,
|
||
|
sender: msg.from,
|
||
|
type: whatsappMsgTypeMapped?.[msg.type]?.type || 'text',
|
||
|
// title: msg.customerProfile.name,
|
||
|
date: msg.sendTime,
|
||
|
};
|
||
|
});
|
||
|
};
|