fca-utils
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -12,2 +12,10 @@ /// <reference types="node" /> | ||
}>; | ||
export type SendAttachment = (attachment: string | { | ||
title: string; | ||
url_or_path: string; | ||
}, reply: boolean) => Promise<{ | ||
threadID: string; | ||
messageID: string; | ||
timestamp: number; | ||
}>; | ||
export type EventMessage = Pick<IFCAU_ListenMessage, Extract<keyof IFCAU_ListenMessage, 'type'>> extends infer R ? Extract<IFCAU_ListenMessage, { | ||
@@ -32,2 +40,3 @@ type: "event"; | ||
reply: SendMessage; | ||
sendAttachment: SendAttachment; | ||
}; | ||
@@ -41,2 +50,3 @@ }; | ||
reply: SendMessage; | ||
sendAttachment: SendAttachment; | ||
}) => void): this; | ||
@@ -70,5 +80,4 @@ on(event: 'command', listener: (props: CommandsProps) => void): this; | ||
openServer(port?: number, app?: Express): void; | ||
loginWithEmail(email: string, password: string, options: Partial<IFCAU_Options>): void; | ||
loginWithAppState(EState: string, options: Partial<IFCAU_Options>): void; | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
import login from '@xaviabot/fca-unofficial'; | ||
import axios from 'axios'; | ||
import { createReadStream, existsSync } from 'fs'; | ||
import { EventEmitter } from 'events'; | ||
@@ -36,3 +38,26 @@ import createHttpsServer from './server.js'; | ||
send: (message) => this.#api.sendMessage(message, threadID), | ||
reply: (message) => this.#api.sendMessage(message, threadID, messageID) | ||
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); | ||
} | ||
} | ||
@@ -47,7 +72,7 @@ }; | ||
} | ||
loginWithEmail(email, password, options) { | ||
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) { | ||
@@ -54,0 +79,0 @@ const appState = getAppstate(EState); |
{ | ||
"name": "fca-utils", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "A NodeJS package to help interacting with Facebook Messenger API (fca-unofficial)", | ||
@@ -34,3 +34,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@xaviabot/fca-unofficial": "^1.3.15", | ||
"@xaviabot/fca-unofficial": "^1.3.18", | ||
"axios": "^1.3.4", | ||
@@ -40,5 +40,4 @@ "cors": "^2.8.5", | ||
"express-rate-limit": "^6.7.0", | ||
"helmet": "^6.0.1", | ||
"node-fetch": "^3.3.1" | ||
"helmet": "^6.0.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
21663
6
283
21
1
- Removednode-fetch@^3.3.1
- Removeddata-uri-to-buffer@4.0.1(transitive)
- Removedfetch-blob@3.2.0(transitive)
- Removedformdata-polyfill@4.0.10(transitive)
- Removednode-domexception@1.0.0(transitive)
- Removednode-fetch@3.3.2(transitive)
- Removedweb-streams-polyfill@3.3.3(transitive)