Socket
Socket
Sign inDemoInstall

fca-utils

Package Overview
Dependencies
127
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.6 to 0.0.7

lib/handlers/event.d.ts

67

lib/index.d.ts
/// <reference types="node" />
import { IFCAU_API, IFCAU_Options, IFCAU_ListenMessage, MessageObject } from '@xaviabot/fca-unofficial';
import { EventEmitter } from 'events';
import { Express } from 'express';
import EventEmitter from 'events';
export declare const DEFAULT_USER_AGENT = "Mozilla/5.0 (Linux; Android 10; SM-G996U Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36";
export declare const DEFAULT_OPTIONS: Partial<IFCAU_Options>;
export type AttachmentObject = {
title: string;
url_or_path: string | string[];
};
export type SendMessage = (message: string | MessageObject) => Promise<{

@@ -12,6 +15,6 @@ threadID: string;

}>;
export type SendAttachmentWR = (attachment: string | {
title: string;
url_or_path: string;
}, reply: boolean) => Promise<{
export type SendAttachmentWR = (attachment: string | string[] | AttachmentObject, options: {
skipFailed: boolean;
reply: boolean;
}) => Promise<{
threadID: string;

@@ -21,5 +24,4 @@ messageID: string;

}>;
export type SendAttachment = (attachment: string | {
title: string;
url_or_path: string;
export type SendAttachment = (attachment: string | string[] | AttachmentObject, options: {
skipFailed: boolean;
}) => Promise<{

@@ -37,34 +39,33 @@ threadID: string;

export type ReactionMessage = Pick<IFCAU_ListenMessage, Extract<keyof IFCAU_ListenMessage, 'type'>> extends infer R ? Extract<IFCAU_ListenMessage, {
type: "reaction";
type: "message_reaction";
}> extends infer S ? R & S : never : never;
export type UnsendMessage = Pick<IFCAU_ListenMessage, Extract<keyof IFCAU_ListenMessage, 'type'>> extends infer R ? Extract<IFCAU_ListenMessage, {
type: "unsend";
type: "message_unsend";
}> extends infer S ? R & S : never : never;
export type OtherMessage = Exclude<IFCAU_ListenMessage, EventMessage | TextMessage | ReactionMessage | UnsendMessage>;
export type TextMessageExtended = TextMessage & {
send: SendMessage;
reply: SendMessage;
sendAttachment: SendAttachmentWR;
};
export type ReactionMessageExtended = ReactionMessage & {
send: SendMessage;
sendAttachment: SendAttachment;
};
export type UnsendMessageExtended = UnsendMessage & {
send: SendMessage;
sendAttachment: SendAttachment;
};
export type CommandsProps = {
name: string;
commandArgs: string[];
message: TextMessage & {
send: SendMessage;
reply: SendMessage;
sendAttachment: SendAttachmentWR;
};
message: TextMessageExtended;
};
export declare interface Client {
on(event: 'ready', listener: (api: IFCAU_API, userID: string) => void): this;
on(event: 'logged', listener: (api: IFCAU_API, userID: string) => void): this;
on(event: 'error', listener: (err: Error) => void): this;
on(event: 'message', listener: (message: TextMessage & {
send: SendMessage;
reply: SendMessage;
sendAttachment: SendAttachmentWR;
}) => void): this;
on(event: 'message', listener: (message: TextMessageExtended) => void): this;
on(event: 'command', listener: (props: CommandsProps) => void): this;
on(event: 'reaction', listener: (message: ReactionMessage & {
send: SendMessage;
sendAttachment: SendAttachment;
}) => void): this;
on(event: 'unsend', listener: (message: UnsendMessage & {
send: SendMessage;
sendAttachment: SendAttachment;
}) => void): this;
on(event: 'reaction', listener: (message: ReactionMessageExtended) => void): this;
on(event: 'unsend', listener: (message: UnsendMessageExtended) => void): this;
on(event: 'others', listener: (message: OtherMessage) => void): this;

@@ -89,5 +90,7 @@ on(event: 'event', listener: (event: EventMessage) => void): this;

getApi(): IFCAU_API | null;
openServer(port?: number, app?: Express): void;
loginWithAppState(EState: string, options: Partial<IFCAU_Options>): void;
loginWithFbState(EState: string, options: Partial<IFCAU_Options>): Promise<IFCAU_API>;
listen(): (EventEmitter & {
stopListening: (callback?: (() => void) | undefined) => void;
}) | undefined;
}
//# sourceMappingURL=index.d.ts.map
import login from '@xaviabot/fca-unofficial';
import axios from 'axios';
import { createReadStream, existsSync } from 'fs';
import { EventEmitter } from 'events';
import createHttpsServer from './server.js';
import EventEmitter from 'events';
import isCommand from './tools/isCommand.js';
import { getAppstate } from './utils.js';
import { eventParser, reactionMessageParser, textMessageParser, unsendMessageParser } from './tools/parser.js';
export const DEFAULT_USER_AGENT = 'Mozilla/5.0 (Linux; Android 10; SM-G996U Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36';

@@ -27,166 +26,46 @@ export const DEFAULT_OPTIONS = {

#isCommand(message) {
if ((message.type === "message" || message.type === "message_reply") && this.#prefix !== null) {
if (message.body.startsWith(this.#prefix) && this.#api !== null) {
const commandArgs = message.body.slice(this.#prefix.length).trim().split(/ +/g);
const name = commandArgs.shift()?.toLowerCase() ?? '';
const { threadID, messageID } = message;
return {
name,
commandArgs,
message: {
...message,
send: (message) => this.#api.sendMessage(message, threadID),
reply: (message) => this.#api.sendMessage(message, threadID, messageID),
sendAttachment: async (attachment, reply = false) => {
const imageSource = typeof attachment === "string" ? attachment : attachment.url_or_path;
const msgObj = {
body: typeof attachment === "string" ? "" : attachment.title,
};
const isExists = existsSync(imageSource);
if (!isExists) {
try {
new URL(imageSource);
msgObj.attachment = await axios.get(imageSource, { responseType: 'stream' }).then(res => res.data);
}
catch (err) {
if (err instanceof Error && err.message.includes('Invalid URL'))
throw new Error("Invalid image source, must be a valid URL or path to the file");
else
throw err;
}
}
else {
msgObj.attachment = createReadStream(imageSource);
}
return this.#api.sendMessage(msgObj, threadID, reply ? messageID : undefined);
}
}
};
}
}
return false;
return isCommand(message, this.#prefix, this.#api);
}
openServer(port = 3001, app) {
createHttpsServer(port, app);
async #loginWithEmail(email, password, options) {
return login({ email, password }, { ...DEFAULT_OPTIONS, ...options })
.then(api => {
});
}
// loginWithEmail(email: string, password: string, options: Partial<IFCAU_Options>) {
// login({ email, password }, { ...DEFAULT_OPTIONS, ...options })
// .then(api => {
// });
// }
loginWithAppState(EState, options) {
async loginWithFbState(EState, options) {
const appState = getAppstate(EState);
login({ appState }, { ...DEFAULT_OPTIONS, ...options })
.then(api => {
this.#api = api;
this.emit('ready', api, api.getCurrentUserID());
api.listenMqtt((err, message) => {
if (!message)
return this.emit('error', err ?? new Error('Fbstate expired/Account checkpointed/banned'));
if (message.type === "event")
this.emit('event', message);
else if (message.type === "message" || message.type === "message_reply") {
const command = this.#isCommand(message);
if (command !== false)
this.emit('command', command);
if (command !== false && this.#ignoreMessageInCommandEvent)
return;
const { threadID, messageID } = message;
this.emit('message', {
...message,
send: (message) => api.sendMessage(message, threadID),
reply: (message) => api.sendMessage(message, threadID, messageID),
sendAttachment: async (attachment, reply = false) => {
const imageSource = typeof attachment === "string" ? attachment : attachment.url_or_path;
const msgObj = {
body: typeof attachment === "string" ? "" : attachment.title,
};
const isExists = existsSync(imageSource);
if (!isExists) {
try {
new URL(imageSource);
msgObj.attachment = await axios.get(imageSource, { responseType: 'stream' }).then(res => res.data);
}
catch (err) {
if (err instanceof Error && err.message.includes('Invalid URL'))
throw new Error("Invalid image source, must be a valid URL or path to the file");
else
throw err;
}
}
else {
msgObj.attachment = createReadStream(imageSource);
}
return this.#api.sendMessage(msgObj, threadID, reply ? messageID : undefined);
}
});
}
else if (message.type === "message_reaction") {
const { threadID } = message;
this.emit('reaction', {
...message,
send: (message) => api.sendMessage(message, threadID),
sendAttachment: async (attachment) => {
const imageSource = typeof attachment === "string" ? attachment : attachment.url_or_path;
const msgObj = {
body: typeof attachment === "string" ? "" : attachment.title,
};
const isExists = existsSync(imageSource);
if (!isExists) {
try {
new URL(imageSource);
msgObj.attachment = await axios.get(imageSource, { responseType: 'stream' }).then(res => res.data);
}
catch (err) {
if (err instanceof Error && err.message.includes('Invalid URL'))
throw new Error("Invalid image source, must be a valid URL or path to the file");
else
throw err;
}
}
else {
msgObj.attachment = createReadStream(imageSource);
}
return this.#api.sendMessage(msgObj, threadID);
}
});
}
else if (message.type === "message_unsend") {
const { threadID } = message;
this.emit('unsend', {
...message,
send: (message) => api.sendMessage(message, threadID),
sendAttachment: async (attachment) => {
const imageSource = typeof attachment === "string" ? attachment : attachment.url_or_path;
const msgObj = {
body: typeof attachment === "string" ? "" : attachment.title,
};
const isExists = existsSync(imageSource);
if (!isExists) {
try {
new URL(imageSource);
msgObj.attachment = await axios.get(imageSource, { responseType: 'stream' }).then(res => res.data);
}
catch (err) {
if (err instanceof Error && err.message.includes('Invalid URL'))
throw new Error("Invalid image source, must be a valid URL or path to the file");
else
throw err;
}
}
else {
msgObj.attachment = createReadStream(imageSource);
}
return this.#api.sendMessage(msgObj, threadID);
}
});
}
else
this.emit('others', message);
});
})
.catch(err => {
this.emit('error', err);
const api = await login({ appState }, { ...DEFAULT_OPTIONS, ...options });
this.#api = api;
process.nextTick(() => {
this.emit('logged', api, api.getCurrentUserID());
});
return api;
}
listen() {
const api = this.#api;
if (!api) {
this.emit('error', new Error('API not initialized'));
return;
}
return api.listenMqtt((err, message) => {
if (!message)
return this.emit('error', err ?? new Error('Fbstate expired/Account checkpointed/banned'));
if (message.type === "event")
return this.emit('event', eventParser(message, api));
if (message.type === "message" || message.type === "message_reply") {
const command = this.#isCommand(message);
if (command.status === true)
this.emit('command', command.data);
if (command.status === true && this.#ignoreMessageInCommandEvent === true)
return;
return this.emit('message', textMessageParser(message, api));
}
if (message.type === "message_reaction") {
return this.emit('reaction', reactionMessageParser(message, api));
}
if (message.type === "message_unsend") {
return this.emit('unsend', unsendMessageParser(message, api));
}
return this.emit('others', message);
});
}
}

@@ -0,3 +1,5 @@

/// <reference types="node" />
import { Express } from 'express';
export default function createHttpServer(port: number, app?: Express): void;
import http from 'http';
export default function createHttpServer(port: number, app?: Express): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
//# sourceMappingURL=server.d.ts.map

@@ -29,2 +29,3 @@ import express from 'express';

});
return tServer;
}
{
"name": "fca-utils",
"version": "0.0.6",
"version": "0.0.7",
"description": "A NodeJS package to help interacting with Facebook Messenger API (fca-unofficial)",

@@ -34,9 +34,5 @@ "main": "lib/index.js",

"dependencies": {
"@xaviabot/fca-unofficial": "^1.3.18",
"axios": "^1.3.4",
"cors": "^2.8.5",
"express": "^4.18.2",
"express-rate-limit": "^6.7.0",
"helmet": "^6.0.1"
"@xaviabot/fca-unofficial": "^1.3.21",
"axios": "^1.3.4"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc