Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bot-messenger-node

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bot-messenger-node

A Node.js toolkit facilitating the seamless incorporation and effective deployment of the Messenger API in crafting responsive chatbots.

  • 1.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

bot-messenger-node

npm version

NPM
downloads

Node Wrapper to various APIs from Facebook Messenger Platform.

Features

Send API (v18.0)

  • Send text messages
  • Send attachments from a remote file (image, audio, video, file)
  • Send attachments from a local file (image, audio, video, file)
  • Send templates (generic messages)
  • Send quick replies
  • Send buttons

Profile API (v18.0)

  • Set welcome screen
  • Set persistent menu

Attachment Upload API (v16.0)

  • Upload attachments from a remote file (image, audio, video, file)
  • Upload attachments from a local file (image, audio video, file)

Reusable components

Various components used when sending messages in Facebook Messenger are wrapped into Python objects to make them reusable and easy to use.

  • Elements: used to contains various Element objects
  • Element: a card-like component that holds various other components
  • Buttons: used to contains various Button objects
  • Button: button used in various other components, can also be used alone
  • QuickReplies: used to contains various QuickReply objects
  • QuickReply: used when sending messages accompanied with quick replies
  • PersistentMenu: used when setting up persistent menu

How to install

From Npm

npm install bot-messenger-node

Usage

Send API

const { SendApi } = require('bot-messenger-node');

const sendApi = new SendApi('<page_access_token>');
const message = '<message>';
const recipientId = '<recipient_id>';

sendApi.send_text(message, recipientId)

Note: From Facebook regarding User IDs

These ids are page-scoped. These ids differ from those returned from Facebook Login apps which are app-scoped. You must use ids retrieved from a Messenger integration for this page in order to function properly.

Sending a generic template message:

Generic Template Messages allows you to add cool elements like images, text all in a single bubble.

const { SendApi, Elements, Element, Buttons, Button, POSTBACK } = require('bot-messenger-node');

const sendApi = new SendApi('<page_access_token>');

const elements = new Elements();
const buttons = new Buttons();

const button = new Button(POSTBACK, "My button");
buttons.add_button(button.getContent());

const element = new Element("My element", "The element's subtitle", '<image_url>', buttons.get_content());
elements.add_element(element.getContent());

sendApi.send_generic(elements.getContent(), '<recipient_id>')

Sending remote (from URL) image/audio/video/file:
const SendApi = require('bot-messenger-node');

const sendApi = new SendApi('<page_access_token>');

// To send an image
sendApi.send_image('<image_url>', '<recipient_id>')

// To send an audio
sendApi.send_audio('<audio_url>', '<recipient_id>')

// To send a video
sendApi.send_video('<video_url>', '<recipient_id>')
// To send a file
sendApi.send_file('<file_url>', '<recipient_id>')

To do

  • Clarify this docs

Keywords

FAQs

Package last updated on 25 Feb 2024

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