1.1.31 • Published 8 years ago

smsg v1.1.31

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

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

1.1.31

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.61

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.0

8 years ago