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: 4 months 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 (over 4 years ago)
- Last Synced: 2024-04-27T01:03:49.969Z (10 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 [](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)
[](https://travis-ci.org/alexindigo/fbbot)
[](https://travis-ci.org/alexindigo/fbbot)
[](https://ci.appveyor.com/project/alexindigo/fbbot)[](https://coveralls.io/github/alexindigo/fbbot?branch=master)
[](https://david-dm.org/alexindigo/fbbot)
[](https://www.bithound.io/github/alexindigo/fbbot)[](http://expressjs.com)
[](http://hapijs.com)
[](http://restify.com)
[](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