-
Notifications
You must be signed in to change notification settings - Fork 598
Implementing addReaction function #427
Changes from 24 commits
c6957bf
a34c12b
325f16f
6161ed8
99655f7
23c26e6
1ec7ad1
915993f
4a8842a
2211491
bdb9284
9c313ab
8d459e5
7dd583d
d476290
6248686
b74b5e3
7f458e1
d8365fc
158e2ed
a2b54ee
c933951
c55efec
4b2dc82
a2eb5a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
"use strict"; | ||
|
||
var utils = require("../utils"); | ||
var log = require("npmlog"); | ||
|
||
module.exports = function(defaultFuncs, api, ctx) { | ||
return function setMessageReaction(reaction, messageID, callback) { | ||
if(!callback) { | ||
callback = function() {}; | ||
} | ||
|
||
switch (reaction) { | ||
case "\uD83D\uDE0D": //:heart_eyes: | ||
case "\uD83D\uDE06": //:laughing: | ||
case "\uD83D\uDE2E": //:open_mouth: | ||
case "\uD83D\uDE22": //:cry: | ||
case "\uD83D\uDE20": //:angry: | ||
case "\uD83D\uDC4D": //:thumbsup: | ||
case "\uD83D\uDC4E": //:thumbsdown: | ||
case "": | ||
//valid | ||
break; | ||
case ":heart_eyes:": | ||
case ":love:": | ||
reaction = "\uD83D\uDE0D"; | ||
break; | ||
case ":laughing:": | ||
case ":haha:": | ||
reaction = "\uD83D\uDE06"; | ||
break; | ||
case ":open_mouth:": | ||
case ":wow:": | ||
reaction = "\uD83D\uDE2E"; | ||
break; | ||
case ":cry:": | ||
case ":sad:": | ||
reaction = "\uD83D\uDE22"; | ||
break; | ||
case ":angry:": | ||
case ":angery:": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it was probably typo in suggestion... :/ on facebook it is still There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, you are right, it's |
||
reaction = "\uD83D\uDE20"; | ||
break; | ||
case ":thumbsup:": | ||
case ":like:": | ||
reaction = "\uD83D\uDC4D"; | ||
break; | ||
case ":thumbsdown:": | ||
case ":dislike:": | ||
reaction = "\uD83D\uDC4E"; | ||
break; | ||
default: | ||
return callback({error: "Reaction is not a valid emoji."}); | ||
break; | ||
} | ||
|
||
var variables = { | ||
data: { | ||
client_mutation_id: ctx.clientMutationId++, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Oh ok, sorry I must have missed that. |
||
actor_id: ctx.userID, | ||
action: reaction == "" ? "REMOVE_REACTION" : "ADD_REACTION", | ||
message_id: messageID, | ||
reaction: reaction | ||
} | ||
}; | ||
|
||
var qs = { | ||
doc_id: "1491398900900362", | ||
variables: JSON.stringify(variables), | ||
dpr: 1 | ||
}; | ||
|
||
defaultFuncs | ||
.postFormData("https://www.messenger.com/webgraphql/mutation/", ctx.jar, {}, qs) | ||
.then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs)) | ||
.then(function(resData) { | ||
if (!resData) { | ||
throw {error: "addReaction returned empty object."}; | ||
} | ||
if(resData.error) { | ||
throw resData; | ||
} | ||
callback(null); | ||
}) | ||
.catch(function(err) { | ||
log.error("addReaction", err); | ||
return callback(err); | ||
}); | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -397,7 +397,8 @@ function formatMessage(m) { | |
timestampAbsolute: originalMessage.timestamp_absolute, | ||
timestampRelative: originalMessage.timestamp_relative, | ||
timestampDatetime: originalMessage.timestamp_datetime, | ||
tags: originalMessage.tags | ||
tags: originalMessage.tags, | ||
reactions: originalMessage.reactions ? originalMessage.reactions : [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add this to the docs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I searched, the message format is not documented in DOCS There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Added 😊 |
||
}; | ||
|
||
if(m.type === "pages_messaging") obj.pageID = m.realtime_viewer_fbid.toString(); | ||
|
@@ -718,6 +719,13 @@ function formatPresence(presence, userID) { | |
}; | ||
} | ||
|
||
function decodeClientPayload(payload) { | ||
/* | ||
Special function which Client using to "encode" clients JSON payload | ||
*/ | ||
return JSON.parse(String.fromCharCode.apply(null, payload)); | ||
} | ||
|
||
function getAppState(jar){ | ||
return jar | ||
.getCookies("https://www.facebook.com") | ||
|
@@ -756,5 +764,6 @@ module.exports = { | |
generatePresence: generatePresence, | ||
generateAccessiblityCookie: generateAccessiblityCookie, | ||
formatDate: formatDate, | ||
decodeClientPayload: decodeClientPayload, | ||
getAppState: getAppState, | ||
}; |
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
anddelta.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
andaction
is useless.And I did that new object.