whatsapp-web.js
whatsapp-web.js copied to clipboard
Can't send media with button
I can't send media with button
I would like to send an image with two buttons below, but nothing happens when I send it.
The expected behavior:
I am creating a button object and passing the media inside options:
const buttons = new WebWhatsButtons(
"",
message.data.buttons.map(v => ({
id: v.postback,
body: v.title
})),
header,
footer
);
const options = {};
options.media = message_media;
options.caption = message.data.body.data.caption;
client.sendMessage(
chat_id._serialized, buttons, options
));
And this is the Message Object:
{
"_data": {
"id": {
"fromMe": true,
"remote": "[email protected]",
"id": "xxxxxxxxxxxxxxxxx",
"self": "out",
"_serialized": "[email protected]_xxxxxxxxxxxxxxxxx_out"
},
"body": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
"type": "image",
"t": 11111111111111,
"from": "[email protected]",
"to": "[email protected]",
"self": "out",
"ack": 0,
"isNewMsg": true,
"star": false,
"kicNotified": false,
"caption": {
"body": "",
"title": "",
"footer": "",
"type": "chat",
"buttons": [{
"index": 0,
"quickReplyButton": {
"displayText": "Sim",
"id": "sim"
}
}, {
"index": 1,
"quickReplyButton": {
"displayText": "Não",
"id": "não"
}
}]
},
"deprecatedMms3Url": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"directPath": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"mimetype": "image/jpeg",
"filehash": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=",
"encFilehash": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=",
"size": 77578,
"mediaKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=",
"mediaKeyTimestamp": 11111111111,
"streamable": false,
"isFromTemplate": false,
"pollInvalidated": false,
"isSentCagPollCreation": false,
"latestEditMsgKey": null,
"latestEditSenderTimestampMs": null,
"mentionedJidList": [],
"isVcardOverMmsDocument": false,
"isForwarded": false,
"hasReaction": false,
"disappearingModeInitiator": "chat",
"productHeaderImageRejected": false,
"lastPlaybackProgress": 0,
"isDynamicReplyButtonsMsg": true,
"dynamicReplyButtons": [{
"buttonId": "sim",
"buttonText": {
"displayText": "Sim"
},
"type": 1
}, {
"buttonId": "não",
"buttonText": {
"displayText": "Não"
},
"type": 1
}],
"isMdHistoryMsg": false,
"stickerSentTs": 0,
"isAvatar": false,
"requiresDirectConnection": null,
"pttForwardedFeaturesEnabled": true
},
"mediaKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=",
"id": {
"fromMe": true,
"remote": "[email protected]",
"id": "xxxxxxxxxxxxxxxxx",
"self": "out",
"_serialized": "[email protected]_xxxxxxxxxxxxxxxxx_out"
},
"ack": 0,
"hasMedia": true,
"body": {
"body": "",
"title": "",
"footer": "",
"type": "chat",
"buttons": [{
"index": 0,
"quickReplyButton": {
"displayText": "Sim",
"id": "sim"
}
}, {
"index": 1,
"quickReplyButton": {
"displayText": "Não",
"id": "não"
}
}]
},
"type": "image",
"timestamp": 1675794833,
"from": "[email protected]",
"to": "[email protected]",
"deviceType": "web",
"isForwarded": false,
"forwardingScore": 0,
"isStarred": false,
"fromMe": true,
"hasQuotedMsg": false,
"vCards": [],
"mentionedIds": [],
"isGif": false,
}
Expected behavior
An image with two buttons
Steps to Reproduce the Bug or Issue
sendMessage with Button + Media as options.media
Relevant Code
No response
Browser Type
Chromium
WhatsApp Account Type
Standard
Does your WhatsApp account have multidevice enabled?
Yes, I am using Multi Device
Environment
Linux, latest branch of list-buttons-fix
Additional context
No response
Same here, guys please help @pedroslopez @PurpShell
sending menu without Messagemedia it works, but it doesn't work when we sent Media along.
Here, it shows One tick, but the message is never sent, the other end don't receive it.
this is JSON object of message sent.
whatsapp-web.js version github:pedroslopez/whatsapp-web.js#fix-buttons-list
latest version, buttons with either text or MessageMedia aren't sent.
@pedroslopez @PurpShell @vendroid12 I tried to put either as Body and as options.media, but it didn't work. I also tried to set this in the Injected.js manually to see if I can get it to work, but it also didn't
@pedroslopez @PurpShell @vendroid12 I tried to put either as Body and as options.media, but it didn't work. I also tried to set this in the Injected.js manually to see if I can get it to work, but it also didn't
@pedroslopez @PurpShell i think there's a problem, because it doesn’t even show any error, i tried to trace it, but in vain. if anyone knows how to fix this, we shall appreciate. thank you. 🙏
@vendroid12 Can you share with me the code you are using to generate that media+button in the image above, please? Mine I couldn't even visualize that
let url = "https://wwebjs.dev/logo.png";
const media = await MessageMedia.fromUrl(url);
media.mimetype = "image/png";
media.filename = hello.png
;
let btnClickableMenu =new Buttons(media, [{id:'customId',body:'button1'},{body:'button2'}]);
this code will produce this, however the buttons are never sent with the Media. but if body was string it works.
code are from this branch
whatsapp-web.js": "github:pedroslopez/whatsapp-web.js#fix-buttons-list
anyone got any solution ?
@rodyrahi take a look at this, it's working for me: https://github.com/pedroslopez/whatsapp-web.js/pull/1636#issuecomment-1418426107
@rodyrahi take a look at this, it's working for me: #1636 (comment)
can you share your code, when you send button with an Image, please
@arnaldobadin Hi, I am unable to send media with buttons.
const b64data_img = fs.readFileSync("file_path", { encoding: 'base64' });
const mimetype_img = mime.getType("filepath");
const filename_img = "image";
var send_img = new MessageMedia(mimetype_img, b64data_img, filename_img);
let optionsButtonMessage = {
useTemplateButtons: true,
buttons: [
{
url: "https://google.com/",
text: "Google Site"
},
{
phoneNumber: "+628888888888",
text: "Call me"
},
{
id: "your custom id 1",
text: "Some text"
},
{
id: "another id 2",
text: "Another text"
}
],
title: "Title text",
footer: "Footer text"
};
const t = await client.pupPage.evaluate(
(to, send_img, options) =>
WPP.chat.sendTextMessage(to, send_img, options),
from,
send_img,
optionsButtonMessage
);
I am getting the error - "Error: Evaluation failed: TypeError: Invalid value at currentMsg.body: value is invalid". Kindly help me.
@rodyrahi take a look at this, it's working for me: #1636 (comment) @vendroid12
This is the code i am using to send media with buttons but its not working and there is no error coming is there a elaborated solution ? Thanks
async function send_photo_button(element, msg , client) {
console.log(" poto_button is send"); const media = MessageMedia.fromFilePath(element["tittle"]);
let button = new Buttons( media, [ { body: element["op1"] }, { body: element["op2"] }, { body: element["op3"] }, ], element["tittle"], element["footer"] ); setlast_question(element["name"]);
client.sendMessage(msg.from, button); }
@arnaldobadin Hi, I am unable to send media with buttons.
const b64data_img = fs.readFileSync("file_path", { encoding: 'base64' }); const mimetype_img = mime.getType("filepath"); const filename_img = "image"; var send_img = new MessageMedia(mimetype_img, b64data_img, filename_img); let optionsButtonMessage = { useTemplateButtons: true, buttons: [ { url: "https://google.com/", text: "Google Site" }, { phoneNumber: "+628888888888", text: "Call me" }, { id: "your custom id 1", text: "Some text" }, { id: "another id 2", text: "Another text" } ], title: "Title text", footer: "Footer text" }; const t = await client.pupPage.evaluate( (to, send_img, options) => WPP.chat.sendTextMessage(to, send_img, options), from, send_img, optionsButtonMessage );
I am getting the error - "Error: Evaluation failed: TypeError: Invalid value at currentMsg.body: value is invalid". Kindly help me.
are you have solution ???
thanks,, its working for me
thanks,, its working for me
can you give me sample code ?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.