New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

smsg

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smsg

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

  • 1.1.31
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-64.29%
Maintainers
1
Weekly downloads
 
Created
Source

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)
ParameterTypeDescriptionRequired
textStringText that appears in main bodyYes
buttonsArraySet of buttons that appear as call-to-actionsYes
smsg#generic_template

Builds a generic template attachment.

smsg.generic_template(elements)
ParameterTypeDescriptionRequired
elementsArrayData for each bubble in messageYes
smsg#image

Builds an image attachment.

smsg.image(url)
ParameterTypeDescriptionRequired
urlStringURL of imageYes
smsg#postback

Builds a postback button.

smsg.postback(title, payload)
ParameterTypeDescriptionRequired
titleStringButton titleYes
payloadStringThis data will be sent back to you via webhookYes
smsg#web_url

Builds a web_url button (link).

smsg.web_url(title, url)
ParameterTypeDescriptionRequired
titleStringButton titleYes
urlStringThis URL is opened in a browser when the button is tappedYes

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

Keywords

FAQs

Package last updated on 07 Jul 2016

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