Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom attribute while sending message #272

Open
KKshitiz opened this issue Mar 7, 2024 · 4 comments
Open

Custom attribute while sending message #272

KKshitiz opened this issue Mar 7, 2024 · 4 comments

Comments

@KKshitiz
Copy link

KKshitiz commented Mar 7, 2024

I want to add some custom keys while sending the messages in order to integrate it with some other system. Once the message is created with this custom key, it should reflect in the webhook payload as well.

The sendText function should look like this:

 sendText(request: MessageTextRequest) {
    const options: MessageSendOptions = {
      // It's fine to sent just ids instead of Contact object
      mentions: (request.mentions as unknown) as string[],
      extra: {
        my_custom_key: 'some-value',
      },
    };
    return this.whatsapp.sendMessage(
      this.ensureSuffix(request.chatId),
      request.text,
      options,
    );
  }

I checked the MessageSendOptions type in the WAWebJS library and it seems to have an extra param, but it doesn't work:

  /** Options for sending a message */
    export interface MessageSendOptions {
        /** Other keys */
        /** Extra options */
        extra?: any
        /** Other keys */
    }

patron:ADVANCED

@devlikepro devlikepro added enhancement New feature or request engine:WEBJS labels Mar 7, 2024
@devlikepro
Copy link
Contributor

devlikepro commented Mar 7, 2024

Let me check if it works the way you described and WhatsApp sends the extra back to us - in that case we could add extra field in the payload as well.

Do you think it's safe to use extra with some custom logic? It can looks suspicious from WA side, but it's up to you.

patron:PRO

@KKshitiz
Copy link
Author

KKshitiz commented Mar 7, 2024

Sure, thanks a lot. Here's the related PR: pedroslopez/whatsapp-web.js#600

Since it's supported by the Whatsapp web library itself, it shouldn't be a security concern. Let me know what do you think.

Also, I'd be more than happy to work on this if you can guide me a bit.

@allburov
Copy link
Contributor

allburov commented May 4, 2024

It doesn't' work - no my_custom_key gets back in the payload (likely WhatsApp start to cleanup the payload on WhatsApp Web before encrypting it)

patron:PRO

@allburov
Copy link
Contributor

allburov commented May 4, 2024

It's possible to do it this way tho

      extra: {
        quotedMsg: {
          my_custom_key: 'some-value',
        },
      },

in that case we get back it in _data

                "quotedMsg": {
                    "my_custom_key": "some-value"
                },

But I'm not sure about "blocking" concerns - changing payload can be detected by end clients pretty easily

I wouldn't suggest to use that feature and stick to original one only, but if you 100% wish to do that - we can do that!
With that you'll be able to also add self: "in" in that payload to detect messages from the app (not from other sources) #304
I'd strongly recommend using extral database for that tho, but it's up to you, we can add it on our side, not a problem!

patron:PRO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants