Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexindigo/fbbot
Minimal framework/SDK for facebook messenger bots. BYOS (Bring Your Own Server)
https://github.com/alexindigo/fbbot
byos facebook facebook-messenger-bot fb-bot framework messenger-platform minimal nodejs sdk
Last synced: 24 days ago
JSON representation
Minimal framework/SDK for facebook messenger bots. BYOS (Bring Your Own Server)
- Host: GitHub
- URL: https://github.com/alexindigo/fbbot
- Owner: alexindigo
- License: mit
- Created: 2016-07-23T16:44:11.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-09-03T23:26:51.000Z (about 4 years ago)
- Last Synced: 2024-04-27T01:03:49.969Z (7 months ago)
- Topics: byos, facebook, facebook-messenger-bot, fb-bot, framework, messenger-platform, minimal, nodejs, sdk
- Language: JavaScript
- Homepage: https://npmjs.com/fbbot
- Size: 93.8 KB
- Stars: 47
- Watchers: 4
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fbbot [![NPM Module](https://img.shields.io/npm/v/fbbot.svg?style=flat)](https://www.npmjs.com/package/fbbot)
Minimal framework/SDK for facebook messenger bots. BYOS (Bring Your Own Server).
[![[email protected]](https://img.shields.io/badge/messenger_platform-v1.2-brightgreen.svg?style=flat)](https://developers.facebook.com/docs/messenger-platform)
[![Linux Build](https://img.shields.io/travis/alexindigo/fbbot/master.svg?label=linux:0.12-6.x&style=flat)](https://travis-ci.org/alexindigo/fbbot)
[![MacOS Build](https://img.shields.io/travis/alexindigo/fbbot/master.svg?label=macos:0.12-6.x&style=flat)](https://travis-ci.org/alexindigo/fbbot)
[![Windows Build](https://img.shields.io/appveyor/ci/alexindigo/fbbot/master.svg?label=windows:0.12-6.x&style=flat)](https://ci.appveyor.com/project/alexindigo/fbbot)[![Coverage Status](https://img.shields.io/coveralls/alexindigo/fbbot/master.svg?label=code+coverage&style=flat)](https://coveralls.io/github/alexindigo/fbbot?branch=master)
[![Dependency Status](https://img.shields.io/david/alexindigo/fbbot/master.svg?style=flat)](https://david-dm.org/alexindigo/fbbot)
[![bitHound Overall Score](https://www.bithound.io/github/alexindigo/fbbot/badges/score.svg)](https://www.bithound.io/github/alexindigo/fbbot)[![express](https://img.shields.io/badge/express-tested-brightgreen.svg?style=flat)](http://expressjs.com)
[![hapi](https://img.shields.io/badge/hapi-tested-brightgreen.svg?lstyle=flat)](http://hapijs.com)
[![restify](https://img.shields.io/badge/restify-tested-brightgreen.svg?style=flat)](http://restify.com)
[![http](https://img.shields.io/badge/http-tested-brightgreen.svg?style=flat)](https://nodejs.org/api/http.html)## Install
```
npm install --save fbbot
```## Table of Contents
- [Examples](#examples)
- [Listening for messages](#listening-for-messages)
- [Adding middleware](#adding-middleware)
- [Sending messages to user](#sending-messages-to-user)
- [Logging](#logging)
- [API](#api)
- [Fbbot#use](#fbbotuse)
- [Fbbot#on](#fbboton)
- [Fbbot#send](#fbbotsend)
- [Convenience Methods](#convenience-methods)
- [`send.message`](#sendmessage)
- [`send.markSeen`](#sendmarkseen)
- [`send.typingOn`](#sendtypingon)
- [`send.typingOff`](#sendtypingoff)
- [`send.text`](#sendtext)
- [`send.image`](#sendimage)
- [`send.audio`](#sendaudio)
- [`send.video`](#sendvideo)
- [`send.file`](#sendfile)
- [`send.generic`](#sendgeneric)
- [`send.button`](#sendbutton)
- [`send.receipt`](#sendreceipt)
- [`send.quickReplies`](#sendquickreplies)
- [Message Types](#message-types)
- [`MESSAGE`](#message)
- [`MARK_SEEN`](#mark_seen)
- [`TYPING_ON`](#typing_on)
- [`TYPING_OFF`](#typing_off)
- [`TEXT`](#text)
- [`IMAGE`](#image)
- [`AUDIO`](#audio)
- [`VIDEO`](#video)
- [`FILE`](#file)
- [`GENERIC`](#generic)
- [`BUTTON`](#button)
- [`RECEIPT`](#receipt)
- [`QUICK_REPLIES`](#quick_replies)
- [Hooks](#hooks)
- [Incoming](#incoming)
- [Outgoing](#outgoing)
- [Roadmap](#roadmap)
- [License](#license)## Examples
### Listening for messages
```javascript
// also works with `hapi`, `restify` and built-in `http`
var express = require('express');
var Fbbot = require('fbbot');var app = express();
var fbbot = new Fbbot({token: '...', secret: '...'});// plug-in fbbot
// It will also listen for GET requests to authorize fb app.
app.all('/webhook', fbbot.requestHandler);
// assuming HTTPS is terminated elsewhere,
// or you can use standard express https capabilities
app.listen(8080);// catching messages
fbbot.on('message', function(message, send)
{
// message.type <-- type of the message (text, attachment, quick_reply, sticker, etc)
// message.user <-- user object
// message.text <-- text for text messages
// message.attachments <-- list of attachments if available
// send <-- send method with baked in user.id `send(fbbot., , )`
});// handle only text messages
fbbot.on('message.text', function(message, send)
{
// message.user <-- user object
// message.text <-- text for text messages
// send <-- send method with baked in user.id `send(fbbot., , )`
});fbbot.on('postback', function(postback, send)
{
// postback.user <-- user object
// postback.payload <-- parsed payload
// send <-- send method with baked in user.id `send(fbbot., , )`
});
```Check out [test folder](test/fixtures) for available options.
### Adding middleware
```javascript
var express = require('express');
var Fbbot = require('fbbot');var app = express();
var fbbot = new Fbbot({token: '...', secret: '...'});// plug-in fbbot
app.all('/webhook', fbbot.requestHandler);
// assuming HTTPS is terminated elsewhere,
// or you can use standard express https capabilities
app.listen(8080);fbbot.use('message', function(payload, callback)
{
// do something with the payload, async or sync
setTimeout(function()
{
payload.fooWasHere = true;
// pass it to callback
callback(null, payload);
}, 500);
});// catching messages
fbbot.on('message', function(message, send)
{
// modified message payload
message.fooWasHere; // true
});```
More middleware examples could be found in [incoming](incoming/) folder.
### Sending messages to user
Here are two ways of sending messages, using per-instance fbbot.send method,
or the one tailored to the user, provided to the event handlers.```javascript
var express = require('express');
var Fbbot = require('fbbot');var app = express();
var fbbot = new Fbbot({token: '...', secret: '...'});// plug-in fbbot
app.all('/webhook', fbbot.requestHandler);
// assuming HTTPS is terminated elsewhere,
// or you can use standard express https capabilities
app.listen(8080);// "standalone" send function
// send reguar text message
fbbot.send(1234567890, fbbot.TEXT, 'Hi there!', function(error, response)
{
// error