UNPKG

@jikey/fcazero

Version:

Facebook Messenger bot, and is one of the most advanced next-generation Facebook Chat API (FCA)

2 lines (1 loc) 1.95 kB
"use strict";var y=Object.create;var n=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var P=(r,e)=>{for(var t in e)n(r,t,{get:e[t],enumerable:!0})},h=(r,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of T(e))!j.call(r,s)&&s!==t&&n(r,s,{get:()=>e[s],enumerable:!(a=I(e,s))||a.enumerable});return r};var _=(r,e,t)=>(t=r!=null?y(w(r)):{},h(e||!r||!r.__esModule?n(t,"default",{value:r,enumerable:!0}):t,r)),x=r=>h(n({},"__esModule",{value:!0}),r);var b={};P(b,{default:()=>c});module.exports=x(b);var p=require("../utils/clients.js"),d=require("../utils/constants.js"),f=_(require("../utils/logger.js"),1);class c{constructor(e,t,a){this.defaultFuncs=e;this.ctx=a}call(e,t){return new Promise((a,s)=>{try{if(!e.threadID)throw new Error("please pass a threadID as a second argument.");if(d.Constants.getType(e.threadID)!=="Number"&&d.Constants.getType(e.threadID)!=="String")throw new Error("threadID must be a number or a string");let i={thread_id:e.threadID,offset:e.offset,limit:e.limit};return this.defaultFuncs.post("https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php",this.ctx.jar,i).then(p.Clients.parseAndCheckLogin(this.ctx,this.defaultFuncs)).then(u=>{if(u&&u.error)throw u;return Promise.all(u&&u.payload.imagesData.map(g=>(i={thread_id:e.threadID,image_id:g.fbid},this.defaultFuncs.post("https://www.facebook.com/ajax/messaging/attachments/sharedphotos.php",this.ctx.jar,i).then(p.Clients.parseAndCheckLogin(this.ctx,this.defaultFuncs)).then(o=>{if(o&&o.error)throw o;const l=o&&o.jsmods.require[0][3][1].query_metadata.query_path[0].message_thread,m=o&&o.jsmods.require[0][3][1].query_results[l].message_images.edges[0].node.image2;return t&&typeof t=="function"&&t(null,m),a(m)}))))})}catch(i){return f.default.error({error:i},"GetThreadPictures: error"),t&&typeof t=="function"&&t(i),s(i)}})}}