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

ebony-messenger-adapter

v2.0.4

Published

Facebook SendAPI Library for the Ebony framework.

Downloads

93

Readme

Ebony Messenger Adapter

A messenger platform adapter for the Ebony Framework

Documentation

!!! This documentation might be outdated. It will be updated soon !!!

Message

Create a message

Available Options:

  • text: Message text. Previews will not be shown for the URLs in this field. Use attachment instead. Must be UTF-8 and has a 2000 character limit. Text or attachment must be set.
  • attachment: Attachment object. Previews the URL. Used to send messages with media or Structured Messages. Text or attachment must be set.
  • quickreplies: Optional. Array of QuickReply to be sent with messages
  • metadata: Not yet implemented (TODO)

Text Message

Without Quick Replies
const options = {
    text: "Hello World"
};

const message = new Message(options);
With Quick Replies
const options = {
    text: "Hello World",
    quickreplies: [
        new TextQuickReply("Hello", "hello"),
        new LocationQuickReply()
    ]
};

const message = new Message(options);

Attachment Message

The following can be included in the attachment object:

  • Rich media messages including images, audios (TODO), videos (TODO), or files (TODO).
  • Templates including generic template, button template, receipt template (TODO), or list template.
const options = {
    attachment: new GenericTemplate({
        elements: [
                cardElement({
                    title: "Test",
                    subtitle: "Test"
                    buttons: [new UrlButton("Test", "Test")]
                }),
                cardElement({
                    title: "Test",
                    subtitle: "Test"
                    buttons: [new UrlButton("Test", "Test")]
                })
        ]
    })
};

const message = new Message(options);

Quick Replies

The following quick reply types are supported:

  • Text
  • Location
  • Phone Number (Not Implemented: TODO)
  • Email (Not Implemented: TODO)

Text Quick Replies

Params:

  • title: The text to display on the quick reply button. 20 character limit.
  • payload: Custom data that will be sent back to you via the messaging_postbacks webhook event. 1000 character limit. May be set to an empty string if image_url is set (not implemented).
// With text payload
new TextQuickReply("Title", "payload");

// With object payload
new TextQuickReply("title", { hello: "world" });

Location Quick Replies

Sends a button to collect the recipient's location

new LocationQuickReply()

Attachments

Image Attachment

Sends the image specified in the URL

new ImageAttachment("http://example.com/image.png");

Templates

ButtonTemplate

Params:

  • text: UTF-8-encoded text of up to 640 characters. Text will appear above the buttons.
  • buttons: Set of 1-3 buttons that appear as call-to-actions. (Array of Button)
new ButtonTemplate("Hello World", [
    new PostbackButton("Test", "test"),
    new UrlButton("Test", "http://example.com"),
    new CallButton("+3012345689")
]);
List Template

Options:

  • elements: Array of listElement. Minimum of 2 elements required. Maximum of 4 elements is supported.
  • buttons: Button to display at the bottom of the list. Maximum of 1 button is supported. (Array of Button)
  • large: Sets the format of the first list items. Messenger web client currently only renders compact. compact (false): Renders a plain list item. large (true): Renders the first list item as a cover item.
new ListTemplate({
    elements: [
        listElement({
            title: "Test",
            subtitle: "test",
            buttons: [new PostbackButton("Test", "test")]
        }),
        listElement({
            title: "Test",
            subtitle: "test",
            buttons: [new PostbackButton("Test", "test")]
        }),
        listElement({
            title: "Test",
            subtitle: "test",
            buttons: [new PostbackButton("Test", "test")]
        }),
        listElement({
            title: "Test",
            subtitle: "test",
            buttons: [new PostbackButton("Test", "test")]
        })
    ],
    buttons: [new PostbackButton("Test", "test")],
    large: false
});

listElement params:

  • title: String to display as the title of the list item. 80 character limit. May be truncated if the title spans too many lines. Element must also have one or both of image_url or subtitle set.
  • subtitle: String to display as the subtitle of the list item. 80 character limit. May be truncated if the subtitle spans too many lines. Element must have one or both of image_url or subtitle set.
  • image_url: URL of the image to display in the list item. Element must have one or both of image_url or subtitle set.
  • buttons: Button to display on the list item. Maximum of 1 button is supported (Array of Button)
  • default_action: URL button that specifies the default action to execute when the list item is tapped. Only allowed when messenger_extensions property is set to true. (Wrongly Implemented: TODO)
Generic Template

Params:

  • elements: An array of element objects that describe instances of the generic template to be sent. Specifying multiple elements will send a horizontally scrollable carousel of templates. A maximum of 10 elements is supported. (Array of cardElement)
  • image_aspect_ratio: The aspect ratio used to render images specified by element.image_url. Must be horizontal (1.91:1) or square (1:1). Defaults to horizontal.
new GenericTemplate([
    cardElement({
        title: "Test",
        subtitle: "Test",
        buttons: [new PostbackButton("Test", "test")]
    }),
    cardElement({
        title: "Test",
        subtitle: "Test",
        buttons: [new PostbackButton("Test", "test")]
    }),
    cardElement({
        title: "Test",
        subtitle: "Test",
        buttons: [new PostbackButton("Test", "test")]
    })
], "horizontal")

cardElement params:

  • title: The title to display in the template. 80 character limit.
  • subtitle: The subtitle to display in the template. 80 character limit.
  • image_url: The URL of the image to display in the template.
  • buttons: An array of buttons to append to the template. A maximum of 3 buttons per element is supported. (Array of Button)
  • default_action: The default action executed when the template is tapped. Accepts the same properties as URL button, except title (Wrongly Implemented TODO).

Buttons

URL Button

new UrlButton("Title", "http://example.com");

Postback Button

new PostbackButton("Title", "payload");

Share Button

Params:

  • share_contents: The message that you wish the recipient of the share to see, if it is different from the one this button is attached to. The format follows that used in Send API. (Generic Template)

share_contents only supports the following:

Template used must be Generic Template. Maximum of one URL button on the template. If no buttons are specified, the buttons property on the generic template must be set to an empty array.

new ShareButton(share_contents);

Call Button

new CallButton("Test", "+301234567891");

Sender

Params:

  • fb: The sending library used. Must have a sendAPI property.

Returns:

The send function.

const send = sender(fb);

Send Function

Params:

  • id: The PSID of the user
  • message: A Message Object
  • options: The next object
{
    tag,                // The message tag string.  
    notification_type,  // Push notification type (REGULAR, SILENT_PUSH, NO_PUSH)
    type                // The messaging type of the message being sent.
}

Example:

send(id, message, options);