Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fca-utils

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fca-utils

A NodeJS package to help interacting with Facebook Messenger API (fca-unofficial)

  • 0.0.10
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

BETA VERSION

fca-utils

A NodeJS package to interact with Facebook Messenger API (fca-unofficial)
Inspired by discord.js

Installation

npm install fca-utils

Basic Usages

Initialize

import { Client } from 'fca-utils'

const client = new Client({
    prefix: "!", // Prefix for commands
    ignoreMessageInCommandEvent: true, // Ignore message in command event
});

client.loginWithAppState(process.env.BASE64_ENCODED_APPSTATE);
client.on("ready", (api, curID) => {
    console.log("LOGGED IN AS", curID);
    console.log("Listening for messages...");
});

Login with username and password coming soon...



Message Events

client.on(EVENT, (msg) => {
    // Do something
});

Events

  • error - Account error (locked/expired, etc.)
  • message - When a message is received
  • command - When a command is executed (only if prefix is set)
  • reaction - When a reaction is added to a message
  • unsend - When a message is unsent
  • event - When an event is received, such as rename, kick/add users, etc.
  • others - Others events: typ, read, presence, read_receipt



Message

client.on("message", (msg) => {
    console.log("Message received:", msg.body);

    if (msg.type === "message") {
        try {
            if (msg.args[0]?.toLowerCase() === "hi") {
                msg.reply("Hello!");
            }
        } catch (e) {
            console.error(e);
        }
    }
});
Screenshot

message_demo


Basic msg properties:

  • msg.body - Message body
  • msg.args - Array of message body splitted by spaces/line breaks
  • msg.senderID - ID of the sender
  • msg.threadID - ID of the thread/group
  • msg.attachments - Array of attachments
  • msg.mentions - Array of mentions

Basic msg methods:

  • msg.send("your message") - Send a message back to the thread
  • msg.reply("your message") - Reply to the message



Command

client.on("command", async (cmd) => {
    console.log("Command received:", cmd.name);

    try {
        if (cmd.name === "ping") {
            await cmd.message.reply("Pong!");
        }
    } catch (e) {
        console.error(e);
    }
})
Screenshot

message_demo


cmd properties:

  • cmd.message - same as the msg object in "message" event
  • cmd.name - name of the command
  • cmd.commandArgs - array of command arguments, for example:
    • !ping hello world -> ["hello", "world"]



Reaction

client.on("reaction", (msg) => {
    // Do something
});



Unsend

client.on("unsend", (msg) => {
    // Do something
});



Event

client.on("event", (msg) => {
    // Do something
});



Others

client.on("others", (msg) => {
    // Do something
});



Comming soon...

Keywords

FAQs

Package last updated on 22 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc