npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

kb2abot

v1.0.1

Published

kb2abot is a powerful Node.js module that allows you to easily interact with the Facebook Chat API and more!

Downloads

9

Readme

About

kb2abot is a powerful Node.js module that allows you to easily interact with the Facebook Chat API and more!

  • Object-oriented
  • Performant
  • Easy to use

Installation

Node.js 16.6.0 or newer is required.

npm install kb2abot
yarn add kb2abot
pnpm add kb2abot

Example usage

Create a report command (report bug/error to specific user on Facebook):

import {Command} from "kb2abot"
const khoakomlemID = "100007723935647"

class Report extends Command {
	keywords = ["report", "bug"];
	description = "report bug/error to admin";
	guide = "<message>";
	permission = {
		"*": "*"
	};

	// Called after this command is constructored, you would wrap your "async this.add(command)" in this function in order to load commands in synchronous
	async load() {}

	// Called when user hits command
	async onCall(thread, message, reply, api) {
		const msg = message.args[0]
		if (msg.length > 0) {
			await api.sendMessage(`"${msg}"\n\n-ID: ${message.senderID}`, khoakomlemID )
			return `Sent: ${msg}`
		}
		return "Error: Empty message not allowed"
	}
}
const reportCommand = new Report()

Afterwards we add that command to a plugin:

import {readFileSync} from "fs"
import {resolve} from "url"
import {Plugin} from "kb2abot"

class MyPlugin extends Plugin {
	package = JSON.parse(
		readFileSync(new URL(resolve(import.meta.url, "package.json")))
	);

	// Called after this plugin is constructored (you would wrap your "async this.commands.add(command)" in this function in order to load commands in synchronous)
	async load() {
		// Add report command to this plugin
		await this.commands.add(reportCommand)
	}

	// Called when this plugin is disabled
	async onDisable() {}

	// Called when this plugin is enabled
	async onEnable() {}
}
const myPlugin = new MyPlugin()

And we add that plugin to a plugin manager

import {PluginManager} from "kb2abot"
const configDirectory = "./config"
const userdataDirectory = "./userdata" // relative to cwd
const pluginManager = new PluginManager(configDirectory, userdataDirectory)
await pluginManager.add(myPlugin)

Finally, now we add pluginManager to hook function:

import {Deploy, Datastore} from "kb2abot"
import {readHJSON} from "kb2abot/util/common"
Datastore.init("./datastores") // If you dont init datastore, your bot will be freeze and throw timeout error
const botOptions = readHJSON("./bot.hjson") // Read and parse bot.hjson file (relative to cwd)

botOptions is the options of your bot (see the example template at example-bot.hjson

const client = await Deploy.facebook(botOptions.credential, {
	apiOptions: botOptions.fcaOptions,
	pluginManager: pluginManager
})

All done! Now, imagine a user sending a message with body: "/report Hello admin", the bot will reply "Sent: Hello admin". Now you can code what you want and create a wonderful bot 🌟

Links

Contributing

Before creating an issue, please ensure that it hasn't already been reported/suggested See the contribution guide if you'd like to submit a PR.

Help

If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our community KB2A Community.