forked from Schmavery/facebook-chat-api
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Schmavery#435 from GAMELASTER/feature-forward
Attachment forwarding
- Loading branch information
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"use strict"; | ||
|
||
var utils = require("../utils"); | ||
var log = require("npmlog"); | ||
|
||
module.exports = function(defaultFuncs, api, ctx) { | ||
return function forwardAttachment(attachmentID, userOrUsers, callback) { | ||
if (!callback) { | ||
callback = function() {}; | ||
} | ||
|
||
var form = { | ||
attachment_id: attachmentID, | ||
}; | ||
|
||
if(utils.getType(userOrUsers) !== "Array") { | ||
userOrUsers = [userOrUsers]; | ||
} | ||
|
||
var timestamp = Math.floor(Date.now() / 1000); | ||
|
||
for (var i = 0; i < userOrUsers.length; i++) { | ||
//That's good, the key of the array is really timestmap in seconds + index | ||
//Probably time when the attachment will be sent? | ||
form['recipient_map[' + (timestamp + i) + ']'] = userOrUsers[i]; | ||
} | ||
|
||
defaultFuncs | ||
.post("https://www.messenger.com/mercury/attachments/forward/", ctx.jar, form) | ||
.then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs)) | ||
.then(function(resData) { | ||
if (resData.error) { | ||
throw resData; | ||
} | ||
|
||
return callback(null); | ||
***REMOVED*** | ||
.catch(function(err) { | ||
log.error("forwardAttachment", err); | ||
return callback(err); | ||
***REMOVED***; | ||
}; | ||
}; |