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 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-red-contrib-facebook-messenger-writer-2

v4.4.1

Published

A node to write output to Facebook Messenger

Downloads

121

Readme

Node-RED Contrib Facebook Messenger Writer - Version 2

Node-RED node that sends a message to Facebook Messenger.

Install

Run the following command in the root directory of your Node-RED install:

    npm install node-red-contrib-facebook-messenger-writer-2

Usage

This node sends messages from your Facebook page, for this you need the Access Token. To do that it needs a recipient id (which is normally the sender id from a message received) and an Access Token (something that you set up when you follow the Facebook Messenger Developers Quick Start Guide).

The message to send should be set in msg.payload. If msg.payload is a string, the string will be sent as the message. If msg.payload is an object, the object will be sent unaltered.

The node needs an ID to send the return message. As the recipient for the response is normally the sender of the original message, msg.facebookevent can be set to the incoming message. The node will use the sender ID as the recipient ID for the return.

eg.

msg.facebookevent = {
    "sender": { "id": "111111111111" },
    "recipient": { "id": "222222222222" },
    "timestamp": 1478167276278,
    "message": {
        "mid": "mid.1478167276278:684dd80866",
        "seq": 6,
        "text": "Hello Mr Bot"
      }
};

Although only the following is needed by the node.

msg.facebookevent = {
    "sender": { "id": "111111111111" }
};

The Node needs needs the Access Token, that facebook sets up for you to use. This is set in the Node's configuration.

Registering your GET with Facebook

There is no receiver node, as this can be readily accomplished using the standard HTTP Node-RED nodes. When following the Quick Start Guide, you can set a GET HTTP in node for the registration. The entry point you use is upto you. eg.

  \mybot\xyz

This GET should check that the correct Access Token (which you specify when following the quick star guide) and echo back the challenge as sent by facebook.

eg:

  var mode = '';
  var vtoken = '';
  var challenge = '';
  if (msg.payload['hub.mode']) {
      mode = msg.payload['hub.mode'];
  }
  if (msg.payload['hub.verify_token']) {
      vtoken = msg.payload['hub.verify_token'];
  }
  if (msg.payload['hub.challenge']) {
    challenge = msg.payload['hub.challenge'];
  }
  if ('subscribe' == mode &&
    'ThisStringShouldBeUniqueToYouRepresentsYourVerifyToken' == vtoken) {
      msg.payload = challenge;
    }

Receiving Messages (POST) from Facebook

Once registered you can create a POST HTTP in for incoming messages. The entry point should match your registration entry point eg.

  \mybot\xyz

It's upto you how you handle the incoming message, but this is a sample handling function that you can build your logic on.

if (msg.payload.object && 'page' == msg.payload.object) {
    msg.processAS = 'NOTHING';
    if (msg.payload.entry){
        var entry = msg.payload.entry;

        for (var i = 0; i < entry.length; i++) {
            //console.log(myArray[j].x);
            var pageID = entry[i].id;
            var timeOfEvent = entry[i].time;
            var messaging = entry[i].messaging
            for (var j =0; j < messaging.length; j++) {
                if (messaging[j].optin) {
                    msg.processAS = 'AUTHENTICATION';     
                } else if (messaging[j].message) {
                  if(messaging[j].message.attachments) {
                      if(messaging[j].message.attachments[0].type == "location") {
                          msg.processAS = 'LOCATION';
                      } else {
                          msg.processAS = 'OTHER';
                      }
                  } else {
                      msg.processAS = 'MESSAGE';
                  }
                } else if (messaging[j].delivery) {
                    msg.processAS = 'DELIVERY';
                } else if (messaging[j].postback) {
                    msg.processAS = 'POSTBACK';
                }
                msg.messagingEvent = messaging[j];
                node.send([msg,null]);               
            }
        }
    }
}
return [null,msg];

Contributing

For simple typos and fixes please just raise an issue pointing out our mistakes. If you need to raise a pull request please read our contribution guidelines before doing so.

Copyright and license

Copyright 2021 IBM Corp. under the Apache 2.0 license.