Skip to content
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.

api.sendMessage with mentions no longer working #507

Closed
ghost opened this issue Aug 3, 2017 · 8 comments
Closed

api.sendMessage with mentions no longer working #507

ghost opened this issue Aug 3, 2017 · 8 comments

Comments

@ghost
Copy link

ghost commented Aug 3, 2017

Some time within the last 2 days this function broke, and the API gets HTTP error 500, followed by error 404 when trying to send this message. Attached below is the GitHub sample code in the documentation.

const login = require("facebook-chat-api");

login({email: "EMAIL", password: "PASSWORD"}, (err, api) => {
    if(err) return console.error(err);

    api.listen((err, message) => {
        if (message && message.body) {
            // Getting the actual sender name from ID involves calling
            // `api.getThreadInfo` and `api.getUserInfo`
            api.sendMessage({
                body: 'Hello @Sender! @Sender!',
                mentions: [{
                     tag: '@Sender',
                     id: message.senderID,
                     fromIndex: 9, // Highlight the second occurrence of @Sender
                }],
            }, message.threadID);
        }
    });
});
@Schmavery
Copy link
Owner

Schmavery commented Aug 3, 2017

Seems like we might be missing a new field "profile_xmd[i][type]". In my tests so far it's always been equal to 'p'. Do you want to try adding this line and seeing in it helps?
https://github.com/Schmavery/facebook-chat-api/blob/master/src/sendMessage.js#L262-L264

I.e. in sendMessage, instead of

form['profile_xmd[' + i + '][offset]'] = offset;
form['profile_xmd[' + i + '][length]'] = tag.length;
form['profile_xmd[' + i + '][id]'] = id;

we would have

form['profile_xmd[' + i + '][offset]'] = offset;
form['profile_xmd[' + i + '][length]'] = tag.length;
form['profile_xmd[' + i + '][id]'] = id;
form['profile_xmd[' + i + '][type]'] = 'p';

image

@ghost
Copy link
Author

ghost commented Aug 4, 2017

Can confirm that this solves the issue for me.

@Schmavery
Copy link
Owner

Awesome! Any chance you want to submit a PR with that change? :)

@ghost ghost closed this as completed Aug 6, 2017
@Schmavery
Copy link
Owner

Thanks again @7222-SIMON 😄

@kentnek
Copy link

kentnek commented Mar 24, 2018

UPDATE: oh I realized that the version I pulled from NPM is too old, which does not include the fix above.

Hi, this has stopped working again, although there's no error. 😢

Below's the recorded form data, I don't see any difference from the one above though.

client: mercury
action_type: ma-type:user-generated-message
body: @Kent Nguyen hello
ephemeral_ttl_mode: 0
has_attachment: false
message_id: 6383308091057059549
offline_threading_id: 6383308091057059549
source: source:messenger:web
thread_fbid: 1882350935122661
timestamp: 1521899245037
profile_xmd[0][id]: 1373104146
profile_xmd[0][offset]: 0
profile_xmd[0][length]: 12
profile_xmd[0][type]: p
__user: 100008177914293
__a: 1
__dyn: 5V4cjJLyGmaWxd2u6W85k2m2WWAKGgS8zXrWo466ES2N6wAxu13wFGEa8Gm4UJi28rxuF98ScDKuEjKewzAxaag4idxK4ohyVeFFUkxu9x2UOESi5U5aayrgS2m4oqyUfe5FHxu9gqxKVUlF3Ey5ESq68G2ut5wIwpUCu4rGUpCwCGm8xC784a5olyoK7Uy5uazoK13x1yUPz_xe8hohxOU8E-8HgoV8O9wAhVrz8y2qczp4iaxa9AjxCfAxqa_xicCwzx-bw
__req: i
__be: -1
__pc: PHASED:messengerdotcom_pkg
__rev: 3752809
fb_dtsg: AQEjhv5giZAC:AQH1GLUOIgcO
jazoest: 265816910610411853103105906567586581724971768579731039979

@23phy
Copy link

23phy commented Mar 24, 2018

switch (message.body) {
    case 'mention': {
        api.sendMessage({
            body: 'This is @you, and this is @me',
            mentions:
                [{
                    tag: '@you',
                    id: message.senderID,
                },
	        {
	            tag: '@me',
                    id: api.getCurrentUserID()
	        }],
        }, message.threadID);
    }
}

This works with the lastest Schmavery/facebook-chat-api
image

@shellmage
Copy link

@kentnek there seems to be a bug when tag is at offset 0
check issue #857 , I created a new PR for it #858.

@kentnek
Copy link

kentnek commented Jan 3, 2021

@shellcxd3 thanks! but I actually stopped using this library altogether as it seemed to cause my accounts to be flagged and banned by Facebook...

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants