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

messenger-bot-utils

v0.1.0

Published

Utilities to generate Facebook Messenger messages

Downloads

1

Readme

messenger-bot-utils

Generic utilities to streamline the creation of Facebook Messenger bots.

Installation

Install from npm:

npm install messenger-bot-utils

The utilities in this package are broken up into several modules:

import {
  Attachments,
  Buttons,
  Templates,
} from 'messenger-bot-utils';

Usage

Attachment Generators

These are generator functions for creating the JSON structure for text, audio, file, image, and video attachments.

import { Attachments } from 'messenger-bot-utils';
// Returns a JSON object formatted for a text message
Attachments.makeText('some message here');
// Returns a JSON object formatted for an audio attachment
Attachments.makeAudio('AUDIO_URL');
// Returns a JSON object formatted for a file attachment
Attachments.makeFile('FILE_URL');
// Returns a JSON object formatted for an image attachment
Attachments.makeImage('IMAGE_URL');
// Returns a JSON object formatted for a video attachment
Attachments.makeVideo('VIDEO_URL');

Buttons Generators

These are generator functions for creating the JSON structure for buttons.

import { Buttons } from 'messenger-bot-utils';
// Returns a JSON object formatted for a web url button
Buttons.webURL('BUTTON_TITLE', 'WEB_URL');
// Returns a JSON object formatted for a postback button
Buttons.postback('BUTTON_TITLE', 'POSTBACK_PAYLOAD');
// Returns a JSON object formatted for a phone number button, number needs to be formatted as '+15105555555'
Buttons.phone('BUTTON_TITLE', 'FORMATTED_PHONE_NUMBER');
// Returns a JSON object formatted for a share button
Buttons.share();
// Returns a JSON object formatted for a login button
Buttons.login('LOGIN_URL');
// Returns a JSON object formatted for a logout button
Buttons.logout();

Templates Generators

These are generator functions for creating the JSON structure for templates.

import { Templates } from 'messenger-bot-utils';
// Returns a JSON object formatted for a button template, takes a string and an array of button objects
Templates.button('PROMPT_TEXT', [BUTTONS_ARRAY]);
// Returns a JSON object formatted for a generic template, takes an array of element objects, up to 10
Templates.generic([ELEMENTS_ARRAY]);
// Returns a JSON object formatted for a large list template, takes an array of between 2 and 4 element objects, and an optional array of a single button object
Templates.list([ELEMENTS_ARRAY], [BUTTON_OBJECT]);
// Returns a JSON object formatted for a compact list template, takes an array of between 2 and 4 element objects, and an optional array of a single button object
Templates.compactList([ELEMENTS_ARRAY], [BUTTON_OBJECT]);
// Returns a JSON object formatted for a generic element, takes a config object with a `title` key, and optional keys for `subtitle`, `image_url`, `default_action` object, and `buttons` array of buttons.
Templates.makeGenericElement({CONFIG_OBJ});
// Returns a JSON object formatted for a list element, takes a config object with a `title` key, and optional keys for `subtitle`, `image_url`, `default_action` object, and `buttons` array of buttons.
Templates.makeListElement({CONFIG_OBJ});