-
Notifications
You must be signed in to change notification settings - Fork 598
Conversation
I am getting the same error |
Yeah getting the same error as you |
OK so I got it to work by changing doc_id to what was in the request, it is not the same as the thread id, but i am not sure what it is Edit: it seems doc_id is always 1491398900900362 after trying multiple accounts talking to different people and in groups/pms |
And it seems you cannot use emojis other than the default ones :( |
I can't test it right now, but is there any way to remove reactions? |
@ravkr I don't know, probably yes, but don't know how request looks |
To remove a reaction you just need to replace "ADD_REACTION" with "REMOVE_REACTION" Edit: Although the request has the emoji that you want to remove, you can actually just use any string and it will still successfully remove the reaction. |
@mangotec Thank you! I will implement that! |
Great to see this collaboration! Let me know when it's ready to merge :) |
@gamelaster you could use git rebase instead of merging from master, it just looks cleaner :D |
@ravkr yeah,I like rebase more than merging, but I don't know why, it's merged instead of rebase/fast-forward :D |
you can try this next time 😄
|
Okay, I got the reactions update! Let's go finish it 😊 @ravkr ahh yeah, I used |
It's ready! |
src/setMessageReaction.js
Outdated
var utils = require("../utils"); | ||
var log = require("npmlog"); | ||
|
||
var clientMutationId = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes me nervous. Can you store this in the ctx object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/addReaction.js
Outdated
@@ -0,0 +1,45 @@ | |||
"use strict"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you intend to include this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you are right! Fixed
Oyy, I again merged instead of rebase! 😆 All reviews has been solved! |
|
||
var variables = { | ||
data: { | ||
client_mutation_id: ctx.clientMutationId++, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will give NaN if ctx.clientMutationId is not initialized to a number.
You can fix that here: https://github.com/Schmavery/facebook-chat-api/blob/master/index.js#L58
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ok, sorry I must have missed that.
utils.js
Outdated
@@ -375,7 +375,8 @@ function formatDeltaMessage(m){ | |||
messageID: md.messageId, | |||
attachments: (m.delta.attachments || []).map(v => _formatAttachment(v)), | |||
timestamp: md.timestamp, | |||
isGroup: !!md.threadKey.threadFbId | |||
isGroup: !!md.threadKey.threadFbId, | |||
reactions: originalMessage.reactions ? originalMessage.reactions : [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I going crazy or is originalMessage not defined here? Can you make sure to test this change? deltaMessage can have slightly different behaviour than the other one (unless you're not getting delta messages?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, when I thinking about this, the reactions in deltaMessage is not required because all reactions sync going through ClientPayload
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't understand. Can you explain more? Does delta message not have info about reactions?
Mhh... because it sends the delta message right away, so no one could have reacted to it yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know, Delta message doesn't have info about reactions. But, the information about reaction is still in /pull/
request, but marked as ClientPayload
. So first you get DeltaMessage
and then ClientPayload
contains Message Reaction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think that can work.
if (clientPayload && clientPayload.deltas) { | ||
for (var i in clientPayload.deltas) { | ||
var delta = clientPayload.deltas[i]; | ||
if (delta.deltaMessageReaction) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, just one more thing. Can you explicitly create and return a new object? This will help if facebook changes the format of the object they send us, I believe.
Why do you delete delta.threadKey
and delta.action
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think threadKey
and action
is useless.
And I did that new object.
DOCS.md
Outdated
__Arguments__ | ||
|
||
* `reaction`: A string contains `emoji`, `emoji shortcut`, `emoji in unicode` or left `empty string` for delete reaction (look down for list of supported emojis) | ||
* `messageID`: A string or number representing a thread. It happens to be someone's userId in the case of a one to one conversation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A string or number representing a thread
so... it is threadID or messageID?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! It's a messageID
!
src/listen.js
Outdated
var delta = clientPayload.deltas[i]; | ||
if (delta.deltaMessageReaction) { | ||
delta.deltaMessageReaction.type = "message_reaction"; | ||
delta.threadId = delta.threadKey.threadFbId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i used this code:
var fs = require("fs");
var login = require("facebook-chat-api");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.setOptions({listenEvents: true, logLevel: "silly"});
var stopListening = api.listen((err, event) => {
if(err) return console.error(err);
if (event.type === "message") {
console.log(JSON.stringify(event));
//api.addReaction("👍", event.threadID, event.messageID);
api.setMessageReaction("\uD83D\uDE0D", event.messageID, (err) => {
console.error(err);
})
}
});
});
and I got this error:
verb parseAndCheckLogin for (;;); {"t":"msg","seq":12,"u":100015305950325,"ms":[{"ofd_ts":1490827124159,"delta":{"payload":[123,34,100,101,108,116,97,115,34,58,91,123,34,100,101,108,116,97,77,101,115,115,97,103,101,82,101,97,99,116,105,111,110,34,58,123,34,116,104,114,101,97,100,75,101,121,34,58,123,34,111,116,104,101,114,85,115,101,114,70,98,73,100,34,58,49,48,48,48,48,49,51,51,49,51,56,53,53,55,48,125,44,34,109,101,115,115,97,103,101,73,100,34,58,34,109,105,100,46,36,99,65,65,65,65,66,102,56,100,69,74,100,104,84,88,51,100,89,70,98,72,68,105,87,101,117,88,101,80,34,44,34,97,99,116,105,111,110,34,58,48,44,34,117,115,101,114,73,100,34,58,49,48,48,48,49,53,51,48,53,57,53,48,51,50,53,44,34,114,101,97,99,116,105,111,110,34,58,34,92,117,48,48,102,48,92,117,48,48,57,102,92,117,48,48,57,56,92,117,48,48,56,100,34,44,34,115,101,110,100,101,114,73,100,34,58,49,48,48,48,48,49,51,51,49,51,56,53,53,55,48,44,34,111,102,102,108,105,110,101,84,104,114,101,97,100,105,110,103,73,100,34,58,34,54,50,53,50,57,56,50,49,54,50,51,54,54,55,53,54,55,53,49,34,125,125,93,125],"class":"ClientPayload"},"type":"delta","iseq":283814,"queue":100015305950325}]}
info listen Got answer in 282
ERR! listen TypeError: Cannot read property 'threadFbId' of undefined
ERR! listen at parsePackets (/var/www/node/react/node_modules/facebook-chat-api/src/listen.js:163:55)
ERR! listen at Array.forEach (native)
ERR! listen at /var/www/node/react/node_modules/facebook-chat-api/src/listen.js:107:12
ERR! listen at tryCatcher (/var/www/node/react/node_modules/facebook-chat-api/node_modules/bluebird/js/main/util.js:26:23)
ERR! listen at Promise._settlePromiseFromHandler (/var/www/node/react/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:510:31)
ERR! listen at Promise._settlePromiseAt (/var/www/node/react/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:584:18)
ERR! listen at Promise._settlePromises (/var/www/node/react/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:700:14)
ERR! listen at Async._drainQueue (/var/www/node/react/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:123:16)
ERR! listen at Async._drainQueues (/var/www/node/react/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:133:10)
ERR! listen at Immediate.Async.drainQueues [as _onImmediate] (/var/www/node/react/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:15:14)
ERR! listen at processImmediate [as _immediateCallback] (timers.js:383:17)
ERR! listen [TypeError: Cannot read property 'threadFbId' of undefined]
[TypeError: Cannot read property 'threadFbId' of undefined]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, In my old parsed files, It's contains threadFbId, but today new parsed I have otherUserFbId
too ! Maybe hotfix or something from Facebook side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow 100% but if it seems like a value is sometimes in one place and sometimes in another, please support both 😄
Sometimes people have different versions and it would be great to have the api work for everyone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
src/setMessageReaction.js
Outdated
case ":thumbsdown:": | ||
reaction = "\uD83D\uDC4E"; | ||
default: | ||
return callback({error: "reaction is not valid emoji"}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you forgot to add break
s to cases, now it always calls callback with error.
and maybe "Reaction is not a valid emoji."
instead of "reaction is not valid emoji"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch, thanks @ravkr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, thanks @ravkr !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you've added one break, but it needs a break
after every reaction = ...;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yea, sorry, when I arrive home I will fix that 🤣
Should be okay right now I hope! 😆 |
Work for you @ravkr? |
DOCS.md
Outdated
* 😢 - Unicode: `\uD83D\uDE22`, Shortcut: `:cry:` | ||
* 😠 - Unicode: `\uD83D\uDE20`, Shortcut: `:angry:` | ||
* 👍 - Unicode: `\uD83D\uDC4D`, Shortcut: `:thumbsup:` | ||
* 👎 - Unicode: `\uD83D\uDC4E`, Shortcut: `:thumbsdown:` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, it would be better if reaction names shortcuts were unified with the names of the reactions for Facebook posts, i.e.:
- :love:
- :haha:
- :wow:
- :sad:
- :angery:
- :like:
- :dislike:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ivkos hmm, probably you are right, I just used an "unified" emoji shortcuts. Let's left decide to @Schmavery
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind the unified ones, we could potentially support both. @ivkos do you have a source for these "canonical" facebook reaction names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Schmavery They are not really canonical. It's what they're called in the Facebook UI and how most users know them. Reactions in Messenger don't have visible names in the UI, but most of my friends call them basically with the names of the corresponding reactions in Facebook.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but facebook's :love: is heart, not eyes with hearts... :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okey, I added support for Facebook shortcuts 😊
everything seems to work fine 😄 my test code: var fs = require("fs");
var login = require("facebook-chat-api");
var x = 0;
var reactions = [
"\uD83D\uDE0D",
"\uD83D\uDE06",
"\uD83D\uDE2E",
"\uD83D\uDE22",
"\uD83D\uDE20",
"\uD83D\uDC4D",
"\uD83D\uDC4E",
":heart_eyes:",
":laughing:",
":open_mouth:",
":cry:",
":angry:",
":thumbsup:",
":thumbsdown:"
]
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.setOptions({listenEvents: true, logLevel: "silly"});
var stopListening = api.listen((err, event) => {
if(err) return console.error(err);
if (event.type === "message" && event.body.toLowerCase().indexOf("rav") === 0) {
console.log(JSON.stringify(event));
api.setMessageReaction(reactions[x], event.messageID, (err) => {
console.error(err);
})
console.log(`reaction test #${x}`);
x = (x+1)%reactions.length;
}
});
}); |
src/setMessageReaction.js
Outdated
reaction = "\uD83D\uDE22"; | ||
break; | ||
case ":angry:": | ||
case ":angery:": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was probably typo in suggestion... :/ on facebook it is still angry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it from list which provided me @ivkos, but as I remember, it is angery
, but not sure!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you are right, it's angry
(checked myself too)! Fixed
fa0ee69
to
4b2dc82
Compare
Thanks a lot for this @gamelaster! I appreciate you taking all my little bits of feedback into account and finishing this so quickly! |
* Implementing setMessageReaction function * Adding documentation for setMessageReaction * Adding Facebook emoji shortcuts to setMessageReaction
* Implementing setMessageReaction function * Adding documentation for setMessageReaction * Adding Facebook emoji shortcuts to setMessageReaction
* Implementing setMessageReaction function * Adding documentation for setMessageReaction * Adding Facebook emoji shortcuts to setMessageReaction
ToDo:
@mangotec or @ravkr
Could you test if it works? For me I getting error.