New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

wa-chat-server-facebook

Package Overview
Dependencies
Maintainers
3
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wa-chat-server-facebook

wa-chat-server adapter for Facebook

  • 0.2.6
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-86.67%
Maintainers
3
Weekly downloads
 
Created
Source

wa-chat-server-facebook

wa-chat-server-facebook is a wa-chat-server adapter for the Facebook messenger.

Create Facebook Messenger App

  1. Go to https://developers.facebook.com/ and log in using your credentials
  2. Create new Messenger app and open it
  3. From the left panel go to Messenger / Settings
  4. In Access Tokens section add your Facebook page and generate token (1)
  5. In Webhooks section add your callback URL <APP_URL>/adapters/facebook and add a Verify token (2) which can be random value (ideally UUID)
  6. Add your Facebook page to this Webhook and add select messages and messaging_postbacks in the Edit page subscriptions dialog

Adapter Usage

Register The Adapter

An initialization of the wa-chat-server (in a chat application using wa-chat-server to communicate with Watson Assistant) with a wa-chat-server-facebook adapter looks like this:

require('dotenv').config();
import { WAChatServer, Types } from 'wa-chat-server';
import { WAChatServerFacebookAdapter } from 'wa-chat-server-facebook';
const server: WAChatServer = new WAChatServer((process.env as any) as Types.IWAChatServerConfig);
server.addAdapter('facebook', WAChatServerFacebookAdapter);
server.serve();

Configure The Adapter

We must set the following environment variables (e. g. in .env):

VariableObligatoryMeaning
adapter__facebook__facebookApiUrlYhttps://graph.facebook.com/v13.0/me/messages
adapter__facebook__facebookTokenYToken (1)
adapter__facebook__chatServerVerifyTokenYVerify token (2)
adapter__facebook__integrationSourceNSets value of context variable integration-source. Default value is facebook
adapter__facebook__replaceHtmlAnchorNIf set to true the adapter will replace html tags to plain text value
adapter__facebook__useSenderActionsNIf set to true the adapter will use mark_seen and typing_on sender actions when message is received (might generate additional API calls); If set to any other string (including false), it will be used as a context variable name and checked in incoming requests (refer to table below for examples);
Use Sender Actions Example Table
ConfigurationContextWill use sender actions?
undefined | nullanyN
trueanyY
disableSenderActions{ }Y
disableSenderActions{ disableSenderActions: null }Y
disableSenderActions{ disableSenderActions: false }Y
disableSenderActions{ disableSenderActions: true }N
disableSenderActions{ disableSenderActions: 'disabled' }N

Watson Assistant Response Support

  1. text - Text reply (interpreted as Text message)
  2. suggestion - Disambiguation (interpreted as Postback buttons)
  3. option - Options (interpreted as Postback buttons)

Local Development

HTTP Tunnel Setup

For local development we need to set up a secure tunnel localhost and Facebook. We can use ngrok for this purpose:

ngrok http 3023

opens a tunel and gives us a public HTTPS URL to be used by Facebook (without an ngrok account the lifetime of the tunnel will be 2 hours). We must then use the Meta for Developers to set the Callback URL:

We may inspect the communication tunneled by ngrok to localhost on http://localhost:4040.

Transpilation

Run

npm run dev

Linking The Library to The Chat Project

Run

npm link

from the wa-chat-server-facebook root folder.

and then

npm link wa-chat-server-facebook

from the root of your chat application.

Keywords

FAQs

Package last updated on 15 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc