[Feature Suggestion] Last message doesn't update if last message was sent by the bot in autorespond function
See original GitHub issueHello! Thanks for the hard work into making Whaticket - Ticket System Client for Whatsapp!
I got a issue… i hope its not only me, if it is then sorry. But, when using the Whaticket Backend with Whatsapp-Web.js auto responder functions like:
else if (msg.body == '!ping') {
// Send a new message to the same chat
wbot.sendMessage(msg.from, 'pong');
The last message doesn’t get update on the Frontend Client when the message was sent by the bot in that auto respond function above, the last message only updates if the last message was sent by the team/support agent (typed message).
So if the bot send like 3 auto messages, the last message shown on the Frontend Client its the message before those 3 messages that the bot sent, and not really the last message.
That also happens with any android auto responder whatsapp, just install an auto responder app for whatsapp on the phone and set your bot to reply to your customer, when the bot replies the customer, the team/support agent won’t see the message that the bot has sent.
Example: John Doe send message: " Hi " Bot (whatsapp-web.js library) reply message: " Hey, how you doing " Bot (any android app auto responder for whatsapp) reply message: " Hey, how you doing " Last message shown on the Frontend to the team/support agent = " Hi ". (while it should be " Hey, how you doing ")
My code:
wbot.on("message", async msg => {
// console.log(msg);
if (msg.from === "status@broadcast" || msg.type === "location") {
return;
}
else if (msg.body == '!ping') {
// Send a new message to the same chat
wbot.sendMessage(msg.from, 'pong');
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
Hey @esteves67 , I’ve made some changes in wBotMesasgeListener to handle messages that was not sent from frontend app.
At the time it only works for chat messages (media messages will result in blank messages or big base64 hashes in message body), but for “auto response proposals” it works well.
Let me know if it works for you, so I can close this issue.
Hi, Steeve!
You’re right, the system doesn’t handle messages that not wasn’t sent from frontend.
There are two files in code interacting with Whatsapp-Web.js to send and receive messages:
backend/src/services/wbotMessageListener.js
: listen for received messages, store then in database, update ticket last message and send it with websockets to frontend.backend/src/controllers/MessageController.js
: receive a POST request from frontend, send message with WWebJS, store it in DB, update ticket last message and send it with websockets to frontend.The event
wbot.on("message" ,...)
only listen to other people messages. To handle our own messages (sent directly from cellphone or even with WWebJS), we could usewbot.on("message_create, ...)
, that listen to all messages in chat, including ours. But its no so simples because it will result in duplicate messages and break other things, like file upload.I’m currently working a better way to handle it, and I will address the solution to cover your auto response too.
Thanks for the feedback!