@jikey/fcazero
Version:
Facebook Messenger bot, and is one of the most advanced next-generation Facebook Chat API (FCA)
2 lines (1 loc) • 5.53 kB
JavaScript
;var y=Object.create;var _=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var w=(r,t)=>{for(var e in t)_(r,e,{get:t[e],enumerable:!0})},g=(r,t,e,m)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of v(t))!T.call(r,n)&&n!==e&&_(r,n,{get:()=>t[n],enumerable:!(m=I(t,n))||m.enumerable});return r};var C=(r,t,e)=>(e=r!=null?y(b(r)):{},g(t||!r||!r.__esModule?_(e,"default",{value:r,enumerable:!0}):e,r)),R=r=>g(_({},"__esModule",{value:!0}),r);var j={};w(j,{default:()=>u});module.exports=R(j);var f=require("../utils/clients.js"),c=require("../utils/constants.js"),h=C(require("../utils/logger.js"),1);class u{constructor(t,e,m){this.defaultFuncs=t;this.ctx=m}static formatEventReminders(t){return{reminderID:t.id,eventCreatorID:t.lightweight_event_creator.id,time:t.time,eventType:t.lightweight_event_type.toLowerCase(),locationName:t.location_name,locationCoordinates:t.location_coordinates,locationPage:t.location_page,eventStatus:t.lightweight_event_status.toLowerCase(),note:t.note,repeatMode:t.repeat_mode.toLowerCase(),eventTitle:t.event_title,triggerMessage:t.trigger_message,secondsToNotifyBefore:t.seconds_to_notify_before,allowsRsvp:t.allows_rsvp,relatedEvent:t.related_event,members:t.event_reminder_members.edges.map(function(e){return{memberID:e.node.id,state:e.guest_list_state.toLowerCase()}})}}static formatThreadGraphQLResponse(t){if(t.errors)return t.errors;const e=t.message_thread;if(!e)return null;const m=e.thread_key.thread_fbid?e.thread_key.thread_fbid:e.thread_key.other_user_id,n=e.last_message,o=n&&n.nodes&&n.nodes[0]&&n.nodes[0].message_sender&&n.nodes[0].message_sender.messaging_actor?n.nodes[0].message_sender.messaging_actor.id:null,d=n&&n.nodes&&n.nodes[0]?n.nodes[0].snippet:null,a=e.last_read_receipt,i=a&&a.nodes&&a.nodes[0]&&a.nodes[0].timestamp_precise?a.nodes[0].timestamp_precise:null;return{threadID:m,threadName:e.name,participantIDs:e.all_participants.edges.map(s=>s.node.messaging_actor.id),userInfo:e.all_participants.edges.map(s=>({id:s.node.messaging_actor.id,name:s.node.messaging_actor.name,firstName:s.node.messaging_actor.short_name,vanity:s.node.messaging_actor.username,url:s.node.messaging_actor.url,thumbSrc:s.node.messaging_actor.big_image_src.uri,profileUrl:s.node.messaging_actor.big_image_src.uri,gender:s.node.messaging_actor.gender,type:s.node.messaging_actor.__typename,isFriend:s.node.messaging_actor.is_viewer_friend,isBirthday:!!s.node.messaging_actor.is_birthday})),unreadCount:e.unread_count,messageCount:e.messages_count,timestamp:e.updated_time_precise,muteUntil:e.mute_until,isGroup:e.thread_type=="GROUP",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(u.formatEventReminders):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(s,p){return p.nickname&&(s[p.participant_id]=p.nickname),s},{}):{},adminIDs:e.thread_admins,approvalMode:!!e.approval_mode,approvalQueue:e.group_approval_queue.nodes.map(s=>({inviterID:s.inviter.id,requesterID:s.requester.id,timestamp:s.request_timestamp,request_source:s.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:d,snippetSender:o,snippetAttachments:[],serverTimestamp:e.updated_time_precise,imageSrc:e.image?e.image.uri:null,isCanonicalUser:e.is_canonical_neo_user,isCanonical:e.thread_type!="GROUP",recipientsLoadable:!0,hasEmailParticipant:!1,readOnly:!1,canReply:e.cannot_reply_reason==null,lastMessageTimestamp:e.last_message?e.last_message.timestamp_precise:null,lastMessageType:"message",lastReadTimestamp:i,threadType:e.thread_type=="GROUP"?2:1,inviteLink:{enable:e.joinable_mode?e.joinable_mode.mode==1:!1,link:e.joinable_mode?e.joinable_mode.link:null}}}call(t,e){return new Promise(async(m,n)=>{try{if(!t.threadID)throw new Error("please pass a threadID as a second argument.");if(c.Constants.getType(t.threadID)!=="Number"&&c.Constants.getType(t.threadID)!=="String")throw new Error("threadID must be a number or a string");const o=[t.threadID];let d={};return o.map(function(a,i){d["o"+i]={doc_id:"3449967031715030",query_params:{id:a,message_limit:0,load_messages:!1,load_read_receipts:!1,before:null}}}),d={queries:JSON.stringify(d),batch_name:"MessengerGraphQLThreadFetcher"},this.defaultFuncs.post("https://www.facebook.com/api/graphqlbatch/",this.ctx.jar,d).then(f.Clients.parseAndCheckLogin(this.ctx,this.defaultFuncs)).then(a=>{if(a&&a.error)throw a;const i={};if(a&&Array.isArray(a)){for(let s=a.length-2;s>=0;s--){const p=Object.keys(a[s])[0];let l=null;p!==void 0&&(l=u.formatThreadGraphQLResponse(a[s][p].data),i[l?.threadID||o[o.length-1-s]]=l)}return Object.values(i).length==1?(e&&typeof e=="function"&&e(null,Object.values(i)[0]),m(Object.values(i)[0])):(e&&typeof e=="function"&&e(null,i),m(i))}})}catch(o){return h.default.error({error:o},"GetThreadInfo: Error"),e&&typeof e=="function"&&(o instanceof Error?e(o):e(new Error(String(o)))),n(o)}})}}