Git Product home page Git Product logo

Comments (7)

canove avatar canove commented on August 27, 2024 4

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.

from whaticket-community.

canove avatar canove commented on August 27, 2024 3

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!

from whaticket-community.

esteves67 avatar esteves67 commented on August 27, 2024 2

Again, thank you for the Whaticket Client! You made a solution for what WPP is taking ages to do (multiple users on a single phone number).

from whaticket-community.

esteves67 avatar esteves67 commented on August 27, 2024 1

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.

Working flawless! Now the chat is returning and showing auto-respond messages sent by my bot to the person who i am attending!

from whaticket-community.

esteves67 avatar esteves67 commented on August 27, 2024

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!

Thank your for the explanation on how the process works, it clarified for me how everything works since im not a experiencied javascript developer 😄

from whaticket-community.

esteves67 avatar esteves67 commented on August 27, 2024

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!

Hello again! 😄

Not the best approach or solution since i started in nodeJS just 1 month ago, but i think it worked for me:

  • tested in localhost and just 1 person sending message to the bot
  • not tested yet in a real "environment" or real situation with more than 1 person sending message at the same time,

How to: Make changes in Message.js like code bellow:
Also use wbot.on("message_create, ...) in the wbotMessageListener.js.

        /** 
         * Indicates if the message was sent by the current user
         * @type {boolean}
         */
        this.fromMe = data.id.fromMe;
        

        /**
         * ID for the Chat that this message was sent to, except if the message was sent by the current user.
         * @type {string}
         */
        if (this.fromMe == true) {
            this.from = (typeof (data.to) === 'object' && data.to !== null) ? data.to._serialized : data.to;
            this.to = (typeof (data.from) === 'object' && data.from !== null) ? data.from._serialized : data.from;
        } else if (this.fromMe == false) {
            this.from = (typeof (data.from) === 'object' && data.from !== null) ? data.from._serialized : data.from;
            this.to = (typeof (data.to) === 'object' && data.to !== null) ? data.to._serialized : data.to;
        }

        /**
         * ID for who this message is for.
         * 
         * If the message is sent by the current user, it will be the Chat to which the message is being sent.
         * If the message is sent by another user, it will be the ID for the current user. 
         * @type {string}
         */

        /**
         * If the message was sent to a group, this field will contain the user that sent the message.
         * @type {string}
         */
        this.author = (typeof (data.author) === 'object' && data.author !== null) ? data.author._serialized : data.author;

from whaticket-community.

canove avatar canove commented on August 27, 2024

Nice job, @esteves67 ! It may work. But I wouldn't change the WWebJS code directly, since all your changes will be lost in case of an update.

I'll keep this issue open, since my plan is to support this feature soon.

from whaticket-community.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.