PYYUPSK

a self-taught dev from Thailand

Pongsakorn Thipayanate · Samutsakhon, TH ·webring

maintained

Messenger Webhooks

A Node.js library for building Facebook Messenger chatbots, with an event-driven webhook API.

TypeScript / Express / npm / Messenger API· 2024

GitHub →Website →

view .mdopen in claudeopen in chatgpt

A TypeScript library for building Facebook Messenger chatbots. It uses an event-driven design on top of Express. It includes full type definitions and a simple API. You use the API to handle incoming events and send messages.

Why this exists

Building Messenger chatbots usually means you must handle webhook verification, event parsing, and message sending yourself. This library handles all of that behind a typed API. You can then focus on your bot’s logic instead of this background setup work.

Features

  • Event-driven: You handle messages, posts, and other events with simple listeners.
  • Full TypeScript support: The library has complete type definitions for all API responses.
  • Express integration: The library uses Express under the hood for webhook handling.
  • Simple API: You can send text, images, and other message types with minimal code.

Usage

import { Bot, MessageEvent } from "@pyyupsk/messenger-webhooks";

const bot = new Bot({
  accessToken: "YOUR_ACCESS_TOKEN",
  verifyToken: "YOUR_VERIFY_TOKEN",
});

bot.on("message", (event: MessageEvent) => {
  const { sender, message } = event;
  bot.sendTextMessage(sender.id, `You wrote: ${message.text}`);
});

bot.start();

Getting started

  1. Create a Facebook App and generate your access token.
  2. Set up webhook verification in the Facebook Developer Portal.
  3. Deploy your bot with the required environment variables.

← All projects