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 🙏

© 2024 – Pkg Stats / Ryan Hefner

facebook-messenjs

v0.1.3

Published

API wrapper for Facebook Messenger inspired by discord.js

Downloads

7

Readme

Facebook MessenJS

Facebook MessenJS is an API wrapper for Facebook Messenger inspired by discord.js. This library allows you to interact with Facebook Messenger's API. The bot was programmed with an object-oriented approach so that people can program their Facebook Messenger chatbots with ease.

Installation

npm i facebook-messenjs

Example Usage

Create a simple quick example bot:

const { Client } = require('facebook-messenjs');

const bot = new Client({
    pageToken: "PAGE_TOKEN_FROM_FACEBOOK",
    verifyToken: "YOUR_VERIFY_TOKEN",
    appID: "APP_ID_FROM_FACEBOOK"
});

// Allows Facebook to know that you set the URL of the bot properly
bot.on('webhookVerify', verification => {
    if (verification.success) {
        console.log("Webhook verified with Facebook successfully!");
    } else {
        console.log("Webhook verified with Facebook failed! ;-;");
    }
});

// Processes messages from people who message the Facebook page
bot.on("messages", message => {
    message.sender.send("Hi!");
});

// Turns on the bot at port 5566
bot.listen(5566, () => {
    console.log(`Facebook Messenger chatbot listening at http://localhost:${bot.port}`);
});

Create text quick replies:

const { Client, TextQuickReply } = require('facebook-messenjs');
bot.on('messages', message => {
    if (!message.payload) { // Checks if the message has a payload
        message.sender.send("Hi! What is your favorite color?", [
            new QuickReplies.Text("Red", "RESPONSE_RED"),
            new QuickReplies.Text("Yellow", "RESPONSE_YELLOW"),
            new QuickReplies.Text("Others", "RESPONSE_OTHERS")
        ]);
    } else {
        // Responds appropriately to payloads
        switch (message.payload) {
            case "RESPONSE_RED":
                message.sender.send("Red? Me too!");
            break;
            case "RESPONSE_OTHERS":
                message.sender.send("Yellow? That's a nice color!");
            break;
            default:
                message.sender.send("I like that color too.");
        }
    }
});

Set persistent menu:

const { Client, PostbackButton } = require('facebook-messenjs');
bot.on('messagingPostback', postback => {
    if (postback.payload === "GET_STARTED") {
        postback.sender.setPersistentMenu([
            new PostbackButton("Button 1", "PAYLOAD_ONE"),
            new PostbackButton("Button 2", "PAYLOAD_TWO")
        ]);
    }
});

Send pictures:

const { Client, BaseAttachment } = require('facebook-messenjs');
const picture = new BaseAttachment(bot, "image", {
    content: "./picture.png",
    reusable: true
});

bot.on("messages", message => {
    message.sender.send(picture);
});