fca-umaruv2 40.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fca-umaruv2 might be problematic. Click here for more details.

Files changed (67) hide show
  1. package/.travis.yml +6 -0
  2. package/CHANGELOG.md +2 -0
  3. package/DOCS.md +1947 -0
  4. package/LICENSE-MIT +21 -0
  5. package/README.md +225 -0
  6. package/index.js +1 -0
  7. package/lib/getInfoNew.js +35 -0
  8. package/lib/getToken.js +44 -0
  9. package/package.json +74 -0
  10. package/src/addExternalModule.js +1 -0
  11. package/src/addUserToGroup.js +1 -0
  12. package/src/changeAdminStatus.js +1 -0
  13. package/src/changeArchivedStatus.js +1 -0
  14. package/src/changeAvatar.js +1 -0
  15. package/src/changeBio.js +1 -0
  16. package/src/changeBlockedStatus.js +1 -0
  17. package/src/changeGroupImage.js +1 -0
  18. package/src/changeNickname.js +1 -0
  19. package/src/changeThreadColor.js +1 -0
  20. package/src/changeThreadEmoji.js +1 -0
  21. package/src/createNewGroup.js +1 -0
  22. package/src/createPoll.js +1 -0
  23. package/src/deleteMessage.js +1 -0
  24. package/src/deleteThread.js +1 -0
  25. package/src/forwardAttachment.js +1 -0
  26. package/src/getAccessToken.js +1 -0
  27. package/src/getCurrentUserID.js +1 -0
  28. package/src/getEmojiUrl.js +1 -0
  29. package/src/getFriendsList.js +1 -0
  30. package/src/getMessage.js +1 -0
  31. package/src/getThreadHistory.js +1 -0
  32. package/src/getThreadInfo.js +1 -0
  33. package/src/getThreadList.js +1 -0
  34. package/src/getThreadPictures.js +1 -0
  35. package/src/getUserID.js +1 -0
  36. package/src/getUserInfo.js +1 -0
  37. package/src/getUserInfoV2.js +1 -0
  38. package/src/handleFriendRequest.js +1 -0
  39. package/src/handleMessageRequest.js +1 -0
  40. package/src/httpGet.js +1 -0
  41. package/src/httpPost.js +1 -0
  42. package/src/httpPostFormData.js +1 -0
  43. package/src/listenMqtt.js +1 -0
  44. package/src/logout.js +1 -0
  45. package/src/markAsDelivered.js +1 -0
  46. package/src/markAsRead.js +1 -0
  47. package/src/markAsReadAll.js +1 -0
  48. package/src/markAsSeen.js +1 -0
  49. package/src/muteThread.js +1 -0
  50. package/src/removeUserFromGroup.js +1 -0
  51. package/src/resolvePhotoUrl.js +1 -0
  52. package/src/searchForThread.js +1 -0
  53. package/src/sendMessage.js +1 -0
  54. package/src/sendTypingIndicator.js +1 -0
  55. package/src/setMessageReaction.js +1 -0
  56. package/src/setPostReaction.js +1 -0
  57. package/src/setTitle.js +1 -0
  58. package/src/threadColors.js +1 -0
  59. package/src/unfriend.js +1 -0
  60. package/src/unsendMessage.js +1 -0
  61. package/src/uploadAttachment.js +1 -0
  62. package/test/data/shareAttach.js +146 -0
  63. package/test/data/test.txt +7 -0
  64. package/test/example-config.json +18 -0
  65. package/test/test-page.js +140 -0
  66. package/test/test.js +387 -0
  67. package/utils.js +1 -0
@@ -0,0 +1 @@
1
+ const e=require("../utils"),t=require("npmlog");function n(e){return{reminderID:e.id,eventCreatorID:e.lightweight_event_creator.id,time:e.time,eventType:e.lightweight_event_type.toLowerCase(),locationName:e.location_name,locationCoordinates:e.location_coordinates,locationPage:e.location_page,eventStatus:e.lightweight_event_status.toLowerCase(),note:e.note,repeatMode:e.repeat_mode.toLowerCase(),eventTitle:e.event_title,triggerMessage:e.trigger_message,secondsToNotifyBefore:e.seconds_to_notify_before,allowsRsvp:e.allows_rsvp,relatedEvent:e.related_event,members:e.event_reminder_members.edges.map((function(e){return{memberID:e.node.id,state:e.guest_list_state.toLowerCase()}}))}}module.exports=function(s,i,a){return function(i,r,o,m){if(m||"Function"!==e.getType(o)&&"AsyncFunction"!==e.getType(o)||(m=o,o=[""]),"Number"!==e.getType(i)||!Number.isInteger(i)||i<=0)throw{error:"getThreadList: limit must be a positive integer"};if("Null"!==e.getType(r)&&("Number"!==e.getType(r)||!Number.isInteger(r)))throw{error:"getThreadList: timestamp must be an integer or null"};if("String"===e.getType(o)&&(o=[o]),"Array"!==e.getType(o))throw{error:"getThreadList: tags must be an array"};let d=function(){},_=function(){};const c=new Promise((function(e,t){d=e,_=t}));"Function"!==e.getType(m)&&"AsyncFunction"!==e.getType(m)&&(m=function(e,t){if(e)return _(e);d(t)});const u={av:a.globalOptions.pageID,queries:JSON.stringify({o0:{doc_id:"3336396659757871",query_params:{limit:i+(r?1:0),before:r,tags:o,includeDeliveryReceipts:!0,includeSeqID:!1}}}),batch_name:"MessengerGraphQLThreadlistFetcher"};return s.post("https://www.facebook.com/api/graphqlbatch/",a.jar,u).then(e.parseAndCheckLogin(a,s)).then((e=>{if(e[e.length-1].error_results>0)throw e[0].o0.errors;if(0===e[e.length-1].successful_results)throw{error:"getThreadList: there was no successful_results",res:e};r&&e[0].o0.data.viewer.message_threads.nodes.shift(),m(null,e[0].o0.data.viewer.message_threads.nodes.map((e=>function(e){const t=e.last_message,s=t&&t.nodes&&t.nodes[0]&&t.nodes[0].message_sender&&t.nodes[0].message_sender.messaging_actor?t.nodes[0].message_sender.messaging_actor.id:null,i=t&&t.nodes&&t.nodes[0]?t.nodes[0].snippet:null,a=e.last_read_receipt,r=a&&a.nodes&&a.nodes[0]&&a.nodes[0].timestamp_precise?a.nodes[0].timestamp_precise:null;return{threadID:e.thread_key.thread_fbid?e.thread_key.thread_fbid:e.thread_key.other_user_id,threadName:e.name,participantIDs:e.all_participants.edges.map((e=>e.node.messaging_actor.id)),userInfo:e.all_participants.edges.map((e=>({id:e.node.messaging_actor.id,name:e.node.messaging_actor.name,firstName:e.node.messaging_actor.short_name,vanity:e.node.messaging_actor.username,url:e.node.messaging_actor.url,thumbSrc:e.node.messaging_actor.big_image_src.uri,profileUrl:e.node.messaging_actor.big_image_src.uri,gender:e.node.messaging_actor.gender,type:e.node.messaging_actor.__typename,isFriend:e.node.messaging_actor.is_viewer_friend,isBirthday:!!e.node.messaging_actor.is_birthday}))),unreadCount:e.unread_count,messageCount:e.messages_count,timestamp:e.updated_time_precise,muteUntil:e.mute_until,isGroup:"GROUP"==e.thread_type,isSubscribed:e.is_viewer_subscribed,isArchived:e.has_viewer_archived,folder:e.folder,cannotReplyReason:e.cannot_reply_reason,eventReminders:e.event_reminders?e.event_reminders.nodes.map(n):null,emoji:e.customization_info?e.customization_info.emoji:null,color:e.customization_info&&e.customization_info.outgoing_bubble_color?e.customization_info.outgoing_bubble_color.slice(2):null,threadTheme:e.thread_theme,nicknames:e.customization_info&&e.customization_info.participant_customizations?e.customization_info.participant_customizations.reduce((function(e,t){return t.nickname&&(e[t.participant_id]=t.nickname),e}),{}):{},adminIDs:e.thread_admins,approvalMode:Boolean(e.approval_mode),approvalQueue:e.group_approval_queue.nodes.map((e=>({inviterID:e.inviter.id,requesterID:e.requester.id,timestamp:e.request_timestamp,request_source:e.request_source}))),reactionsMuteMode:e.reactions_mute_mode.toLowerCase(),mentionsMuteMode:e.mentions_mute_mode.toLowerCase(),isPinProtected:e.is_pin_protected,relatedPageThread:e.related_page_thread,name:e.name,snippet:i,snippetSender:s,snippetAttachments:[],serverTimestamp:e.updated_time_precise,imageSrc:e.image?e.image.uri:null,isCanonicalUser:e.is_canonical_neo_user,isCanonical:"GROUP"!=e.thread_type,recipientsLoadable:!0,hasEmailParticipant:!1,readOnly:!1,canReply:null==e.cannot_reply_reason,lastMessageTimestamp:e.last_message?e.last_message.timestamp_precise:null,lastMessageType:"message",lastReadTimestamp:r,threadType:"GROUP"==e.thread_type?2:1,inviteLink:{enable:!!e.joinable_mode&&1==e.joinable_mode.mode,link:e.joinable_mode?e.joinable_mode.link:null}}}(e))))})).catch((e=>(t.error("getThreadList",e),m(e)))),c}};
@@ -0,0 +1 @@
1
+ const e=require("../utils"),t=require("npmlog");module.exports=function(r,n,o){return function(n,a,i,s){let u=function(){},h=function(){};const c=new Promise((function(e,t){u=e,h=t}));s||(s=function(e,t){if(e)return h(e);u(t)});let m={thread_id:n,offset:a,limit:i};return r.post("https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php",o.jar,m).then(e.parseAndCheckLogin(o,r)).then((function(t){if(t.error)throw t;return Promise.all(t.payload.imagesData.map((function(t){return m={thread_id:n,image_id:t.fbid},r.post("https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php",o.jar,m).then(e.parseAndCheckLogin(o,r)).then((function(e){if(e.error)throw e;return e.jsmods.require[0][3][1].query_results[e.jsmods.require[0][3][1].query_metadata.query_path[0].message_thread].message_images.edges[0].node.image2}))})))})).then((function(e){s(null,e)})).catch((function(e){t.error("Error in getThreadPictures",e),s(e)})),c}};
@@ -0,0 +1 @@
1
+ const e=require("../utils"),r=require("npmlog");function t(r){return{userID:e.formatID(r.uid.toString()),photoUrl:r.photo,indexRank:r.index_rank,name:r.text,isVerified:r.is_verified,profileUrl:r.path,category:r.category,score:r.score,type:r.type}}module.exports=function(n,o,i){return function(o,c){let u=function(){},a=function(){};const s=new Promise((function(e,r){u=e,a=r}));c||(c=function(e,r){if(e)return a(e);u(r)});const p={value:o.toLowerCase(),viewer:i.i_userID||i.userID,rsp:"search",context:"search",path:"/home.php",request_id:e.getGUID()};return n.get("https://www.facebook.com/ajax/typeahead/search.php",i.jar,p).then(e.parseAndCheckLogin(i,n)).then((function(e){if(e.error)throw e;c(null,e.payload.entries.map(t))})).catch((function(e){return r.error("getUserID",e),c(e)})),s}};
@@ -0,0 +1 @@
1
+ const n=require("../utils"),e=require("npmlog");module.exports=function(r,t,o){return function(t,i){let s=function(){},a=function(){};const c=new Promise((function(n,e){s=n,a=e}));i||(i=function(n,e){if(n)return a(n);s(e)}),"Array"!==n.getType(t)&&(t=[t]);const u={};return t.map((function(n,e){u["ids["+e+"]"]=n})),r.post("https://www.facebook.com/chat/user_info/",o.jar,u).then(n.parseAndCheckLogin(o,r)).then((function(n){if(n.error)throw n;return i(null,function(n){const e={};for(const r in n)if(n.hasOwnProperty(r)){const t=n[r];e[r]={name:t.name,firstName:t.firstName,vanity:t.vanity,thumbSrc:t.thumbSrc,profileUrl:t.uri,gender:t.gender,type:t.type,isFriend:t.is_friend,isBirthday:!!t.is_birthday,searchTokens:t.searchTokens,alternateName:t.alternateName}}return e}(n.payload.profiles))})).catch((function(n){return e.error("getUserInfo",n),i(n)})),c}};
@@ -0,0 +1 @@
1
+ require("../utils"),require("npmlog"),module.exports=function(n,r,e){return function(r,t){var u=function(){},i=function(){},o=new Promise((function(n,r){u=n,i=r}));t||(t=function(n,r){if(n)return i(n);u(r)});try{var{getInfo:f}=require("../lib/getInfoNew");f(r,e.jar,e,n).then((n=>t(null,n)))}catch(n){return t(null,n)}return o}};
@@ -0,0 +1 @@
1
+ const e=require("../utils"),r=require("npmlog");module.exports=function(n,t,o){return function(t,i,s){if("Boolean"!==e.getType(i))throw{error:"Please pass a boolean as a second argument."};let u=function(){},c=function(){};const a=new Promise((function(e,r){u=e,c=r}));return s||(s=function(e,r){if(e)return c(e);u(r)}),n.post("https://www.facebook.com/requests/friends/ajax/",o.jar,{viewer_id:o.i_userID||o.userID,"frefs[0]":"jwl",floc:"friend_center_requests",ref:"/reqs.php",action:i?"confirm":"reject"}).then(e.parseAndCheckLogin(o,n)).then((function(e){if(e.payload.err)throw{err:e.payload.err};return s()})).catch((function(e){return r.error("handleFriendRequest",e),s(e)})),a}};
@@ -0,0 +1 @@
1
+ const e=require("../utils"),n=require("npmlog");module.exports=function(r,t,o){return function(t,c,u){if("Boolean"!==e.getType(c))throw{error:"Please pass a boolean as a second argument."};let a=function(){},i=function(){};const s=new Promise((function(e,n){a=e,i=n}));u||(u=function(e,n){if(e)return i(e);a(n)});const f={client:"mercury"};"Array"!==e.getType(t)&&(t=[t]);const h=c?"inbox":"other";for(let e=0;e<t.length;e++)f[h+"["+e+"]"]=t[e];return r.post("https://www.facebook.com/ajax/mercury/move_thread.php",o.jar,f).then(e.parseAndCheckLogin(o,r)).then((function(e){if(e.error)throw e;return u()})).catch((function(e){return n.error("handleMessageRequest",e),u(e)})),s}};
package/src/httpGet.js ADDED
@@ -0,0 +1 @@
1
+ const n=require("../utils"),t=require("npmlog");module.exports=function(e,o,r){return function(o,u,c,i,l){let f=function(){},g=function(){};const p=new Promise((function(n,t){f=n,g=t}));return"Function"!=n.getType(u)&&"AsyncFunction"!=n.getType(u)||(i=u,u={}),"Function"!=n.getType(c)&&"AsyncFunction"!=n.getType(c)||(i=c,c={}),c=c||{},i=i||function(n,t){if(n)return g(n);f(t)},l?n.get(o,r.jar,u,r.globalOptions,r,c).then((function(n){i(null,n.body)})).catch((function(n){return t.error("httpGet",n),i(n)})):e.get(o,r.jar,u,null,c).then((function(n){i(null,n.body)})).catch((function(n){return t.error("httpGet",n),i(n)})),p}};
@@ -0,0 +1 @@
1
+ const n=require("../utils"),t=require("npmlog");module.exports=function(o,e,r){return function(e,u,c,i,s){let f=function(){},p=function(){};const l=new Promise((function(n,t){f=n,p=t}));return"Function"!=n.getType(u)&&"AsyncFunction"!=n.getType(u)||(i=u,u={}),"Function"!=n.getType(c)&&"AsyncFunction"!=n.getType(c)||(i=c,c={}),c=c||{},i=i||function(n,t){if(n)return p(n);f(t)},s?n.post(e,r.jar,u,r.globalOptions,r,c).then((function(n){i(null,n.body)})).catch((function(n){return t.error("httpPost",n),i(n)})):o.post(e,r.jar,u,{},c).then((function(n){i(null,n.body)})).catch((function(n){return t.error("httpPost",n),i(n)})),l}};
@@ -0,0 +1 @@
1
+ const t=require("../utils"),n=require("npmlog");module.exports=function(o,r,e){return function(r,u,c,i,l){let a=function(){},f=function(){};const p=new Promise((function(t,n){a=t,f=n}));return"Function"!=t.getType(u)&&"AsyncFunction"!=t.getType(u)||(i=u,u={}),"Function"!=t.getType(c)&&"AsyncFunction"!=t.getType(c)||(i=c,c={}),c=c||{},i=i||function(t,n){if(t)return f(t);a(n)},l?t.postFormData(r,e.jar,u,e.globalOptions,e,c).then((function(t){i(null,t.body.toString())})).catch((function(t){return n.error("httpGet",t),i(t)})):o.postFormData(r,e.jar,u,null,c).then((function(t){i(null,t.body.toString())})).catch((function(t){return n.error("httpPostFormData",t),i(t)})),p}};
@@ -0,0 +1 @@
1
+ const e=require("../utils"),t=require("npmlog"),a=require("mqtt"),s=require("websocket-stream"),r=require("https-proxy-agent"),n=require("events"),i=function(){};let o={},l=function(){};const d=["/legacy_web","/webrtc","/rtc_multi","/onevc","/br_sr","/sr_res","/t_ms","/thread_typing","/orca_typing_notifications","/notify_disconnect","/orca_presence","/legacy_web_mtouch"];function g(t,n,i,g){const m=i.globalOptions.online,p=Math.floor(9007199254740991*Math.random())+1,h={u:i.i_userID||i.userID,s:p,chat_on:m,fg:!1,d:e.getGUID(),ct:"websocket",aid:"219994525426954",mqtt_sid:"",cp:3,ecp:10,st:[],pm:[],dc:"",no_auto_fg:!0,gas:null,pack:[],a:i.globalOptions.userAgent,aids:null},u=i.jar.getCookies("https://www.facebook.com").join("; ");let _;_=i.mqttEndpoint?i.mqttEndpoint+"&sid="+p:i.region?"wss://edge-chat.facebook.com/chat?region="+i.region.toLocaleLowerCase()+"&sid="+p:"wss://edge-chat.facebook.com/chat?sid="+p;const y={clientId:"mqttwsclient",protocolId:"MQIsdp",protocolVersion:3,username:JSON.stringify(h),clean:!0,wsOptions:{headers:{Cookie:u,Origin:"https://www.facebook.com","User-Agent":i.globalOptions.userAgent,Referer:"https://www.facebook.com/",Host:new URL(_).hostname},origin:"https://www.facebook.com",protocolVersion:13},keepalive:10,reschedulePings:!1};if(void 0!==i.globalOptions.proxy){const e=new r(i.globalOptions.proxy);y.wsOptions.agent=e}i.mqttClient=new a.Client((e=>s(_,y.wsOptions)),y);const b=i.mqttClient;b.on("error",(function(e){b.end(),i.globalOptions.autoReconnect?l():g({type:"stop_listen",error:"Connection refused: Server unavailable"},null)})),b.on("close",(function(){b.end(),t.post("https://www.facebook.com/api/graphqlbatch/",i.jar,o).then(e.parseAndCheckLogin(i,t)).then((t=>{if("Array"!=e.getType(t))throw{error:"Not logged in",res:t};g("Connection closed.")})).catch((t=>("Object"!=e.getType(t)||"Not logged in"!==t.error&&"Not logged in."!==t.error||(i.loggedIn=!1),g(t))))})),b.on("connect",(function(){let e;d.forEach((function(e){b.subscribe(e)}));const t={sync_api_version:10,max_deltas_able_to_process:1e3,delta_batch_size:500,encoding:"JSON",entity_fbid:i.i_userID||i.userID};i.syncToken?(e="/messenger_sync_get_diffs",t.last_seq_id=i.lastSeqId,t.sync_token=i.syncToken):(e="/messenger_sync_create_queue",t.initial_titan_sequence_id=i.lastSeqId,t.device_params=null),b.publish(e,JSON.stringify(t),{qos:1,retain:!1}),b.publish("/foreground_state",JSON.stringify({foreground:m}),{qos:1}),b.publish("/set_client_settings",JSON.stringify({make_user_available_when_in_foreground:!0}),{qos:1});const a=setTimeout((function(){b.end(),l()}),5e3);i.tmsWait=function(){clearTimeout(a),i.globalOptions.emitReady&&g({type:"ready",error:null}),delete i.tmsWait}})),b.on("message",(function(a,s,r){let o=Buffer.isBuffer(s)?Buffer.from(s).toString():s;try{o=JSON.parse(o)}catch(e){o={}}if("jewel_requests_add"===o.type)g(null,{type:"friend_request_received",actorFbId:o.from.toString(),timestamp:Date.now().toString()});else if("jewel_requests_remove_old"===o.type)g(null,{type:"friend_request_cancel",actorFbId:o.from.toString(),timestamp:Date.now().toString()});else if("/t_ms"===a){i.tmsWait&&"function"==typeof i.tmsWait&&i.tmsWait(),o.firstDeltaSeqId&&o.syncToken&&(i.lastSeqId=o.firstDeltaSeqId,i.syncToken=o.syncToken),o.lastIssuedSeqId&&(i.lastSeqId=parseInt(o.lastIssuedSeqId));for(const e in o.deltas)c(t,n,i,g,{delta:o.deltas[e]})}else if("/thread_typing"===a||"/orca_typing_notifications"===a){const t={type:"typ",isTyping:!!o.state,from:o.sender_fbid.toString(),threadID:e.formatID((o.thread||o.sender_fbid).toString())};g(null,t)}else if("/orca_presence"===a&&!i.globalOptions.updatePresence)for(const e in o.list){const t=o.list[e],a={type:"presence",userID:t.u.toString(),timestamp:1e3*t.l,statuses:t.p};g(null,a)}}))}function c(a,s,r,n,i){if("NewMessage"==i.delta.class){if(r.globalOptions.pageID&&r.globalOptions.pageID!=i.queue)return;!function t(a){if(a==i.delta.attachments.length){let t;try{t=e.formatDeltaMessage(i)}catch(e){return n({error:"Problem parsing message object. Please open an issue at https://github.com/ntkhang03/fb-chat-api/issues.",detail:e,res:i,type:"parse_error"})}return t&&r.globalOptions.autoMarkDelivery&&m(r,s,t.threadID,t.messageID),r.globalOptions.selfListen||t.senderID!==r.i_userID&&t.senderID!==r.userID?void n(null,t):void 0}if("photo"!=i.delta.attachments[a].mercury.attach_type)return t(a+1);s.resolvePhotoUrl(i.delta.attachments[a].fbid,((e,s)=>(e||(i.delta.attachments[a].mercury.metadata.url=s),t(a+1))))}(0)}if("ClientPayload"==i.delta.class){const l=e.decodeClientPayload(i.delta.payload);if(l&&l.deltas){for(const i in l.deltas){var o=l.deltas[i];if(o.deltaMessageReaction&&r.globalOptions.listenEvents)n(null,{type:"message_reaction",threadID:(o.deltaMessageReaction.threadKey.threadFbId?o.deltaMessageReaction.threadKey.threadFbId:o.deltaMessageReaction.threadKey.otherUserFbId).toString(),messageID:o.deltaMessageReaction.messageId,reaction:o.deltaMessageReaction.reaction,senderID:0==o.deltaMessageReaction.senderId?o.deltaMessageReaction.userId.toString():o.deltaMessageReaction.senderId.toString(),userID:(o.deltaMessageReaction.userId||o.deltaMessageReaction.senderId).toString()});else if(o.deltaRecallMessageData&&r.globalOptions.listenEvents)n(null,{type:"message_unsend",threadID:(o.deltaRecallMessageData.threadKey.threadFbId?o.deltaRecallMessageData.threadKey.threadFbId:o.deltaRecallMessageData.threadKey.otherUserFbId).toString(),messageID:o.deltaRecallMessageData.messageID,senderID:o.deltaRecallMessageData.senderID.toString(),deletionTimestamp:o.deltaRecallMessageData.deletionTimestamp,timestamp:o.deltaRecallMessageData.timestamp});else if(o.deltaRemoveMessage&&r.globalOptions.listenEvents)n(null,{type:"message_self_delete",threadID:(o.deltaRemoveMessage.threadKey.threadFbId?o.deltaRemoveMessage.threadKey.threadFbId:o.deltaRemoveMessage.threadKey.otherUserFbId).toString(),messageID:1==o.deltaRemoveMessage.messageIds.length?o.deltaRemoveMessage.messageIds[0]:o.deltaRemoveMessage.messageIds,senderID:s.getCurrentUserID(),deletionTimestamp:o.deltaRemoveMessage.deletionTimestamp,timestamp:o.deltaRemoveMessage.timestamp});else if(o.deltaMessageReply){let i=void 0===o.deltaMessageReply.message||void 0===o.deltaMessageReply.message.data||void 0===o.deltaMessageReply.message.data.prng?[]:JSON.parse(o.deltaMessageReply.message.data.prng),l=i.map((e=>e.i)),d=i.map((e=>e.o)),g=i.map((e=>e.l));const c={};for(let e=0;e<l.length;e++)c[l[e]]=(o.deltaMessageReply.message.body||"").substring(d[e],d[e]+g[e]);const p={type:"message_reply",threadID:(o.deltaMessageReply.message.messageMetadata.threadKey.threadFbId?o.deltaMessageReply.message.messageMetadata.threadKey.threadFbId:o.deltaMessageReply.message.messageMetadata.threadKey.otherUserFbId).toString(),messageID:o.deltaMessageReply.message.messageMetadata.messageId,senderID:o.deltaMessageReply.message.messageMetadata.actorFbId.toString(),attachments:o.deltaMessageReply.message.attachments.map((function(e){const t=JSON.parse(e.mercuryJSON);return Object.assign(e,t),e})).map((t=>{let a;try{a=e._formatAttachment(t)}catch(e){a=t,a.error=e,a.type="unknown"}return a})),body:o.deltaMessageReply.message.body||"",isGroup:!!o.deltaMessageReply.message.messageMetadata.threadKey.threadFbId,mentions:c,timestamp:o.deltaMessageReply.message.messageMetadata.timestamp,participantIDs:(o.deltaMessageReply.message.participants||[]).map((e=>e.toString()))};if(o.deltaMessageReply.repliedToMessage){i=void 0===o.deltaMessageReply.repliedToMessage||void 0===o.deltaMessageReply.repliedToMessage.data||void 0===o.deltaMessageReply.repliedToMessage.data.prng?[]:JSON.parse(o.deltaMessageReply.repliedToMessage.data.prng),l=i.map((e=>e.i)),d=i.map((e=>e.o)),g=i.map((e=>e.l));const t={};for(let e=0;e<l.length;e++)t[l[e]]=(o.deltaMessageReply.repliedToMessage.body||"").substring(d[e],d[e]+g[e]);p.messageReply={threadID:(o.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId?o.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId:o.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.otherUserFbId).toString(),messageID:o.deltaMessageReply.repliedToMessage.messageMetadata.messageId,senderID:o.deltaMessageReply.repliedToMessage.messageMetadata.actorFbId.toString(),attachments:o.deltaMessageReply.repliedToMessage.attachments.map((function(e){const t=JSON.parse(e.mercuryJSON);return Object.assign(e,t),e})).map((t=>{let a;try{a=e._formatAttachment(t)}catch(e){a=t,a.error=e,a.type="unknown"}return a})),body:o.deltaMessageReply.repliedToMessage.body||"",isGroup:!!o.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId,mentions:t,timestamp:o.deltaMessageReply.repliedToMessage.messageMetadata.timestamp,participantIDs:(o.deltaMessageReply.repliedToMessage.participants||[]).map((e=>e.toString()))}}else{if(o.deltaMessageReply.replyToMessageId)return a.post("https://www.facebook.com/api/graphqlbatch/",r.jar,{av:r.globalOptions.pageID,queries:JSON.stringify({o0:{doc_id:"2848441488556444",query_params:{thread_and_message_id:{thread_id:p.threadID,message_id:o.deltaMessageReply.replyToMessageId.id}}}})}).then(e.parseAndCheckLogin(r,a)).then((t=>{if(t[t.length-1].error_results>0)throw t[0].o0.errors;if(0===t[t.length-1].successful_results)throw{error:"forcedFetch: there was no successful_results",res:t};const a=t[0].o0.data.message,s={};for(const e in a.message.ranges)s[a.message.ranges[e].entity.id]=(a.message.text||"").substr(a.message.ranges[e].offset,a.message.ranges[e].length);p.messageReply={threadID:p.threadID,messageID:a.message_id,senderID:a.message_sender.id.toString(),attachments:a.message.blob_attachment.map((t=>{let a;try{a=e._formatAttachment({blob_attachment:t})}catch(e){a=t,a.error=e,a.type="unknown"}return a})),body:a.message.text||"",isGroup:p.isGroup,mentions:s,timestamp:parseInt(a.timestamp_precise)}})).catch((e=>{t.error("forcedFetch",e)})).finally((function(){r.globalOptions.autoMarkDelivery&&m(r,s,p.threadID,p.messageID),(r.globalOptions.selfListen||p.senderID!==r.i_userID&&p.senderID!==r.userID)&&n(null,p)}));p.delta=o}return r.globalOptions.autoMarkDelivery&&m(r,s,p.threadID,p.messageID),r.globalOptions.selfListen||p.senderID!==r.i_userID&&p.senderID!==r.userID?void n(null,p):void 0}}return}}if("NewMessage"===i.delta.class||r.globalOptions.listenEvents)switch(i.delta.class){case"ReadReceipt":try{l=e.formatDeltaReadReceipt(i.delta)}catch(e){return n({error:"Problem parsing message object. Please open an issue at https://github.com/ntkhang03/fb-chat-api/issues.",detail:e,res:i.delta,type:"parse_error"})}return void n(null,l);case"AdminTextMessage":switch(i.delta.type){case"change_thread_theme":case"change_thread_nickname":case"change_thread_icon":case"change_thread_admins":case"group_poll":var l;try{l=e.formatDeltaEvent(i.delta)}catch(e){return n({error:"Problem parsing message object. Please open an issue at https://github.com/ntkhang03/fb-chat-api/issues.",detail:e,res:i.delta,type:"parse_error"})}return void n(null,l);default:return}case"ForcedFetch":if(!i.delta.threadKey)return;var d=i.delta.messageId,g=i.delta.threadKey.threadFbId;if(d&&g){const s={av:r.globalOptions.pageID,queries:JSON.stringify({o0:{doc_id:"2848441488556444",query_params:{thread_and_message_id:{thread_id:g.toString(),message_id:d}}}})};a.post("https://www.facebook.com/api/graphqlbatch/",r.jar,s).then(e.parseAndCheckLogin(r,a)).then((a=>{if(a[a.length-1].error_results>0)throw a[0].o0.errors;if(0===a[a.length-1].successful_results)throw{error:"forcedFetch: there was no successful_results",res:a};const s=a[0].o0.data.message;if("Object"==e.getType(s))switch(t.info("forcedFetch",s),s.__typename){case"ThreadImageMessage":(r.globalOptions.selfListenEvent||s.message_sender.id.toString()!==r.i_userID&&s.message_sender.id.toString()!==r.userID)&&r.loggedIn&&n(null,{type:"event",threadID:e.formatID(g.toString()),messageID:s.message_id,logMessageType:"log:thread-image",logMessageData:{attachmentID:s.image_with_metadata&&s.image_with_metadata.legacy_attachment_id,width:s.image_with_metadata&&s.image_with_metadata.original_dimensions.x,height:s.image_with_metadata&&s.image_with_metadata.original_dimensions.y,url:s.image_with_metadata&&s.image_with_metadata.preview.uri},logMessageBody:s.snippet,timestamp:s.timestamp_precise,author:s.message_sender.id});break;case"UserMessage":t.info("ff-Return",{type:"message",senderID:e.formatID(s.message_sender.id),body:s.message.text||"",threadID:e.formatID(g.toString()),messageID:s.message_id,attachments:[{type:"share",ID:s.extensible_attachment.legacy_attachment_id,url:s.extensible_attachment.story_attachment.url,title:s.extensible_attachment.story_attachment.title_with_entities.text,description:s.extensible_attachment.story_attachment.description.text,source:s.extensible_attachment.story_attachment.source,image:((s.extensible_attachment.story_attachment.media||{}).image||{}).uri,width:((s.extensible_attachment.story_attachment.media||{}).image||{}).width,height:((s.extensible_attachment.story_attachment.media||{}).image||{}).height,playable:(s.extensible_attachment.story_attachment.media||{}).is_playable||!1,duration:(s.extensible_attachment.story_attachment.media||{}).playable_duration_in_ms||0,subattachments:s.extensible_attachment.subattachments,properties:s.extensible_attachment.story_attachment.properties}],mentions:{},timestamp:parseInt(s.timestamp_precise),isGroup:s.message_sender.id!=g.toString()}),n(null,{type:"message",senderID:e.formatID(s.message_sender.id),body:s.message.text||"",threadID:e.formatID(g.toString()),messageID:s.message_id,attachments:[{type:"share",ID:s.extensible_attachment.legacy_attachment_id,url:s.extensible_attachment.story_attachment.url,title:s.extensible_attachment.story_attachment.title_with_entities.text,description:s.extensible_attachment.story_attachment.description.text,source:s.extensible_attachment.story_attachment.source,image:((s.extensible_attachment.story_attachment.media||{}).image||{}).uri,width:((s.extensible_attachment.story_attachment.media||{}).image||{}).width,height:((s.extensible_attachment.story_attachment.media||{}).image||{}).height,playable:(s.extensible_attachment.story_attachment.media||{}).is_playable||!1,duration:(s.extensible_attachment.story_attachment.media||{}).playable_duration_in_ms||0,subattachments:s.extensible_attachment.subattachments,properties:s.extensible_attachment.story_attachment.properties}],mentions:{},timestamp:parseInt(s.timestamp_precise),isGroup:s.message_sender.id!=g.toString()})}else t.error("forcedFetch",s)})).catch((e=>{t.error("forcedFetch",e)}))}break;case"ThreadName":case"ParticipantsAddedToGroupThread":case"ParticipantLeftGroupThread":case"ApprovalQueue":var c;try{c=e.formatDeltaEvent(i.delta)}catch(e){return n({error:"Problem parsing message object. Please open an issue at https://github.com/ntkhang03/fb-chat-api/issues.",detail:e,res:i.delta,type:"parse_error"})}return(r.globalOptions.selfListenEvent||c.author.toString()!==r.i_userID&&c.author.toString()!==r.userID)&&r.loggedIn?void n(null,c):void 0}}function m(e,a,s,r){s&&r&&a.markAsDelivered(s,r,(r=>{r?t.error("markAsDelivered",r):e.globalOptions.autoMarkRead&&a.markAsRead(s,(e=>{e&&t.error("markAsDelivered",e)}))}))}module.exports=function(t,a,s){let r=i;return l=function(){return s.t_mqttCalled=!1,t.post("https://www.facebook.com/api/graphqlbatch/",s.jar,o).then(e.parseAndCheckLogin(s,t)).then((n=>{if("Array"!=e.getType(n)){const e=new Error("Not logged in");throw e.res=n,e.error="Not logged in",e}if(n&&n[n.length-1].error_results>0)throw n[0].o0.errors;if(0===n[n.length-1].successful_results)throw{error:"getSeqId: there was no successful_results",res:n};if(!n[0].o0.data.viewer.message_threads.sync_sequence_id){const e=new Error("No sync_sequence_id found.");throw e.res=n,e.error="getSeqId: no sync_sequence_id found.",e}s.lastSeqId=n[0].o0.data.viewer.message_threads.sync_sequence_id,g(t,a,s,r)})).catch((t=>{throw"Object"!=e.getType(t)||"Not logged in"!==t.error&&"Not logged in."!==t.error||(s.loggedIn=!1),t}))},function(e){const d=new class extends n{stopListening(e){e=e||(()=>{}),r=i,s.mqttClient&&(s.mqttClient.unsubscribe("/webrtc"),s.mqttClient.unsubscribe("/rtc_multi"),s.mqttClient.unsubscribe("/onevc"),s.mqttClient.publish("/browser_close","{}"),s.mqttClient.end(!1,(function(...t){e(t),s.mqttClient=void 0})))}async stopListeningSync(){return new Promise((e=>{this.stopListening(((...t)=>{e(t)}))}))}};return r=e||function(e,t){if(e)return d.emit("error",e);d.emit("message",t)},s.firstListen||(s.lastSeqId=null),s.syncToken=void 0,s.t_mqttCalled=!1,o={av:s.globalOptions.pageID,queries:JSON.stringify({o0:{doc_id:"3336396659757871",query_params:{limit:1,before:null,tags:["INBOX"],includeDeliveryReceipts:!1,includeSeqID:!0}}})},s.firstListen&&s.lastSeqId?g(t,a,s,r):l().catch((()=>{g(t,a,s,r)})),s.firstListen=!1,a.stopListening=d.stopListening,a.stopListeningSync=d.stopListeningSync,d}};
package/src/logout.js ADDED
@@ -0,0 +1 @@
1
+ const e=require("../utils"),t=require("npmlog");module.exports=function(o,n,r){return function(n){let u=function(){},s=function(){};const c=new Promise((function(e,t){u=e,s=t}));return n||(n=function(e,t){if(e)return s(e);u(t)}),o.post("https://www.facebook.com/bluebar/modern_settings_menu/?help_type=364455653583099&show_contextual_help=1",r.jar,{pmid:"0"}).then(e.parseAndCheckLogin(r,o)).then((function(t){const n=t.jsmods.instances[0][2][0].filter((function(e){return"logout"===e.value}))[0],u=t.jsmods.markup.filter((function(e){return e[0]===n.markup.__m}))[0][1].__html,s={fb_dtsg:e.getFrom(u,'"fb_dtsg" value="','"'),ref:e.getFrom(u,'"ref" value="','"'),h:e.getFrom(u,'"h" value="','"')};return o.post("https://www.facebook.com/logout.php",r.jar,s).then(e.saveCookies(r.jar))})).then((function(t){if(!t.headers)throw{error:"An error occurred when logging out."};return o.get(t.headers.location,r.jar).then(e.saveCookies(r.jar))})).then((function(){r.loggedIn=!1,t.info("logout","Logged out successfully."),n()})).catch((function(e){return t.error("logout",e),n(e)})),c}};
@@ -0,0 +1 @@
1
+ const e=require("../utils"),r=require("npmlog");module.exports=function(n,t,o){return function(t,i,s){let c=function(){},u=function(){};const a=new Promise((function(e,r){c=e,u=r}));if(s||(s=function(e,r){if(e)return u(e);c(r)}),!t||!i)return s("Error: messageID or threadID is not defined");const f={};return f["message_ids[0]"]=i,f["thread_ids["+t+"][0]"]=i,n.post("https://www.facebook.com/ajax/mercury/delivery_receipts.php",o.jar,f).then(e.saveCookies(o.jar)).then(e.parseAndCheckLogin(o,n)).then((function(e){if(e.error)throw e;return s()})).catch((function(n){return r.error("markAsDelivered",n),"Object"==e.getType(n)&&"Not logged in."===n.error&&(o.loggedIn=!1),s(n)})),a}};
@@ -0,0 +1 @@
1
+ const e=require("../utils"),t=require("npmlog");module.exports=function(r,n,a){return async function(n,o,s){"Function"!==e.getType(o)&&"AsyncFunction"!==e.getType(o)||(s=o,o=!0),null==o&&(o=!0),s||(s=()=>{});const i={};if(void 0!==a.globalOptions.pageID){let c;i.source="PagesManagerMessagesInterface",i.request_user_id=a.globalOptions.pageID,i["ids["+n+"]"]=o,i.watermarkTimestamp=(new Date).getTime(),i.shouldSendReadReceipt=!0,i.commerce_last_message_type="";try{c=await r.post("https://www.facebook.com/ajax/mercury/change_read_status.php",a.jar,i).then(e.saveCookies(a.jar)).then(e.parseAndCheckLogin(a,r))}catch(e){return s(e),e}if(c.error){const r=c.error;return t.error("markAsRead",r),"Object"==e.getType(r)&&"Not logged in."===r.error&&(a.loggedIn=!1),s(r),r}return s(),null}try{if(!a.mqttClient)throw{error:"You can only use this function after you start listening."};{const e=await new Promise((e=>a.mqttClient.publish("/mark_thread",JSON.stringify({threadID:n,mark:"read",state:o}),{qos:1,retain:!1},e)));if(e)throw e}}catch(e){return s(e),e}}};
@@ -0,0 +1 @@
1
+ const r=require("../utils"),n=require("npmlog");module.exports=function(e,o,t){return function(o){let u=function(){},i=function(){};const c=new Promise((function(r,n){u=r,i=n}));return o||(o=function(r,n){if(r)return i(r);u(n)}),e.post("https://www.facebook.com/ajax/mercury/mark_folder_as_read.php",t.jar,{folder:"inbox"}).then(r.saveCookies(t.jar)).then(r.parseAndCheckLogin(t,e)).then((function(r){if(r.error)throw r;return o()})).catch((function(r){return n.error("markAsReadAll",r),o(r)})),c}};
@@ -0,0 +1 @@
1
+ const e=require("../utils"),n=require("npmlog");module.exports=function(t,r,o){return function(r,c){"Function"!=e.getType(r)&&"AsyncFunction"!=e.getType(r)||(c=r,r=Date.now());let i=function(){},u=function(){};const s=new Promise((function(e,n){i=e,u=n}));return c||(c=function(e,n){if(e)return u(e);i(n)}),t.post("https://www.facebook.com/ajax/mercury/mark_seen.php",o.jar,{seen_timestamp:r}).then(e.saveCookies(o.jar)).then(e.parseAndCheckLogin(o,t)).then((function(e){if(e.error)throw e;return c()})).catch((function(t){return n.error("markAsSeen",t),"Object"==e.getType(t)&&"Not logged in."===t.error&&(o.loggedIn=!1),c(t)})),s}};
@@ -0,0 +1 @@
1
+ const e=require("../utils"),t=require("npmlog");module.exports=function(n,r,o){return function(r,u,i){let c=function(){},a=function(){};const f=new Promise((function(e,t){c=e,a=t}));return i||(i=function(e,t){if(e)return a(e);c(t)}),n.post("https://www.facebook.com/ajax/mercury/change_mute_thread.php",o.jar,{thread_fbid:r,mute_settings:u}).then(e.saveCookies(o.jar)).then(e.parseAndCheckLogin(o,n)).then((function(e){if(e.error)throw e;return i()})).catch((function(e){return t.error("muteThread",e),i(e)})),f}};
@@ -0,0 +1 @@
1
+ const e=require("../utils"),r=require("npmlog");module.exports=function(t,o,n){return function(o,i,u){if(!u&&("Function"===e.getType(i)||"AsyncFunction"===e.getType(i)))throw{error:"please pass a threadID as a second argument."};if("Number"!==e.getType(i)&&"String"!==e.getType(i))throw{error:"threadID should be of type Number or String and not "+e.getType(i)+"."};if("Number"!==e.getType(o)&&"String"!==e.getType(o))throw{error:"userID should be of type Number or String and not "+e.getType(o)+"."};let c=function(){},p=function(){};const f=new Promise((function(e,r){c=e,p=r}));return u||(u=function(e,r){if(e)return p(e);c(r)}),t.post("https://www.facebook.com/chat/remove_participants",n.jar,{uid:o,tid:i}).then(e.parseAndCheckLogin(n,t)).then((function(e){if(!e)throw{error:"Remove from group failed."};if(e.error)throw e;return u()})).catch((function(e){return r.error("removeUserFromGroup",e),u(e)})),f}};
@@ -0,0 +1 @@
1
+ const r=require("../utils"),t=require("npmlog");module.exports=function(e,o,n){return function(o,u){let c=function(){},i=function(){};const s=new Promise((function(r,t){c=r,i=t}));return u||(u=function(r,t){if(r)return i(r);c(t)}),e.get("https://www.facebook.com/mercury/attachments/photo",n.jar,{photo_id:o}).then(r.parseAndCheckLogin(n,e)).then((r=>{if(r.error)throw r;return u(null,r.jsmods.require[0][3][0])})).catch((r=>(t.error("resolvePhotoUrl",r),u(r)))),s}};
@@ -0,0 +1 @@
1
+ const r=require("../utils");module.exports=function(e,n,t){return function(n,o){let a=function(){},u=function(){};const i=new Promise((function(r,e){a=r,u=e}));return o||(o=function(r,e){if(r)return u(r);a(e)}),e.post("https://www.facebook.com/ajax/mercury/search_threads.php",t.jar,{client:"web_messenger",query:n,offset:0,limit:21,index:"fbid"}).then(r.parseAndCheckLogin(t,e)).then((function(e){if(e.error)throw e;return e.payload.mercury_payload.threads?o(null,e.payload.mercury_payload.threads.map(r.formatThread)):o({error:"Could not find thread `"+n+"`."})})),i}};
@@ -0,0 +1 @@
1
+ var e=require("../utils"),t=require("npmlog"),r=require("bluebird"),n=(require("fs-extra"),{attachment:!0,url:!0,sticker:!0,emoji:!0,emojiSize:!0,body:!0,mentions:!0,location:!0});module.exports=function(i,o,a){function s(r,n,o,s,l){if("Array"===e.getType(n)){for(var u=0;u<n.length;u++)r["specific_to_list["+u+"]"]="fbid:"+n[u];r["specific_to_list["+n.length+"]"]="fbid:"+a.userID,r.client_thread_id="root:"+s,t.info("sendMessage","Sending message to multiple users: "+n)}else o?(r["specific_to_list[0]"]="fbid:"+n,r["specific_to_list[1]"]="fbid:"+a.userID,r.other_user_fbid=n):r.thread_fbid=n;a.globalOptions.pageID&&(r.author="fbid:"+a.globalOptions.pageID,r["specific_to_list[1]"]="fbid:"+a.globalOptions.pageID,r["creator_info[creatorID]"]=a.userID,r["creator_info[creatorType]"]="direct_admin",r["creator_info[labelType]"]="sent_message",r["creator_info[pageID]"]=a.globalOptions.pageID,r.request_user_id=a.globalOptions.pageID,r["creator_info[profileURI]"]="https://www.facebook.com/profile.php?id="+a.userID),i.post("https://www.facebook.com/messaging/send/",a.jar,r).then(e.parseAndCheckLogin(a,i)).then((function(e){if(!e)return l({error:"Send message failed."});if(e.error)return 1545012===e.error&&t.warn("sendMessage","Got error 1545012. This might mean that you're not part of the conversation "+n),l(e);var r=e.payload.actions.reduce((function(e,t){return{threadID:t.thread_fbid,messageID:t.message_id,timestamp:t.timestamp}||e}),null);return l(null,r)})).catch((function(r){return t.error("sendMessage",r),"Object"==e.getType(r)&&"Not logged in."===r.error&&(a.loggedIn=!1),l(r,null)}))}return function(o,l,u,c,d){if(void 0===d&&(d=null),!u&&("Function"===e.getType(l)||"AsyncFunction"===e.getType(l)))return l({error:"Pass a threadID as a second argument."});c||"String"!==e.getType(u)||(c=u,u=function(){});var f=function(){},m=function(){},p=new Promise((function(e,t){f=e,m=t}));u||(u=function(e,t){if(e)return m(e);f(t)});var g=e.getType(o),_=e.getType(l),h=e.getType(c);if("String"!==g&&"Object"!==g)return u({error:"Message should be of type string or object and not "+g+"."});if("Array"!==_&&"Number"!==_&&"String"!==_)return u({error:"ThreadID should be of type number, string, or array and not "+_+"."});if(c&&"String"!==h)return u({error:"MessageID should be of type string and not "+_+"."});"String"===g&&(o={body:o});var y=Object.keys(o).filter((e=>!n[e]));if(y.length>0)return u({error:"Dissallowed props: `"+y.join(", ")+"`"});var b=e.generateOfflineThreadingID(),I={client:"mercury",action_type:"ma-type:user-generated-message",author:"fbid:"+a.userID,timestamp:Date.now(),timestamp_absolute:"Today",timestamp_relative:e.generateTimestampRelative(),timestamp_time_passed:"0",is_unread:!1,is_cleared:!1,is_forward:!1,is_filtered_content:!1,is_filtered_content_bh:!1,is_filtered_content_account:!1,is_filtered_content_quasar:!1,is_filtered_content_invalid_app:!1,is_spoof_warning:!1,source:"source:chat:web","source_tags[0]":"source:chat",body:o.body?o.body.toString().replace("️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️"," "):"",html_body:!1,ui_push_phase:"V3",status:"0",offline_threading_id:b,message_id:b,threading_id:e.generateThreadingID(a.clientID),"ephemeral_ttl_mode:":"0",manual_retry_cnt:"0",has_attachment:!!(o.attachment||o.url||o.sticker),signatureID:e.getSignatureID(),replied_to_message_id:c};return function(n,c,f,m){if(n.location){if(null==n.location.latitude||null==n.location.longitude)return f({error:"location property needs both latitude and longitude"});c["location_attachment[coordinates][latitude]"]=n.location.latitude,c["location_attachment[coordinates][longitude]"]=n.location.longitude,c["location_attachment[is_current_location]"]=!!n.location.current}!function(n,c,f,m){n.sticker&&(c.sticker_id=n.sticker),function(n,o,s,l){n.attachment?(o.image_ids=[],o.gif_ids=[],o.file_ids=[],o.video_ids=[],o.audio_ids=[],"Array"!==e.getType(n.attachment)&&(n.attachment=[n.attachment]),function(n,o){for(var s=[],l=0;l<n.length;l++){if(!e.isReadableStream(n[l]))throw{error:"Attachment should be a readable stream and not "+e.getType(n[l])+"."};s.push(i.postFormData("https://upload.facebook.com/ajax/mercury/upload.php",a.jar,{upload_1024:n[l],voice_clip:"true"},{}).then(e.parseAndCheckLogin(a,i)).then((function(e){if(e.error)throw e;return e.payload.metadata[0]})))}r.all(s).then((e=>o(null,e))).catch((function(e){return t.error("uploadAttachment",e),o(e)}))}(n.attachment,(function(e,t){if(e)return s(e);t.forEach((function(e){var t=Object.keys(e)[0];o[t+"s"].push(e[t])})),l()}))):l()}(o,I,u,(()=>function(r,n,o,s){var l;r.url?(n["shareable_attachment[share_type]"]="100",l=function(e,t){if(e)return o(e);n["shareable_attachment[share_params]"]=t,s()},i.post("https://www.facebook.com/message_share_attachment/fromURI/",a.jar,{image_height:960,image_width:960,uri:r.url}).then(e.parseAndCheckLogin(a,i)).then((function(e){return e.error?l(e):e.payload?void l(null,e.payload.share_data.share_params):l({error:"Invalid url"})})).catch((function(e){return t.error("getUrl",e),l(e)}))):s()}(o,I,u,(()=>function(r,n,i,a){if(null!=r.emojiSize&&null==r.emoji)return i({error:"emoji property is empty"});if(r.emoji){if(null==r.emojiSize&&(r.emojiSize="medium"),"small"!=r.emojiSize&&"medium"!=r.emojiSize&&"large"!=r.emojiSize)return i({error:"emojiSize property is invalid"});if(null!=n.body&&""!=n.body)return i({error:"body is not empty"});n.body=r.emoji,n["tags[0]"]="hot_emoji_size:"+r.emojiSize}!function(r,n,i,o){if(r.mentions)for(let e=0;e<r.mentions.length;e++){const o=r.mentions[e],a=o.tag;if("string"!=typeof a)return i({error:"Mention tags must be strings."});const s=r.body.indexOf(a,o.fromIndex||0);s<0&&t.warn("handleMention",'Mention for "'+a+'" not found in message string.'),null==o.id&&t.warn("handleMention","Mention id should be non-null.");const l=o.id||0;n.body="‎"+r.body,n["profile_xmd["+e+"][offset]"]=s+1,n["profile_xmd["+e+"][length]"]=a.length,n["profile_xmd["+e+"][id]"]=l,n["profile_xmd["+e+"][type]"]="p"}!function(t,r,n,i,o){"Array"===e.getType(r)?s(t,r,!1,n,i):"Boolean"!=e.getType(o)?s(t,r,r.toString().length<16,n,i):s(t,r,!o,n,i)}(I,l,b,u,d)}(o,I,u)}(o,I,u)))))}(o,I)}(o,I,u),p}};
@@ -0,0 +1 @@
1
+ const n=require("../utils"),t=require("npmlog");module.exports=function(e,o,r){function c(c,i,g,a){const u={typ:+c,to:"",source:"mercury-chat",thread:i};"Boolean"==n.getType(a)?(a||(u.to=i),e.post("https://www.facebook.com/ajax/messaging/typ.php",r.jar,u).then(n.parseAndCheckLogin(r,e)).then((function(n){if(n.error)throw n;return g()})).catch((function(e){return t.error("sendTypingIndicator",e),"Object"==n.getType(e)&&"Not logged in"===e.error&&(r.loggedIn=!1),g(e)}))):o.getUserInfo(i,(function(o,c){if(o)return g(o);Object.keys(c).length>0&&(u.to=i),e.post("https://www.facebook.com/ajax/messaging/typ.php",r.jar,u).then(n.parseAndCheckLogin(r,e)).then((function(n){if(n.error)throw n;return g()})).catch((function(e){return t.error("sendTypingIndicator",e),"Object"==n.getType(e)&&"Not logged in."===e.error&&(r.loggedIn=!1),g(e)}))}))}return function(e,o,r){return"Function"!==n.getType(o)&&"AsyncFunction"!==n.getType(o)&&(o&&t.warn("sendTypingIndicator","callback is not a function - ignoring."),o=()=>{}),c(!0,e,o,r),function(o){"Function"!==n.getType(o)&&"AsyncFunction"!==n.getType(o)&&(o&&t.warn("sendTypingIndicator","callback is not a function - ignoring."),o=()=>{}),c(!1,e,o,r)}}};
@@ -0,0 +1 @@
1
+ const e=require("../utils"),a=require("npmlog");module.exports=function(r,t,c){return function(t,n,s,o){let i=function(){},u=function(){};const h=new Promise((function(e,a){i=e,u=a}));switch(s||(s=function(e,a){if(e)return u(e);i(a)}),t){case"😍":case"😆":case"😮":case"😢":case"😠":case"👍":case"👎":case"❤":case"💗":case"":break;case":heart_eyes:":case":love:":t="😍";break;case":laughing:":case":haha:":t="😆";break;case":open_mouth:":case":wow:":t="😮";break;case":cry:":case":sad:":t="😢";break;case":angry:":t="😠";break;case":thumbsup:":case":like:":t="👍";break;case":thumbsdown:":case":dislike:":t="👎";break;case":heart:":t="❤";break;case":glowingheart:":t="💗";break;default:if(o)break;return s({error:"Reaction is not a valid emoji."})}const b={data:{client_mutation_id:c.clientMutationId++,actor_id:c.i_userID||c.userID,action:""==t?"REMOVE_REACTION":"ADD_REACTION",message_id:n,reaction:t}},l={doc_id:"1491398900900362",variables:JSON.stringify(b),dpr:1};return r.postFormData("https://www.facebook.com/webgraphql/mutation/",c.jar,{},l).then(e.parseAndCheckLogin(c.jar,r)).then((function(e){if(!e)throw{error:"setReaction returned empty object."};if(e.error)throw e;s(null)})).catch((function(e){return a.error("setReaction",e),s(e)})),h}};
@@ -0,0 +1 @@
1
+ const e=require("../utils"),t=require("npmlog");module.exports=function(r,n,a){return function(n,o,c){let i=function(){},d=function(){};const s=new Promise((function(e,t){i=e,d=t}));if(c||("Function"===e.getType(o)||"AsyncFunction"===e.getType(o)?(c=o,o=0):c=function(e,t){if(e)return d(e);i(t)}),"Number"!==e.getType(o)&&"String"===e.getType(o)&&(o={unlike:0,like:1,heart:2,love:16,haha:4,wow:3,sad:7,angry:8}[o.toLowerCase()]),"Number"!==e.getType(o)&&"String"!==e.getType(o))throw{error:"setPostReaction: Invalid reaction type"};if(0!=o&&!o)throw{error:"setPostReaction: Invalid reaction type"};const u={av:a.userID,fb_api_caller_class:"RelayModern",fb_api_req_friendly_name:"CometUFIFeedbackReactMutation",doc_id:"4769042373179384",variables:JSON.stringify({input:{actor_id:a.i_userID||a.userID,feedback_id:new Buffer("feedback:"+n).toString("base64"),feedback_reaction:o,feedback_source:"OBJECT",is_tracking_encrypted:!0,tracking:[],session_id:"f7dd50dd-db6e-4598-8cd9-561d5002b423",client_mutation_id:Math.round(19*Math.random()).toString()},useDefaultActor:!1,scale:3})};return r.post("https://www.facebook.com/api/graphql/",a.jar,u).then(e.parseAndCheckLogin(a,r)).then((function(e){if(e.errors)throw e;return c(null,{viewer_feedback_reaction_info:(t=e.data).feedback_react.feedback.viewer_feedback_reaction_info,supported_reactions:t.feedback_react.feedback.supported_reactions,top_reactions:t.feedback_react.feedback.top_reactions.edges,reaction_count:t.feedback_react.feedback.reaction_count});var t})).catch((function(e){return t.error("setPostReaction",e),c(e)})),s}};
@@ -0,0 +1 @@
1
+ const e=require("../utils"),t=require("npmlog");module.exports=function(r,n,a){return function(n,o,i){if(!i&&("Function"===e.getType(o)||"AsyncFunction"===e.getType(o)))throw{error:"please pass a threadID as a second argument."};let s=function(){},c=function(){};const u=new Promise((function(e,t){s=e,c=t}));i||(i=function(e,t){if(e)return c(e);s(t)});const m=e.generateOfflineThreadingID(),_={client:"mercury",action_type:"ma-type:log-message",author:"fbid:"+(a.i_userID||a.userID),author_email:"",coordinates:"",timestamp:Date.now(),timestamp_absolute:"Today",timestamp_relative:e.generateTimestampRelative(),timestamp_time_passed:"0",is_unread:!1,is_cleared:!1,is_forward:!1,is_filtered_content:!1,is_spoof_warning:!1,source:"source:chat:web","source_tags[0]":"source:chat",status:"0",offline_threading_id:m,message_id:m,threading_id:e.generateThreadingID(a.clientID),manual_retry_cnt:"0",thread_fbid:o,thread_name:n,thread_id:o,log_message_type:"log:thread-name"};return r.post("https://www.facebook.com/messaging/set_thread_name/",a.jar,_).then(e.parseAndCheckLogin(a,r)).then((function(e){if(e.error&&1545012===e.error)throw{error:"Cannot change chat title: Not member of chat."};if(e.error&&1545003===e.error)throw{error:"Cannot set title of single-user chat."};if(e.error)throw e;return i()})).catch((function(e){return t.error("setTitle",e),i(e)})),u}};
@@ -0,0 +1 @@
1
+ module.exports=function(e,r,a){return{MessengerBlue:"196241301102133",Viking:"1928399724138152",GoldenPoppy:"174636906462322",RadicalRed:"2129984390566328",Shocking:"2058653964378557",FreeSpeechGreen:"2136751179887052",Pumpkin:"175615189761153",LightCoral:"980963458735625",MediumSlateBlue:"234137870477637",DeepSkyBlue:"2442142322678320",BrilliantRose:"169463077092846",DefaultBlue:"196241301102133",HotPink:"169463077092846",AquaBlue:"2442142322678320",BrightPurple:"234137870477637",CoralPink:"980963458735625",Orange:"175615189761153",Green:"2136751179887052",LavenderPurple:"2058653964378557",Red:"2129984390566328",Yellow:"174636906462322",TealBlue:"1928399724138152",Aqua:"417639218648241",Mango:"930060997172551",Berry:"164535220883264",Citrus:"370940413392601",Candy:"205488546921017",Earth:"1833559466821043",Support:"365557122117011",Music:"339021464972092",Pride:"1652456634878319",DoctorStrange:"538280997628317",LoFi:"1060619084701625",Sky:"3190514984517598",LunarNewYear:"357833546030778",Celebration:"627144732056021",Chill:"390127158985345",StrangerThings:"1059859811490132",Dune:"1455149831518874",Care:"275041734441112",Astrology:"3082966625307060",JBalvin:"184305226956268",Birthday:"621630955405500",Cottagecore:"539927563794799",Ocean:"736591620215564",Love:"741311439775765",TieDye:"230032715012014",Monochrome:"788274591712841",Default:"3259963564026002",Rocket:"582065306070020",Berry2:"724096885023603",Candy2:"624266884847972",Unicorn:"273728810607574",Tropical:"262191918210707",Maple:"2533652183614000",Sushi:"909695489504566",Citrus2:"557344741607350",Lollipop:"280333826736184",Shadow:"271607034185782",Rose:"1257453361255152",Lavender:"571193503540759",Tulip:"2873642949430623",Classic:"3273938616164733",Peach:"3022526817824329",Honey:"672058580051520",Kiwi:"3151463484918004",Grape:"193497045377796",NonBinary:"737761000603635",ThankfulForFriends:"1318983195536293",Transgender:"504518465021637",TaylorSwift:"769129927636836",NationalComingOutDay:"788102625833584",Autumn:"822549609168155",Cyberpunk2077:"780962576430091"}};
@@ -0,0 +1 @@
1
+ const n=require("../utils"),e=require("npmlog");module.exports=function(r,t,o){return function(t,i){let u=function(){},c=function(){};const f=new Promise((function(n,e){u=n,c=e}));return i||(i=function(n,e){if(n)return c(n);u(e)}),r.post("https://www.facebook.com/ajax/profile/removefriendconfirm.php",o.jar,{uid:t,unref:"bd_friends_tab",floc:"friends_tab","nctr[_mod]":"pagelet_timeline_app_collection_"+(o.i_userID||o.userID)+":2356318349:2"}).then(n.parseAndCheckLogin(o,r)).then((function(n){if(n.error)throw n;return i()})).catch((function(n){return e.error("unfriend",n),i(n)})),f}};
@@ -0,0 +1 @@
1
+ const n=require("../utils"),e=require("npmlog");module.exports=function(r,t,o){return function(t,u){let s=function(){},i=function(){};const c=new Promise((function(n,e){s=n,i=e}));return u||(u=function(n,e){if(n)return i(n);s(e)}),r.post("https://www.facebook.com/messaging/unsend_message/",o.jar,{message_id:t}).then(n.parseAndCheckLogin(o,r)).then((function(n){if(n.error)throw n;return u()})).catch((function(n){return e.error("unsendMessage",n),u(n)})),c}};
@@ -0,0 +1 @@
1
+ const t=require("../utils"),e=require("npmlog"),r=require("bluebird");module.exports=function(n,a,o){return function(a,u){if(!a&&!t.isReadableStream(a)&&"Array"===!t.getType(a)&&"Array"===t.getType(a)&&!a.length)throw{error:"Please pass an attachment or an array of attachments."};let i=function(){},c=function(){};const l=new Promise((function(t,e){i=t,c=e}));return u||(u=function(t,e){if(t)return c(t);i(e)}),"Array"!==t.getType(a)&&(a=[a]),function(a,u){u=u||function(){};const i=[];for(let e=0;e<a.length;e++){if(!t.isReadableStream(a[e]))throw{error:"Attachment should be a readable stream and not "+t.getType(a[e])+"."};i.push(n.postFormData("https://upload.facebook.com/ajax/mercury/upload.php",o.jar,{upload_1024:a[e],voice_clip:"true"},{}).then(t.parseAndCheckLogin(o,n)).then((function(t){if(t.error)throw t;return t.payload.metadata[0]})))}r.all(i).then((function(t){u(null,t)})).catch((function(t){return e.error("uploadAttachment",t),u(t)}))}(a,((t,e)=>{if(t)return u(t);u(null,e)})),l}};
@@ -0,0 +1,146 @@
1
+ module.exports = {
2
+ "delta": {
3
+ "attachments": [
4
+ {
5
+ "fbid": "1522004821162174",
6
+ "id": "1522004821162174",
7
+ "mercury": {
8
+ "app_attribution": null,
9
+ "attach_type": "share",
10
+ "name": null,
11
+ "url": null,
12
+ "rel": null,
13
+ "preview_url": null,
14
+ "preview_width": null,
15
+ "preview_height": null,
16
+ "large_preview_url": null,
17
+ "large_preview_width": null,
18
+ "large_preview_height": null,
19
+ "icon_type": null,
20
+ "metadata": null,
21
+ "thumbnail_url": null,
22
+ "share": {
23
+ "description": null,
24
+ "media": {
25
+ "animated_image": null,
26
+ "animated_image_size": {
27
+ "height": null,
28
+ "width": null
29
+ },
30
+ "image": null,
31
+ "image_size": {
32
+ "height": null,
33
+ "width": null
34
+ },
35
+ "duration": null,
36
+ "playable": null,
37
+ "source": null
38
+ },
39
+ "source": "Dimon - testing",
40
+ "style_list": [
41
+ "business_message_items", "fallback"
42
+ ],
43
+ "title": "search engines",
44
+ "properties": null,
45
+ "uri": null,
46
+ "subattachments": [],
47
+ "deduplication_key": "abcde",
48
+ "action_links": [],
49
+ "share_id": "1522004821162174",
50
+ "target": {
51
+ "call_to_actions": [],
52
+ "items": [
53
+ {
54
+ "id": "629934437209008",
55
+ "name": "search engines",
56
+ "desc": "",
57
+ "thumb_url": null,
58
+ "item_url": null,
59
+ "title": "search engines",
60
+ "text": "",
61
+ "source": null,
62
+ "metalines": {
63
+ "metaline_1": "click to get redirected",
64
+ "metaline_2": null,
65
+ "metaline_3": null
66
+ },
67
+ "location": 12314,
68
+ "category": 69,
69
+ "call_to_actions": [
70
+ {
71
+ "action_link": "http://l.facebook.com/l.php?u=http%3A%2F%2Fgoogle.com%2F&h=ATNziCq_-6I3ZPYwwLluFdCrWMEwLLKvokFlXdEdS4LD2Lzsv2cR2SJYffJcDYBfB092Xeq8oRdftJk4husEYVduH24RnlP3HvVQOkOrciXDs2M7TkWYyNLBelvJ2Fc-mw8pbGy5NslGf_fkZ_A",
72
+ "action_type": 2,
73
+ "id": "FFD=",
74
+ "title": "Google",
75
+ "link_target_ids": [629934437209008],
76
+ "is_mutable_by_server": false,
77
+ "should_show_user_confirmation": false,
78
+ "confirmation_title": null,
79
+ "confirmation_message": null,
80
+ "confirmation_continue_label": null,
81
+ "confirmation_cancel_label": null,
82
+ "payment_metadata": {
83
+ "total_price": null,
84
+ "payment_module_config": null
85
+ },
86
+ "is_disabled": false
87
+ }, {
88
+ "action_link": "http://l.facebook.com/l.php?u=http%3A%2F%2Fyahoo.com%2F&h=ATNIuTf7iDGP5xXTWOAdhaGhRFfDf4eS09t_G9CrR0MDiBKpqtCDzPf_9y5Bq7TXMgmo6RttztsgeO0ReSc0PDvJDTa1fLMMK2CjrpkqC91_m-yaMXfeQ4aI6MbhZrOPnK3YFnQP4XvRx3N1udE",
89
+ "action_type": 2,
90
+ "id": "CDE=",
91
+ "title": "Yahoo",
92
+ "link_target_ids": [629934437209008],
93
+ "is_mutable_by_server": false,
94
+ "should_show_user_confirmation": false,
95
+ "confirmation_title": null,
96
+ "confirmation_message": null,
97
+ "confirmation_continue_label": null,
98
+ "confirmation_cancel_label": null,
99
+ "payment_metadata": {
100
+ "total_price": null,
101
+ "payment_module_config": null
102
+ },
103
+ "is_disabled": false
104
+ }, {
105
+ "action_link": "http://l.facebook.com/l.php?u=http%3A%2F%2Fbing.com%2F&h=ATMoMijAt6Da6WWIQ679DhZyZizWdxAViWwyl-RjKobFUG_x8GmB8LD6pPa3KP5K1-QTL9vuaFwjqB0itaMFWk4VwQ9uh56JgnbFnAo4qM_CrQufgLeHwwCnWSCnZt8IzYT4y6YULLLFA5bL1H4",
106
+ "action_type": 2,
107
+ "id": "ABC=",
108
+ "title": "Bing",
109
+ "link_target_ids": [629934437209008],
110
+ "is_mutable_by_server": false,
111
+ "should_show_user_confirmation": false,
112
+ "confirmation_title": null,
113
+ "confirmation_message": null,
114
+ "confirmation_continue_label": null,
115
+ "confirmation_cancel_label": null,
116
+ "payment_metadata": {
117
+ "total_price": null,
118
+ "payment_module_config": null
119
+ },
120
+ "is_disabled": false
121
+ }
122
+ ]
123
+ }
124
+ ],
125
+ "location": 132145,
126
+ "category": 69,
127
+ "message": "Aaa: search engines"
128
+ }
129
+ }
130
+ },
131
+ "otherUserFbIds": ["1521994257829897"],
132
+ "titanType": 1
133
+ }
134
+ ],
135
+ "messageMetadata": {
136
+ "actorFbId": "1345",
137
+ "messageId": "mid.12345:asdv",
138
+ "offlineThreadingId": "1345v1345",
139
+ "tags": ["source:messenger:commerce"],
140
+ "threadKey": {
141
+ "otherUserFbId": "13451345"
142
+ },
143
+ "timestamp": "1487078180265"
144
+ }
145
+ }
146
+ }
@@ -0,0 +1,7 @@
1
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut placerat risus massa, eu rutrum massa tempus id. Aenean aliquet turpis at risus gravida, id scelerisque sem vestibulum. Aliquam erat volutpat. Pellentesque ut justo a sapien fringilla tincidunt ornare ac arcu. Nam non finibus turpis, eget tincidunt turpis. Morbi sed tempus leo. Aliquam ut nunc sed ante efficitur tristique et sed eros.
2
+
3
+ In eu tincidunt libero, eget tincidunt mauris. Donec ultrices placerat tincidunt. Sed ultrices neque dui, id viverra ante porta sed. Suspendisse tincidunt malesuada finibus. Ut cursus dolor sem, eu mattis lectus euismod a. In porttitor maximus lacus, eget volutpat mauris pretium at. Nulla consequat ipsum id enim fermentum feugiat. Fusce convallis bibendum massa ac viverra.
4
+
5
+ Sed a vehicula diam, et sollicitudin nunc. Quisque nec libero sit amet nibh fringilla pretium at vel massa. In enim dolor, euismod sed sapien id, accumsan tempus lacus. Aenean dapibus nulla at libero ultricies, id sagittis erat pretium. Nam iaculis tellus est, lobortis lacinia dui egestas vitae. Phasellus elementum quis lectus nec tincidunt. Ut gravida vestibulum ipsum ut cursus.
6
+
7
+ Mauris quam est, dignissim sed quam at, vulputate scelerisque purus. Maecenas tortor turpis, venenatis non purus et, finibus venenatis augue. Etiam et fringilla enim. Suspendisse a leo sed ex aliquet feugiat vitae nec magna. Vestibulum id massa in orci dictum ultricies. Vestibulum vitae leo sed lacus tempor dapibus. Cras viverra lorem sit amet magna imperdiet sodales. In sollicitudin ex sed feugiat commodo. Maecenas ac arcu tristique quam euismod ultrices quis et mi. Nulla lacinia sit amet lacus nec ultrices. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In hac habitasse platea dictumst. Curabitur vehicula, enim at vulputate bibendum, lorem tortor pellentesque massa, nec aliquam lacus mi ac libero. In vel nibh in ante facilisis tristique. Aliquam sapien purus, lobortis quis ultricies nec, dictum a turpis. Aenean pharetra congue lacus, id cursus erat fringilla congue.
@@ -0,0 +1,18 @@
1
+ // Instructions: Copy this file to test-config.json, fill in your test data
2
+ // and remove all comments (JSON doesn't support comments).
3
+ // Run the test with `npm test` after installing the devDependencies (mocha).
4
+ {
5
+ // Test user login information
6
+ "user" : {
7
+ "id" : "00000000000000",
8
+ "email" : "example@test.com",
9
+ "password" : "qwerty"
10
+ },
11
+ // Array of at least 2 other user IDs (not the same as the test user)
12
+ "userIDs" : [
13
+ "11111111111111",
14
+ "22222222222222"
15
+ ],
16
+ // Id of page to which test user is an admin
17
+ "pageID": "3333333333333"
18
+ }
@@ -0,0 +1,140 @@
1
+ var login = require('../index.js');
2
+ var fs = require('fs');
3
+ var assert = require('assert');
4
+
5
+ var conf = JSON.parse(process.env.testconfig || fs.readFileSync('test/test-config.json', 'utf8'));
6
+ var credentials = {
7
+ email: conf.user.email,
8
+ password: conf.user.password,
9
+ };
10
+
11
+ var userIDs = conf.userIDs;
12
+
13
+ var options = {
14
+ selfListen: true,
15
+ listenEvents: true,
16
+ logLevel: "silent",
17
+ pageID: conf.pageID
18
+ };
19
+ var getType = require('../utils').getType;
20
+
21
+ var userID = conf.user.id;
22
+
23
+ var groupChatID;
24
+ var groupChatName;
25
+
26
+ function checkErr(done){
27
+ return function(err) {
28
+ if (err) done(err);
29
+ };
30
+ }
31
+
32
+ // describe('Login As Page:', function() {
33
+ // var api = null;
34
+ // process.on('SIGINT', () => api && !api.logout() && console.log("Logged out :)"));
35
+ // var tests = [];
36
+ // var stopListening;
37
+ // this.timeout(20000);
38
+
39
+ // function listen(done, matcher) {
40
+ // tests.push({matcher:matcher, done:done});
41
+ // }
42
+
43
+ // before(function(done) {
44
+ // login(credentials, options, function (err, localAPI) {
45
+ // if(err) return done(err);
46
+
47
+ // assert(localAPI);
48
+ // api = localAPI;
49
+ // stopListening = api.listen(function (err, msg) {
50
+ // if (err) throw err;
51
+ // // Removes matching function and calls corresponding done
52
+ // tests = tests.filter(function(test) {
53
+ // return !(test.matcher(msg) && (test.done() || true));
54
+ // });
55
+ // });
56
+
57
+ // done();
58
+ // });
59
+ // });
60
+
61
+ // it('should login without error', function (){
62
+ // assert(api);
63
+ // });
64
+
65
+ // it('should get the right user ID', function (){
66
+ // assert(userID == api.getCurrentUserID());
67
+ // });
68
+
69
+ // it('should send text message object (user)', function (done){
70
+ // var body = "text-msg-obj-" + Date.now();
71
+ // listen(done, msg =>
72
+ // msg.type === 'message' &&
73
+ // msg.body === body &&
74
+ // msg.isGroup === false
75
+ // );
76
+ // api.sendMessage({body: body}, userID, checkErr(done));
77
+ // });
78
+
79
+ // it('should send sticker message object (user)', function (done){
80
+ // var stickerID = '767334526626290';
81
+ // listen(done, msg =>
82
+ // msg.type === 'message' &&
83
+ // msg.attachments.length > 0 &&
84
+ // msg.attachments[0].type === 'sticker' &&
85
+ // msg.attachments[0].stickerID === stickerID &&
86
+ // msg.isGroup === false
87
+ // );
88
+ // api.sendMessage({sticker: stickerID}, userID, checkErr(done));
89
+ // });
90
+
91
+ // it('should send basic string (user)', function (done){
92
+ // var body = "basic-str-" + Date.now();
93
+ // listen(done, msg =>
94
+ // msg.type === 'message' &&
95
+ // msg.body === body &&
96
+ // msg.isGroup === false
97
+ // );
98
+ // api.sendMessage(body, userID, checkErr(done));
99
+ // });
100
+
101
+ // it('should send typing indicator', function (done) {
102
+ // var stopType = api.sendTypingIndicator(userID, function(err) {
103
+ // checkErr(done)(err);
104
+ // stopType();
105
+ // done();
106
+ // });
107
+ // });
108
+
109
+ // it('should get the right user info', function (done) {
110
+ // api.getUserInfo(userID, function(err, data) {
111
+ // checkErr(done)(err);
112
+ // var user = data[userID];
113
+ // assert(user.name);
114
+ // assert(user.firstName);
115
+ // assert(user.vanity !== null);
116
+ // assert(user.profileUrl);
117
+ // assert(user.gender);
118
+ // assert(user.type);
119
+ // assert(!user.isFriend);
120
+ // done();
121
+ // });
122
+ // });
123
+
124
+ // it('should get the list of friends', function (done) {
125
+ // api.getFriendsList(function(err, data) {
126
+ // checkErr(done)(err);
127
+ // assert(getType(data) === "Array");
128
+ // data.map(function(v) {parseInt(v);});
129
+ // done();
130
+ // });
131
+ // });
132
+
133
+ // it('should log out', function (done) {
134
+ // api.logout(done);
135
+ // });
136
+
137
+ // after(function (){
138
+ // if (stopListening) stopListening();
139
+ // });
140
+ // });