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

smsg

v1.1.31

Published

A simple library for constructing structured messages for the Messenger Platform Send API.

Downloads

18

Readme

smsg

Travis Code-Style:Standard License:MIT

smsg is a simple library for constructing structured messages (with attachments) for the Messenger Platform Send API.

smsg is a shortening of the term structured message

Use Cases

You can use smsg to quickly build:

  • button template attachments
  • generic template attachments
  • image attachments
  • postback buttons
  • web_url buttons

Installation

Installing smsg is as simple as installing any other npm module:

$ npm install smsg --save

Usage

Quick Example A: Build an image attachment

import smsg from 'smsg'

smsg.image('https://www.images.com/image-1.png')

Outputs the following message object:

{
  attachment: {
    type: 'image',
    payload: {
      url: 'https://www.images.com/image-1.png'
    }
  }
}

Quick Example B: Build button template attachment

import smsg from 'smsg'

smsg.button_template('What do you want?', [
  smsg.postback('See Products', 'SEE_PRODUCTS'),
  smsg.postback('Donate Money', 'DONATE'),
  smsg.web_url('See Website', 'https://www.example.com')
])

Outputs the following message object:

{
  attachment: {
    type: 'template',
    payload: {
      template_type: 'button',
      text: 'What do you want?',
      buttons: [
        {
          title: 'See Products',
          type: 'postback',
          payload: 'SEE_PRODUCTS'
        },
        {
          title: 'Donate Money',
          type: 'postback',
          payload: 'DONATE'
        },
        {
          title: 'See Website',
          type: 'web_url',
          url: 'https://www.example.com'
        }
      ]
    }
  }
}

Reference

smsg#button_template

Builds a button template attachment.

smsg.button_template(text, buttons)

| Parameter | Type | Description | Required |--- |--- |--- | --- | text | String | Text that appears in main body | Yes | buttons | Array | Set of buttons that appear as call-to-actions | Yes

smsg#generic_template

Builds a generic template attachment.

smsg.generic_template(elements)

| Parameter | Type | Description | Required |--- |--- |--- | --- | elements | Array | Data for each bubble in message | Yes

smsg#image

Builds an image attachment.

smsg.image(url)

| Parameter | Type | Description | Required |--- |--- |--- | --- | url | String | URL of image | Yes

smsg#postback

Builds a postback button.

smsg.postback(title, payload)

| Parameter | Type | Description | Required |--- |--- |--- | --- | title | String | Button title | Yes | payload | String | This data will be sent back to you via webhook | Yes

smsg#web_url

Builds a web_url button (link).

smsg.web_url(title, url)

| Parameter | Type | Description | Required |--- |--- |--- | --- | title | String | Button title | Yes | url | String | This URL is opened in a browser when the button is tapped | Yes

Contributing

Running Tests

First, install dev dependencies. Then, run npm test

$ npm install
$ npm test

Bug Reports & Feature Requests

Something does not work as expected or perhaps you think this module needs a feature? Please open an issue using GitHub's issue tracker. Please be as specific and straightforward as possible.

Developing

Pull Requests (PRs) are welcome. Make sure you follow the same basic stylistic conventions as the original code (i.e. "JavaScript standard code style")

License

The MIT License (MIT)

Copyright (c) 2016 Kristian Muñiz