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 🙏

© 2024 – Pkg Stats / Ryan Hefner

fb-messenger

v2.3.1

Published

Facebook Messenger Platform API

Downloads

172

Readme

fb-messenger npm npm npm

Facebook Messenger Platform NodeJS API Wrapper

js-standard-style Greenkeeper badge Codacy Badge Code Climate

Installation

Requires Node 8+

npm install fb-messenger --save

API

You must require fb-messenger and create an instance

// Constructor
const FBMessenger = require('fb-messenger')
const messenger = new FBMessenger({token, notificationType})
// token is optional, if not included, must be sent in each method, notificationType is optional, default = 'REGULAR'

messenger.setToken(token) // Sets the instance token

messenger.setNotificationType(notificationType) // Sets the instance notificationType

// Methods (notificationType and token are optional)
messenger.sendTextMessage({id, message, notificationType, token}) // Sends a text message

messenger.sendAudioMessage({id, url, notificationType, token}) // Sends an audio from URL

messenger.sendVideoMessage({id, url, notificationType, token}) // Sends an video from URL

messenger.sendImageMessage({id, url, notificationType, token}) // Sends an image from URL

messenger.sendFileMessage({id, url, notificationType, token}) // Sends an file from URL

messenger.sendQuickRepliesMessage({id, attachment, quickReplies, notificationType, token}) // Sends a Quick Replies Message

messenger.sendButtonsMessage({id, message, buttons, notificationType, token}) // Sends a buttons template message

messenger.sendGenericMessage({id, elements, notificationType, token}) // Sends a generic template message

messenger.sendListMessage({id, elements, buttons, top_element_type, notificationType, token}) // Sends a list template message

messenger.sendMediaMessage({id, elements, notificationType, token}) // Sends a media template message

messenger.sendOpenGraphMessage({id, elements, notificationType, token}) // Sends an open graph template message

messenger.sendReceiptMessage({id, payload, notificationType, token}) // Sends a receipt template message (No need for template_type in payload) 

messenger.sendAction({id, actionType, token}) // Send an action type (One of 'mark_seen', 'typing_on', 'typing_off')

messenger.sendMessage({id, data, notificationType, token}) // Send a message from custom data

messenger.getProfile({id, token}) // Gets user information

messenger.setWelcomeMessage({pageId, message, token}) // Sets Page's Welcome Message (message can be a text string or a strucuted message)

messenger.setGreetingText ({pageId, message, token}) // Sets Page's Greeting Text

messenger.setPersistentMenu ({pageId, menuItems, token}) // Set's Page's Persistent Menu

messenger.setDomainWhitelist ({pageId, domains, token}) // Set's Page's Whitelisted Domains 

messenger.sendThreadSettingsMessage ({pageId, body, token}) // Send Manually Page's Thread Settings

Notification Types:

  • REGULAR
  • SILENT_PUSH
  • NO_PUSH

Examples

Basic Example

const FBMessenger = require('fb-messenger')
const messenger = new FBMessenger({token: '<YOUR TOKEN>'}) // Will always use this page's token for request unless sent on each method

messenger.sendTextMessage({id: '<ID>', text: 'Hello'})

Catch errors Example

const FBMessenger = require('fb-messenger')
const messenger = new FBMessenger({token: '<YOUR TOKEN>'})

try {
  const response = await messenger.sendTextMessage({id: '<ID>', text: 'Hello'})
  console.log(response)
} catch (e) {
  console.error(e)
}

No push Example

const FBMessenger = require('fb-messenger')
const messenger = new FBMessenger({token: '<YOUR TOKEN>'})

messenger.sendTextMessage({id: '<ID>', text: 'Hello', notificationType: 'NO_PUSH'})

Default to silent push Example

const FBMessenger = require('fb-messenger')
const messenger = new FBMessenger({token: '<YOUR TOKEN>', notificationType: 'SILENT_PUSH'})

Complete Example

const FBMessenger = require('fb-messenger')
const messenger = new FBMessenger({token: '<YOUR TOKEN>', notificationType: 'NO_PUSH'})

try {
  await messenger.sendTextMessage({id: '<ID>', text: 'Hello'}) // Send a message with NO_PUSH, ignoring response
  console.log('Sent successfully')
} catch(e) {
  console.error(e)
}

// Send an image overriding default notification type with callback
try {
  const response = await messenger.sendImageMessage({id: '<ID>', url: '<IMG URL>', notificationType: 'REGULAR'})
  console.log('Sent image, response:')
  console.dir(response)
} catch(e) {
  console.error(e)
}

messenger.sendTextMessage({id: '<ID>', text: 'Hello', token: '<YOUR OTHER TOKEN>'}) // Send message on another page

License

MIT. Copyright © Diego Rodríguez Baquero