question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Suggestion] Last message doesn't update if last message was sent by the bot in autorespond function

See original GitHub issue

Hello! 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:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
canovecommented, Aug 21, 2020

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.

3reactions
canovecommented, Aug 15, 2020

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 use wbot.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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Facebook Automated Responses in 2023 [Complete Guide]
Facebook automated responses allow businesses to generate automated responses to common queries they receive through the Messages function of ...
Read more >
How to create an auto-responder (and other bots) in Microsoft ...
Click the button below to use our template. Connect Microsoft Teams and choose your auto-responder trigger. Customize the message you want to  ......
Read more >
Auto-reply for WhatsApp: A Guide for 2022 - Verloop.io
Steps To Set-up Auto-reply for WhatsApp:​​ From there, click on Settings, followed by Business Settings, and lastly on Away message. Now, turn on ......
Read more >
Understand and troubleshoot Out of Office (OOF) replies
Discusses how OOF works and some of the main reasons why an OOF reply might not get delivered to users.
Read more >
Set up an SMS Auto-Responder with Twilio Studio
Use Twilio Studio to create an autoresponder to greet incoming SMS or Whatsapp messages with a personalized response.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found