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.86 kB
"use strict";var l=Object.create;var n=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var k=(r,e)=>{for(var t in e)n(r,t,{get:e[t],enumerable:!0})},m=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of y(e))!A.call(r,s)&&s!==t&&n(r,s,{get:()=>e[s],enumerable:!(i=h(e,s))||i.enumerable});return r};var R=(r,e,t)=>(t=r!=null?l(g(r)):{},m(e||!r||!r.__esModule?n(t,"default",{value:r,enumerable:!0}):t,r)),M=r=>m(n({},"__esModule",{value:!0}),r);var w={};k(w,{default:()=>f});module.exports=M(w);var p=require("../utils/clients.js"),d=R(require("../utils/logger.js"),1);class f{constructor(e,t,i){this.defaultFuncs=e;this.ctx=i}call(e,t){return new Promise(async(i,s)=>{try{e.read==null&&(e.read=!0);const a={},u=this.ctx.jar;if(typeof this.ctx.globalOptions.pageID<"u"){a.source="PagesManagerMessagesInterface",a.request_user_id=this.ctx.globalOptions.pageID,a["ids["+e.threadID+"]"]=e.read,a.watermarkTimestamp=new Date().getTime(),a.shouldSendReadReceipt=!0,a.commerce_last_message_type="";const o=await this.defaultFuncs.post("https://www.facebook.com/ajax/mercury/change_read_status.php",u,a).then(p.Clients.saveCookies(u)).then(p.Clients.parseAndCheckLogin(this.ctx,this.defaultFuncs));o&&o.error&&(d.default.error({err:o.error},"markAsRead"),t&&typeof t=="function"&&t(o.error),s(o.error)),i()}else if(this.ctx.mqttClient&&this.ctx.mqttClient.connected){const o=await new Promise(c=>this.ctx.mqttClient.publish("/mark_thread",JSON.stringify({threadID:e.threadID,mark:"read",state:e.read}),{qos:1,retain:!1},c));if(o)throw o}else throw{error:"You can only use this function after you start listening."}}catch(a){d.default.error({err:a},"markAsRead"),t&&typeof t=="function"&&t(a instanceof Error?a:new Error(String(a))),s(a)}})}}