feat: Send buttons and Lists (#756)

This commit is contained in:
tuyuribr
2021-09-13 18:06:05 -03:00
committed by GitHub
parent ab415ff9be
commit b60029ed09
10 changed files with 259 additions and 6 deletions

View File

@@ -153,7 +153,47 @@ exports.LoadUtils = () => {
options = { ...options, ...preview };
}
}
let extraOptions = {};
if(options.buttons){
let caption;
if(options.buttons.type === 'chat') {
content = options.buttons.body;
caption = content;
}else{
caption = options.caption ? options.caption : ' '; //Caption can't be empty
}
extraOptions = {
productHeaderImageRejected: false,
isFromTemplate: false,
isDynamicReplyButtonsMsg: true,
title: options.buttons.title ? options.buttons.title : undefined,
footer: options.buttons.footer ? options.buttons.footer : undefined,
dynamicReplyButtons: options.buttons.buttons,
replyButtons: options.buttons.buttons,
caption: caption
};
delete options.buttons;
}
if(options.list){
if(window.Store.Conn.platform === 'smba' || window.Store.Conn.platform === 'smbi'){
throw '[LT01] Whatsapp business can\'t send this yet';
}
extraOptions = {
...extraOptions,
type: 'list',
footer: options.list.footer,
list: {
...options.list,
listType: 1
},
body: options.list.description
};
delete options.list;
delete extraOptions.list.footer;
}
const newMsgId = new window.Store.MsgKey({
fromMe: true,
remote: chat.id,
@@ -175,7 +215,8 @@ exports.LoadUtils = () => {
...locationOptions,
...attOptions,
...quotedMsgOptions,
...vcardOptions
...vcardOptions,
...extraOptions
};
await window.Store.SendMessage.addAndSendMsgToChat(chat, message);
@@ -282,8 +323,11 @@ exports.LoadUtils = () => {
if (msg.buttons) {
msg.buttons = msg.buttons.serialize();
}
if (msg.dynamicReplyButtons) {
msg.dynamicReplyButtons = JSON.parse(JSON.stringify(msg.dynamicReplyButtons));
}
if(msg.replyButtons) {
msg.replyButtons = msg.replyButtons.serialize();
msg.replyButtons = JSON.parse(JSON.stringify(msg.replyButtons));
}
delete msg.pendingAckUpdate;