1.10.8 • Published 14 days ago

flowai-js-templates v1.10.8

Weekly downloads
58
License
ISC
Repository
github
Last release
14 days ago

The Flow.ai JavaScript Response Templates

Easy helper classes to create rich flow.ai response templates like cards, buttons and locations.

Reponse templates allow developers to render widgets at channels that support this like Facebook Messenger or the flow.ai Web client.

What can you do?

  • No need to write error prone JSON
  • Full support for all template types

Getting started

All classes are available for usage with Flow.ai Cloud functions. When you want to send rich responses using a webhook, install the library with NPM.

Install

npm install --save flowai-js-templates

Usage

When using Flow.ai cloud code there is no need to require or import anything.

const { Card } = require('flowai-js-templates')

const card = new Card({
  title: "Cookie factory",
  subtitle: "Infinite lane 23"
})

Sending back rich messages

You can send back rich messages in 3 different ways

Cloud code

Within a cloud code function you can directly send back messages by returning them from your function.

Sending a single message with a single response
async payload=> {

  // Create a generic speech bubble
  const text = new Text("Hi there!")

  // Create a generic message with fallback text
  const message = new Message("Hi, there")
  message.addResponse(text)

  return message
}
Sending a single message with multiple responses
async payload=> {

  // Create a generic speech bubble
  const text = new Text("Hi there!")

  // Create a Google Business Messages specific card
  const card = new GBM.Card({
    title: "Cookie factory",
    description: "Infinite lane 23"
  })

  return new Message("Hi, the address of the Cookie factory is Infinite lane 23")
          .addResponse(text)
          .addResponse(card)
}
Sending back multiple messages
async payload=> {

  // Create a generic speech bubble
  const text = new Text("Hi there!")

  // Create a generic card
  const card = new Card({
    title: "Cookie factory",
    subtitle: "Infinite lane 23"
  })

  return [
    new Message("Hi, there").addResponse(text),
    new Message("the address of the Cookie factory is Infinite lane 23").addResponse(card)
  ]
}

Channel specific

We support a number of generic components that render on most channels. For example a Card element works for both Facebook Messenger and the Flow.ai Web Widget.

However, there are specific components as well for channels like Apple Business Chat or an IVR Bot.

You can create and send these as well. The following example shows how to create and send a Time Picker for Apple Business chat.

async payload=> {
  const timePicker = new Apple.TimePicker({
    receivedMessage: new Apple.InteractiveMessage({
      title: "Schedule an Appointment",
      subtitle: "We'll see you there!",
      style: "icon"
    }),
    replyMessage: new Apple.InteractiveMessage({
      title: "Your Appointment",
      style: "icon"
    }),
    event: new Apple.EventItem({
      title: "Some event",
      location: new Apple.LocationItem({
        latitude: 37.7725,
        longitude: -122.4311,
        radius: 100,
        title: "Some venue"
      }),
      timeslots: [
        new Apple.TimeItem({
          duration: 60,
          startTime: "2020-05-26T08:27:55+00:00"
        }),
        new Apple.TimeItem({
          duration: 60,
          startTime: "2020-05-26T09:27:55+00:00"
        }),
        new Apple.TimeItem({
          duration: 60,
          startTime: "2020-05-26T10:27:55+00:00"
        })
      ],
      timezoneOffset: 2
    })
  })

  return new Message('Time picker').addResponse(timePicker)
}

For a complete overview of all reply actions see the Flow.ai documentation site.


Reply Templates Reference

Each reply being sent is part of a message.

Base.Message

The base representation of a message to a user. Contains a pronounceable fallback message and optional rich Template responses.

Properties

NameTypeDescription
fallbackstringPronounceable and represents the responses as a whole
responsesArray.<Template>List of rich Template responses

new Message(fallback, meta)

Example

// Create a message without responses
// this will create a response
// when converted to JSON
const message = new Message('Hi there')

// This also works for multiple text responses by adding an array of strings
const message = new Message(['Hi there', 'How can I help?'])
ParamTypeDescription
fallbackstringRequired
metaObjectOptional property list with data

message.addResponse(response)

Add a response

ParamTypeDescription
responseTemplateresponse

Generic

We provide a collection of generic message templates that can be sent to any messaging channel. These generic templates are transformed into specific channel counter parts. They provide a convenient way to reply with a single message to multiple channels.

Message

Inherits from Message.

message.addQuickReply(quickReply)

A convenience method to add a quick reply to the last response template of a Message

Example

const message = new Message("Want a cold beverage?")
 .addQuickReply(new QuickReply({
   label: 'Yes'
 }))
 .addQuickReply(new QuickReply({
   label: 'No'
 }))
ParamTypeDescription
quickReplyQuickReplyRequired

message.addSuggestedAction(suggestedAction)

A convenience method to add a Suggested Action to the last response template of a Message

Example

const message = new Message("Put on some music please!")
 .addSuggestedAction(new SuggestedAction({
   "label": "test with code action",
   "type": "calendar_action",
   "title": "Party at Imran's",
   "description": "party tonight",
   "startTime": "2023-04-27T23:30",
   "endTime": "2023-04-28T04:30",
   "timezone": "(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi"
 }))
ParamTypeDescription
suggestedActionSuggestedActionRequired

Text

The simplest messages are made of text. Text messages are best suited to communicate information without the need for visuals, complex interaction, or response.

Properties

NameTypeDescription
textstringText to show

new Text()

Example

const text = new Text('Want a free soda?')
text.addQuickReply(new QuickReply({
  label: 'Yes',
  value: 'yes'
}))
text.addQuickReply(new QuickReply({
  label: 'No',
  value: 'no'
}))
ParamTypeDescription
opts.textstringRequired

Image

Deliver an image to a user. Optionally you can specify an Action to perform when a user interacts with the image. Note: This is not supported on all channels.

Properties

NameTypeDescription
titlestringDescribes the image
urlstringURL to the image
actionActionOptional Action

new Image()

Example

const image = new Image({
  title: "Awesome title",
  url: "https://...",
  action: new Action({
    type: 'url',
    value: 'https://...'
  })
})
ParamTypeDescription
opts.titlestringRequired
opts.urlstringRequired
opts.actionstringOptional Action

File

Deliver a file to a user. Optionally you can specify an Action to perform when a user interacts with the file. Note: This is not supported on all channels.

Properties

NameTypeDescription
titlestringDescribes the file
urlstringURL to the file
actionActionOptional Action

new File()

Example

const file = new File({
  title: "Awesome title",
  url: "https://...",
  action: new Action({
    type: 'url',
    value: 'https://...'
  })
})
ParamTypeDescription
opts.titlestringOptional
opts.urlstringRequired
opts.actionstringOptional Action

Video

Deliver a video to a user or show a video player. Optionally you can specify an Action to perform when a user interacts with the video. Note: This is not supported on all channels.

Properties

NameTypeDescription
titlestringDescribes the video
urlstringURL to the video
actionActionOptional Action

new Video(opts)

Example

const video = new Video({
  title: "Awesome title",
  url: "https://...",
  action: new Action({
    type: 'url',
    value: 'https://...'
  })
})
ParamTypeDescription
optsobject
opts.titlestringRequired
opts.urlstringRequired
opts.actionstringOptional
opts.thumbnailUrlstringOptional

Audio

Send an audio file or show an audio player to a user. Optionally you can specify an Action to perform when a user interacts with the audio. Note: This is not supported on all channels.

Properties

NameTypeDescription
titlestringDescribes the audio
urlstringURL to the audio file
actionActionOptional Action
durationdurationrequired for channels like 'LINE' otherwise optional

new Audio()

Example

// Generic audio
const audio = new Audio({
  title: "Name of the song",
  url: "https://..."
})
ParamTypeDescription
opts.titlestringRequired
opts.urlstringRequired
opts.actionstringOptional
opts.durationnumberOptional

Location

Send or display a location on a map to a user. Optionally add an Action to perform when the user interacts with the location. Note: only supported on some channels.

Properties

NameTypeDescription
titlestringDescribes the location
latstringLatitude
longstringLongitude
actionActionOptional Action

new Location()

Example

const location = new Location({
  title: "Infinite Loop 1",
  lat: "37.331860",
  long: "-122.030248",
  action: new Action({
    type: 'url',
    value: 'https://...'
  })
})
ParamTypeDescription
opts.titlestringRequired
opts.latstringRequired
opts.longstringRequired
opts.actionstringOptional

Buttons

Generic template with an optional short description and list of Button components to request input from a user

Properties

NameTypeDescription
titlestringMain title of the buttons
buttonsArray.<Button>Optional set of buttons

new Buttons()

Example

const buttons = new Buttons("Vintage bikes and more")
buttons.addButton(new Button({
 label: "View website",
 type: "url",
 value: "..."
}))
buttons.addButton(new Button({
 label: "Special offers",
 type: "postback",
 value: "Show me special offers"
}))
ParamTypeDescription
opts.titlestringRequired

new Buttons(body, footer, header, buttons)

Example

const ButtonWA = new Templates.WhatsApp.Button({
             title: "Example title",
           })
const HeaderWA = new Templates.WhatsApp.Header({
             type: 'text',
             value: 'Example value'
           })

const buttonsWA = new Templates.WhatsApp.List({body: 'Example body',
            header: HeaderWA,
            buttons: [ButtonWA]
          })
ParamTypeDescription
bodystringRequired
footerstringOptional
headerHeaderOptional Header
buttonsArrayRequired

buttons.addButton(button)

Add a button to the buttons

ParamTypeDescription
buttonButtonbutton

buttons.addButton(button)

Add a button to the buttons

ParamTypeDescription
buttonButtonbutton

Card

A generic template that can be a combination of a Media attachment, short description or Button components to request input from a user.

Properties

NameTypeDescription
titlestringMain title of the card
subtitlestringOptional subtitle
mediaMediaOptional Media
actionActionOptional Action
buttonsArray.<Button>Optional set of Button components
actionActionOptional Action that is triggered when a user interacts with the card

new Card()

Example

const button1 = new Button({
  label: "Label",
  type: "url",
  value: "https://..."
})

const button2 = new Button({
  label: "Label",
  type: "url",
  value: "https://..."
 })

const card = new Card({
  title: "Awesome title",
  subtitle: "Some subtitle",
  media: new Media({
   url: "https://...",
   type: "image"
  })
})
card.addButton(button1)
card.addButton(button2)
ParamTypeDescription
opts.titlestringRequired
opts.subtitlestringOptional
opts.mediaMediaOptional Media
opts.actionActionOptional Action

new Card()

Example

const button1 = new Button({
  label: "Label",
  type: "url",
  value: "https://..."
})

const button2 = new Button({
  label: "Label",
  type: "url",
  value: "https://..."
 })

const rbm_card_vr = new Card({
  title: "Awesome title",
  subtitle: "Some subtitle",
  cardOrientation: "VERTICAL" 
  media: new Media({
   url: "https://...",
   type: "image",
   height: "TALL"
  })
})
card.addButton(button1)
card.addButton(button2)

const rbm_card_hr = new Card({
  title: "Awesome title",
  subtitle: "Some subtitle",
  cardOrientation: "HORIZONTAL",
  thumbnailImageAlignment: "LEFT", 
  media: new Media({
   url: "https://...",
   type: "image",
   height: "TALL"
  })
})
card.addButton(button1)
card.addButton(button2)
ParamTypeDescription
opts.titlestringRequired
opts.subtitlestringOptional
opts.mediaMediaOptional Media
opts.cardOrientationstringRequired
opts.thumbnailImageAlignmentstringRequired for horizontal orientation
opts.actionActionOptional Action

card.addButton(button)

Add a button to the card

ParamTypeDescription
buttonButtonbutton

card.addButton(button)

Add a button to the card

ParamTypeDescription
buttonButtonbutton

card.addRBMButton(button)

Add a RBM type button to the card

ParamTypeDescription
buttonRBMButtonbutton

Carousel

Template that renders a set of generic Card templates

Properties

NameTypeDescription
cardsArray.<Card>Set of Card templates

new Carousel(cards)

Example

const card1 = new Card({
  title: "Awesome title 1",
  subtitle: "Some subtitle 1",
  media: new Media({
   url: "https://...",
   type: "image"
  })
})

const card2 = new Card({
  title: "Awesome title 2",
  subtitle: "Some subtitle 2",
  media: new Media({
   url: "https://...",
   type: "image"
  })
})

const carousel = new Carousel()
carousel.addCard(card1)
carousel.addCard(card2)

Example

// Short hand
const card1 = new Card({
  title: "Awesome title 1",
  subtitle: "Some subtitle 1",
  media: new Media({
   url: "https://...",
   type: "image"
  })
})

const card2 = new Card({
  title: "Awesome title 2",
  subtitle: "Some subtitle 2",
  media: new Media({
   url: "https://...",
   type: "image"
  })
})

const carousel = new Carousel([card1, card2])
ParamTypeDescription
cardsArrayOptional list of Card templates

new Carousel(cardWidth, cards)

Example

const card1 = new Card({
  title: "Awesome title 1",
  subtitle: "Some subtitle 1",
  cardOrientation: 'VERTICAL'
  media: new Media({
   url: "https://...",
   type: "image"
  })
})

const card2 = new Card({
  title: "Awesome title 2",
  subtitle: "Some subtitle 2",
  cardOrientation: 'VERTICAL'
  media: new Media({
   url: "https://...",
   type: "image"
  })
})

const carousel = new Carousel()
carousel.addCard(card1)
carousel.addCard(card2)
carousel.cardWidth = 'MEDIUM'
ParamTypeDescription
cardWidthstringrequired
cardsArrayOptional list of Card templates

carousel.addCard(card)

Add a Card to the list of cards

ParamTypeDescription
cardCardcard

carousel.addCard(card)

Add a Card to the list of cards

ParamTypeDescription
cardCardcard

List

Template that displays a set of ListItem components

Properties

NameTypeDescription
itemsArray.<ListItem>Set of list items

list.addItem(item)

Add a ListItem to the list of items

ParamTypeDescription
itemListItemListItem

list.addButton(button)

Add a Button to the list of buttons

ParamTypeDescription
buttonButtonbutton

list.addItem(item)

Add a ListItemSection to the list of items

ParamTypeDescription
itemListItemSectionListItemSection

ListItem

Item within a List template

Properties

NameTypeDescription
titlestringTitle of the list item
subtitlestringOptional subtitle
mediaMediaOptional Media
buttonsArray.<Button>Optional set of buttons
actionActionOptional Action that is triggered when a user interacts with the list item
featuredboolOptional set this element to be featured in the List (default false)

new ListItem()

ParamTypeDescription
opts.titlestringRequired
opts.subtitlestringOptional
opts.mediaMediaOptional
opts.actionActionOptional
opts.featuredboolOptional

new ListItem()

ParamTypeDescription
opts.titlestringRequired
opts.descriptionstringRequired
opts.idstringOptional, id of the button. If not passed will be automatically generated

listItem.addButton(button)

Add a button to the list item

ParamTypeDescription
buttonButtonbutton

Action

Attach an action that is performed when a user interacts with a generic Card, List or Buttons templates

Properties

NameTypeDescription
typestringType of action (url, phone, postback, share, login, webview, event)
valuestringValue of the action
paramsArray.<Param>Optional parameters associated with the action

new Action()

Example

const image = new Image({
  ...
  action: new Action({
    type: 'url',
    value: 'https://...'
  })
})
ParamTypeDescription
opts.typestringRequired
opts.valuestringRequired
opts.paramParam | Array.<Param>Optional Param or array or Array of Params related to this action

Button

Render a button inside Card or Buttons templates. Unlike QuickReply templates, by default a button will remain on the screen even after a user presses them.

Properties

NameTypeDescription
typestringType of button (url, phone, postback, share, login, webview, event, flow, step)
labelstringLabel of the button
valuestringValue of the button
paramsArray.<Param>Optional parameters associated with the button
triggerButtonTriggerOptional ButtonTrigger for specific type of button

new Button(opts)

Example

new Button({
 type: 'webview',
 label: 'More info'
 value: 'https://...',
 trigger: new ButtonTrigger({
   type: 'event',
   value: 'Event to Trigger'
 })
})
ParamTypeDescription
optsobjectRequired properties
opts.typestringRequired, type of button (url, phone, postback, share, login, webview, event, flow, step)
opts.labelstringRequired, label of the button
opts.valuestringRequired, value of the button (can be a URL or other string value)
opts.idstringOptional, id of the button. If not passed will be automatically generated
opts.paramParam | Array.<Param>Optional Param or array or Array of Params related to this button

new Button(opts)

Example

new Button({
 type: 'webview',
 label: 'More info'
 value: 'https://...',
 trigger: new ButtonTrigger({
   type: 'event',
   value: 'event-to-trigger'
 })
})
ParamTypeDescription
optsobjectRequired properties
opts.typestringRequired, type of button (url, phone, postback, share, login, webview, event, flow, step)
opts.valuestringRequired, value of the button (can be a URL or other string value) (not for calendar action)
opts.labelstringRequired, label of the button
opts.idstringOptional, id of the button. If not passed will be automatically generated
opts.titlestringRequired
opts.descriptionstringOptional
opts.startTimestringRequired
opts.endTimestringRequired
opts.timezonestringRequired
opts.triggerButtonTriggerOptional
opts.paramParam | Array.<Param>Optional Param or array or Array of Params related to this button

new Button(opts)

Example

new Button({
 title: 'Select',
 type: 'event',
 value: 'NICE_EVENT'
})
ParamTypeDescription
optsobject
opts.titlestringRequired, title of the button
opts.typestringRequired, type of the button (text, event, flow or step)
opts.valuestringRequired, value of payload to be sent back to the server when customer clicks the buttons
opts.idstringOptional, id of the button. If not passed will be automatically generated
opts.paramParamOptional, parameter to pass to the button
opts.paramsArray.<Param>Optional, parameters to pass to the button

ButtonTrigger

Attach an optional trigger that can be applied to a Button if the type of the button is either 'url' or 'phone'.

Properties

NameTypeDescription
typestringType of button trigger (event, flow)
valuestringValue of the event/flow to be triggered

new ButtonTrigger(opts)

Example

new ButtonTrigger({
 type: 'event',
 value: 'event-to-trigger'
})
ParamTypeDescription
optsobjectRequired properties
opts.typestringRequired, type of additional trigger (event, flow)
opts.valuestringRequired, name of the event/flow to be triggered

Media

Component that represents a URL to an image, video or audio file. Used within generic templates like Card and Image.

Properties

NameTypeDescription
urlstringURL to the media file

new Media()

ParamTypeDescription
opts.urlstringRequired
opts.typestringRequired

new Media()

ParamTypeDescription
opts.urlstringRequired
opts.typestringRequired
opts.heightstringRequired for Vertical layout

new Media()

ParamTypeDescription
opts.urlstringRequired
opts.typestringRequired

QuickReply

Component placed on any Template. Represents a shortcut for a user to reply with. Ideal for yes / no type of questions.

Properties

NameTypeDescription
labelstringLabel that is shown as a quick reply
valuestringValue that is being send as the quick reply, empty if type is location
typestringType of quick reply, default is text (text, location, user_email, user_phone_number, event, flow, step)
quickReplyIdstringType of quick reply, default is text (text, location, user_email, user_phone_number, event, flow, step)
paramsArray.<Param>Optional parameters associated with the quick reply
tagsArray.<Param>Optional tags associated with the quick reply

new QuickReply()

Example

const text = new Text('We have a 40" screen for sale. Want to preorder it?')
text.addQuickReply(new QuickReply({
  label: 'đź‘Ť',
  value: 'Yes'
}))
text.addQuickReply(new QuickReply({
  label: 'đź‘Ž',
  value: 'No'
}))
ParamTypeDescription
opts.labelstringRequired
opts.typestringOptional type, default is text (text, location, user_email, user_phone_number, event, flow, step)
opts.valuestringRequired, ignored if type is location
opts.quickReplyIdstringRequired
opts.autobooleanOptional, flag for auto reply
opts.stepIdstringOptional, step link for auto reply
opts.paramParam | Array.<Param>Optional Param or array or Array of Params related to this QuickReply
opts.tagsParam | Array.<Param>Optional Tags or array or Array of Tags related to this QuickReply

Messenger

These reply templates are specific to the Messenger integration. They are not supported by other channels.

Messenger.Products

Products Template

Properties

NameTypeDescription
productIdsArray.<string>list of product IDs

new Products(productIds)

The product template can be used to render products that have been uploaded to Facebook catalog. Product details (image, title, price) will automatically be pulled from the product catalog.

Example

// Single product card
const product = new Messenger.Products('11232112332')

// Carousel of products
const product = new Messenger.Products(['11232112332', '23422224343])
ParamTypeDescription
productIdsArray.<string>Required

Messenger.OTN

One-Time Notification Request Template

Properties

NameTypeDescription
titlestringtitle of the OTN
tagstringtag that will be assigned to actor when this OTN is called

new OTN(title, tag)

The One-Time Notification request template template will be rendered and once the user clicks the Notify Me button, a special OTNR trigger is called. The specific user can now be reached for a follow up message after the 24hr period.

Example

const otn = new Messenger.OTN('When keyboards are available', 'keyboard')
ParamTypeDescription
titlestringRequired title for the request
tagstringOptional tag name to apply when a user accepts the OTNR

Messenger.Receipt

Receipt Template

Properties

NameTypeDescription
sharablebooleanOptional, set to true to enable the native share button in Messenger for the template message. Defaults to false.
recipientNamestringRequired, the recipient's name.
merchantNamestringOptional, the merchant's name. If present this is shown as logo text.
orderNumberstringRequired, the order number. Must be unique.
currencystringRequired, currency of the payment.
paymentMethodstringRequired, the payment method used. Providing enough information for the customer to decipher which payment method and account they used is recommended. This can be a custom string, such as, "Visa 1234".
timestampstringOptional, timestamp of the order in seconds.
elementsArray.<ReceiptElement>Optional, array of a maximum of 100 element objects that describe items in the order. Sort order of the elements is not guaranteed.
addressReceiptAddressOptional, the shipping address of the order.
summaryReceiptSummaryOptional, the payment summary. See summary.
adjustmentsArray.<ReceiptAdjustment>Optional, an array of payment objects that describe payment adjustments, such as discounts.

new Receipt()

The receipt template allows you to send an order confirmation. The template may include an order summary, payment details, and shipping information.

Example

// Create a receipt
const receipt = new Messenger.Receipt({
  recipientName: "Stephane Crozatier",
  orderNumber: "12345678902",
  currency: "USD",
  paymentMethod: "Visa 2345",
  orderUrl: "http://petersapparel.parseapp.com/order?order_id=123456",
  timestamp: "1428444852",
  address: new Messenger.ReceiptAddress({
    street1: "1 Hacker Way",
    street2: "2nd floor",
    city: "Menlo Park",
    postalCode: "94025",
    state: "CA",
    country: "US"
  }),
  summary: new Messenger.ReceiptSummary({
    subtotal: 75.00,
    shippingCost: 4.95,
    totalTax: 6.19,
    totalCost: 56.14
  }),
  adjustments: [
    new Messenger.ReceiptAdjustment({
      name: "New Customer Discount",
      amount: 20
    }),
    new Messenger.ReceiptAdjustment({
      name: "$10 Off Coupon",
      amount: 10
    })
  ],
  elements: [
    new Messenger.ReceiptElement({
      title: "Classic White T-Shirt",
      subtitle: "100% Soft and Luxurious Cotton",
      quantity: 2,
      price: 29.95,
      currency: "USD",
      imageUrl: "http://petersapparel.parseapp.com/img/whiteshirt.png"
    }),
    new Messenger.ReceiptElement({
      title: "Classic Gray T-Shirt",
      subtitle: "100% Soft and Luxurious Cotton",
      quantity: 2,
      price: 49.95,
      currency: "USD",
      imageUrl: "http://petersapparel.parseapp.com/img/grayshirt.png"
    })
  ]
})

Messenger.ReceiptElement

Component used in Receipt templates

Properties

NameTypeDescription
titlestringRequired, the name to display for the item.
subtitlestringOptional, a brief item description
quantitynumberOptional, the quantity of the item purchased.
pricenumberRequired, the price of the item. For free items, '0' is allowed.
currencystringOptional, the currency of the item price.
imageUrlstringOptional, the URL of an image to be displayed with the item.

new ReceiptElement(opts)

The shipping element of an order

Example

const element = new Messenger.ReceiptElement({
})
ParamTypeDescription
optsobjectRequired properties
opts.titlestringRequired, the name to display for the item.
opts.subtitlestringOptional, a brief item description
opts.quantitynumberOptional, the quantity of the item purchased.
opts.pricenumberRequired, the price of the item. For free items, '0' is allowed.
opts.currencystringOptional, the currency of the item price.
opts.imageUrlstringOptional, the URL of an image to be displayed with the item.

Messenger.ReceiptAddress

Component used in Receipt templates

Properties

NameTypeDescription
street1stringRequired, the street address, line 1.
street2stringOptional, the street address, line 2.
citystringRequired, the city name of the address.
postalCodestringRequired, the postal code of the address.
statestringRequired, the state abbreviation for U.S. addresses, or the region/province for non-U.S. addresses.
countrystringRequired, the two-letter country abbreviation of the address.

new ReceiptAddress(opts)

The shipping address of an order

Example

const address = new Messenger.ReceiptAddress({
  street1: "1 Hacker Way",
  street2: "2nd floor",
  city: "Menlo Park",
  postalCode: "94025",
  state: "CA",
  country: "US"
})
ParamTypeDescription
optsobjectRequired properties
opts.street1stringRequired, the street address, line 1.
opts.street2stringOptional, the street address, line 2.
opts.citystringRequired, the city name of the address.
opts.postalCodestringRequired, the postal code of the address.
opts.statestringRequired, the state abbreviation for U.S. addresses, or the region/province for non-U.S. addresses.
opts.countrystringRequired, the two-letter country abbreviation of the address.

Messenger.ReceiptSummary

Component used in Receipt templates

Properties

NameTypeDescription
subtotalnumberOptional, the sub-total of the order.
shippingCostnumberOptional, the shipping cost of the order.
totalTaxnumberOptional, the tax of the order.
totalCostnumberRequired, the total cost of the order, including sub-total, shipping, and tax.

new ReceiptSummary(opts)

The shipping summary of an order

Example

const summary = new Messenger.ReceiptSummary({
  subtotal: 75.00,
  shippingCost: 4.95,
  totalTax: 6.19,
  totalCost: 56.14
})
ParamTypeDescription
optsobjectRequired properties
opts.subtotalnumberOptional, the sub-total of the order.
opts.shippingCostnumberOptional, the shipping cost of the order.
opts.totalTaxnumberOptional, the tax of the order.
opts.totalCostnumberRequired, the total cost of the order, including sub-total, shipping, and tax.

Messenger.ReceiptAdjustment

Component used in Receipt templates

Properties

NameTypeDescription
namestringRequired, name of the adjustment.
amountnumberRequired, the amount of the adjustment.

new ReceiptAdjustment(opts)

Describes a payment adjustments, such as discounts

Example

const adjustment = new Messenger.ReceiptAdjustment({
  name: "10% discount",
  amount: 4.95
})
ParamTypeDescription
optsobjectRequired properties
opts.namestringRequired, name of the adjustment.
opts.amountnumberRequired, the amount of the adjustment.

Phone

These reply templates are specific to the Twilio voice integration. They are not supported by other channels.

Phone.Ask

Send a message to a user asking for input

Properties

NameTypeDescription
speechstringText to speech
urlstringURL to an audio file
expectedstringOptional, what kind of input to expect. Valid are speech or digits (default is speech)
hintsstringOptional, expected words or sentences, comma separated (max 500 words)
languagestringOptional language for text to speech
voicestringOptional voice for text to speech
timeoutnumberOptional, number of seconds to wait for user input (default ) and send a repeat message
repeatnumberOptional, number of times to ask again after user has not provided input (default 1, 0 is unlimited loop)
finishOnKeystringOptional, only when expecting digits, set a value that your caller can press to submit their digits.
numDigitsnumberOptional, only when expecting digits, set the number of digits you expect from your caller
speechTimeoutstringOptional, only when expecting speech, sets the limit (in seconds) to wait before it stopping speech recognition

new Ask()

Ask a user for input

Example

const ask = new Phone.Ask({
  speech: 'Do you speak English?',
  language: 'en-GB',
  expected: 'speech',
  hints: 'yes,yeah,yup,yes I do,no,no not really,nope'
})

Phone.Say

Play an audio file or send a text message to a user that is transformed to speech

Properties

NameTypeDescription
speechstringThe text transformed to speech Send a message to a user
speechstringText to speech
urlstringURL to an audio file
languagestringOptional language for text to speech
voicestringOptional voice for text to speech

new Say(opts)

Example

const say = new Phone.Say({
  speech: 'The weather is nice today!',
  language: 'en-GB'
})
ParamTypeDescription
optsObjectConfiguration
opts.speechstringText to speech
opts.urlstringURL to audio File
opts.languagestringOptional language for text to speech
opts.voicestringOptional voice for text to speech

Phone.Pause

Pause a moment during the call

Properties

NameTypeDescription
secondsfloatThe number of seconds to delay

new Pause()

Example

const pause = new Phone.Pause(0.2)
ParamTypeDescription
opts.secondsnumberRequired

Phone.Dial

Dial a number and forward the call

Properties

NameTypeDescription
phoneNumberstringThe number of phoneNumber to delay

new Dial()

Example

const pause = new Dial(0.2)
ParamTypeDescription
opts.phoneNumberstringRequired

Phone.Hangup

Disconnect

new Hangup()

Disconnect a phone call

Example

const hangup = new Phone.Hangup()

Apple Business Chat (Preview)

These reply templates are specific to the Apple Business Chat integration. They are not supported by other channels.

Apple.RichLink

Enhance the customer's experience by allowing them to preview inline content.

Properties

NameTypeDescription
titlestringRequired title
urlstringRequired. URL to the linked web page
assetsarrayRequired. List of assets like ImageAsset or VideoAsset

new RichLink(opts)

Example

const richLink = new Apple.RichLink({
  title: "Some news website",
  url: "https://www.mynewswebsite.corp",
  assets: [
    new Apple.ImageAsset({
      url: "https://source.unsplash.com/random",
      mimeType: "image/png"
    }),
    new Apple.VideoAsset({
      url: "https://somevideo",
      mimeType: "video/mp4"
    })
  ]
})
ParamTypeDescription
optsobjectCollection of options
opts.titlestringRequired title
opts.urlstringRequired. URL to the linked web page
opts.assetsarrayRequired. List of assets like ImageAsset or VideoAsset

richLink.addAsset(asset)

Add an asset to the list of media assets

ParamTypeDescription
assetAssetasset

Apple.ImageAsset

Component that represents an image asset used with a RichLink template

Properties

NameTypeDescription
urlstringRequired. URL to the image
mimeTypestringRequired. A string representing the format/type of the image; for example, image/jpeg, image/png

new ImageAsset(opts)

ParamTypeDescription
optsobjectCollection of options
opts.urlstringRequired. URL to the image
opts.mimeTypestringRequired. The format/type of the image

Apple.VideoAsset

Component that represents a video asset used with a RichLink template

Properties

NameTypeDescription
urlstringRequired. URL to the video
mimeTypestringRequired. A string representing the format/type of the video; for example, video/mp4, video/mpeg

new VideoAsset(opts)

ParamTypeDescription
optsobjectCollection of options
opts.urlstringRequired. URL to the video
opts.mimeTypestringRequired. The format/type of the video

Apple.ListPicker

Allow the customer to choose from a list of items

Properties

NameTypeDescription
sectionsarrayRequired 1 or more ListPickerSection objects
multipleSelectionbooleanIndicates whether the customer can make multiple selections across sections. Defaults to false
receivedMessageInteractiveMessageRequired. Message bubble that is shown to the customer to open the ListPicker window
replyMessageInteractiveMessageRequired. When the customer’s device receives a picker, the Messages app uses the replyMessage to set the style, content, and images for the reply message bubble that the Messages app displays after the customer makes their selection and returns a reply to the business.
opts.triggerActionobjectRequired. Trigger Action when items are selected from the list

new ListPicker(opts)

Example

const listPicker = new Apple.ListPicker({
  receivedMessage: new Apple.InteractiveMessage({
    title: "Select products",
    subtitle: "Fresh and straight from the farm",
    style: "small"
  }),
  replyMessage: new Apple.InteractiveMessage({
    title: "Selected products",
    style: "small"
  }),
  sections: [
    new Apple.ListPickerSection({
      title: "Fruit",
      items: [
        new Apple.ListPickerItem({
          title: "Apple",
          subtitle: "Red and delicious"
        }),
        new Apple.ListPickerItem({
          title: "Orange",
          subtitle: "Vitamin C boost"
        })
      ]
    }),
    new Apple.ListPickerSection({
      title: "Veggies",
      items: [
        new Apple.ListPickerItem({
          title: "Lettuce",
          subtitle: "Crispy greens"
        }),
        new Apple.ListPickerItem({
          title: "Cucumber",
          subtitle: "Organic"
        })
      ]
    })
  ]
})
ParamTypeDescription
optsobjectCollection of options
opts.sectionsarrayAn array of ListPickerSection objects
opts.multipleSelectionbooleanIndicates whether the customer can make multiple selections across sections. Defaults to false
opts.receivedMessageInteractiveMessageRequired. Message bubble that is shown to the customer to open the ListPicker window
opts.replyMessageInteractiveMessageRequired. Message bubble that is shown when the customer made a choice
opts.triggerActionobjectRequired. Trigger Action when items are selected from the list

listPicker.addSection(section)

Add a section to the sections

ParamTypeDescription
sectionListPickerSectionsection

Apple.ListPickerSection

Component that groups a list of ListPickerItem objects and is part of a ListPicker

Properties

NameTypeDescription
itemsArray.<ListPickerItem>A list of ListPickerItem objects
multipleSelectionbooleanIndicates whether the customer can make multiple selections within the section. Defaults to false
orderNumberAn integer containing the ordinal position for the section
titlestringRequired title

new ListPickerSection(opts)

ParamTypeDescription
optsobjectCollection of options
opts.itemsArray.<ListPickerItem>An array of ListPickerItem objects
opts.multipleSelectionbooleanIndicates whether the customer can make multiple selections within the section. Defaults to false
opts.orderNumberAn integer containing the ordinal position for the section
opts.titlestringRequired title

listPickerSection.addItem(item)

Add a list item to the section

Example

const section = new Apple.ListPickerSection({
  title: "Fruit"
})
section.addItem(new Apple.ListPickerItem({
  title: "Apples"
}))
section.addItem(new Apple.ListPickerItem({
  title: "Oranges"
}))
ParamTypeDescription
itemListPickerItemitem

Apple.ListPickerItem

Component that represents a selectable item inside a ListPickerSection

Properties

NameTypeDescription
identifierstringField identifying the item
imagestringOptional URL to a 30x30 image
ordernumberOptional integer representing the ordinal position for the item
stylestringOptional item style. Defaults to default
titlestringRequired title
subtitlestringOptional subtitle,
paramsstringOptional params,

new ListPickerItem(opts)

ParamTypeDescription
optsobjectCollection of options
opts.identifierstringOptional Unique identifier
opts.imagestringOptional URL to a 30x30 image
opts.orderNumberOptional integer representing the ordinal position for the item
opts.stylestringOptional item style. Defaults to default
opts.titlestringRequired title
opts.subtitlestringOptional subtitle
opts.paramsstringOptional subtitle

Apple.AuthRequest

Authenticate a customer using the OAuth protocol

Properties

NameTypeDescription
oauth2Oauth2Required. Oauth2 collection of keys
receivedMessageInteractiveMessageRequired. Message bubble that is shown to the customer to start the authentication
replyMessageInteractiveMessageRequired. When the customer’s device receives a authentication request, the Messages app uses the replyMessage to set the style, content, and images for the reply message bubble that the Messages app displays after the customer authenticates and returns a reply to the business.

new AuthRequest(opts)

Example

const authRequest = new Apple.AuthRequest({
  oauth2: new Apple.Oauth2({
    responseType: "code",
    scope: ["email", "profile"],
    state: "security_token",
    responseEncryptionKey: "BFz948MTG3OQ0Q69 <truncated>",
    clientSecret: "client_secret"
  }),  
  receivedMessage: new Apple.InteractiveMessage({
    title: "Sign In to Business Chat Sandbox"
  }),
  replyMessage: new Apple.InteractiveMessage({
    title: "You are signed in!"
  })
})
ParamTypeDescription
optsobjectCollection of options
opts.oauth2Oauth2Required. Oauth2 collection of keys
opts.receivedMessageInteractiveMessageRequired. Message bubble that is shown to the customer to open the authentication request window
opts.replyMessageInteractiveMessageRequired. Message bubble that is shown when the customer authenticated

Apple.Oauth2

Keys for the OAuth2 authentication request used with a AuthRequest

Properties

NameTypeDescription
clientSecretstringRequired. The secret provisioned by the authorization server
responseEncryptionKeystringRequired. The Base64-encoded public key that encrypts the access token returned in the response
responseTypestringRequired. Indicates the type of authentication request
scopeArray.<string>Required. Array of scopes that describe the granted access for read and write
statestringRequired. Indicates the state of the authentication request

new Oauth2(opts)

Example

const authRequest = new Apple.AuthRequest({
  oauth2: new Apple.Oauth2({
    responseType: "code",
    scope: ["email", "profile"],
    state: "security_token",
    responseEncryptionKey: "BFz948MTG3OQ0Q69 <truncated>",
    clientSecret: "client_secret"
  }),  
  receivedMessage: new Apple.InteractiveMessage({
    title: "Sign In to Business Chat Sandbox"
  }),
  replyMessage: new Apple.InteractiveMessage({
    title: "You are signed in!"
  })
})
ParamTypeDescription
optsobjectCollection of options
opts.clientSecretstringRequired. The secret provisioned by the authorization server
opts.responseEncryptionKeystringRequired. The Base64-encoded public key that encrypts the access token returned in the response
opts.responseTypestringRequired. Indicates the type of authentication request
opts.scopeArray.<string>Required. Array of scopes that describe the granted access for read and write
opts.statestringRequired. Indicates the state of the authentication request

oauth2.addScope(scope)

Add a scope to the list of scopes

ParamTypeDescription
scopestringscope
1.10.8

14 days ago

1.10.7

2 months ago

1.10.5

4 months ago

1.10.6

4 months ago

1.10.4

4 months ago

1.10.3

6 months ago

1.10.2

6 months ago

1.10.1

6 months ago

1.9.22

7 months ago

1.9.21

8 months ago

1.10.0

7 months ago

1.9.20

8 months ago

1.9.19

9 months ago

1.9.18

9 months ago

1.9.17

9 months ago

1.9.16

12 months ago

1.9.15

12 months ago

1.9.12-a

1 year ago

1.9.14

12 months ago

1.9.13

1 year ago

1.9.12

1 year ago

1.9.11

1 year ago

1.9.10

1 year ago

1.9.9

1 year ago

1.9.8

1 year ago

1.9.7

1 year ago

1.9.6

1 year ago

1.9.5

2 years ago

1.9.4

2 years ago

1.9.3

2 years ago

1.9.2

2 years ago

1.9.1

2 years ago

1.9.0

2 years ago

1.8.11

2 years ago

1.8.12

2 years ago

1.8.13

2 years ago

1.8.14

2 years ago

1.8.15

2 years ago

1.8.9-fix

3 years ago

1.8.9

3 years ago

1.8.10

3 years ago

1.8.8

3 years ago

1.8.7

3 years ago

1.8.6

3 years ago

1.8.5

3 years ago

1.8.4

3 years ago

1.8.3

3 years ago

1.8.2

3 years ago

1.8.5-list

3 years ago

1.8.1

3 years ago

1.8.0

3 years ago

1.8.4-list

3 years ago

1.8.3-list

3 years ago

1.8.2-list

3 years ago

1.8.1-list

3 years ago

1.7.14

3 years ago

1.7.10

3 years ago

1.7.11

3 years ago

1.7.12

3 years ago

1.7.13

3 years ago

1.7.9

3 years ago

1.7.8

3 years ago

1.7.7

3 years ago

1.7.6

3 years ago

1.7.5

4 years ago

1.7.4

4 years ago

1.7.3

4 years ago

1.7.2-beta.1

4 years ago

1.7.2-beta.2

4 years ago

1.7.2

4 years ago

1.7.1-beta.5

4 years ago

1.7.1-beta.4

4 years ago

1.7.1-beta.3

4 years ago

1.7.1-beta.2

4 years ago

1.7.1-beta.1

4 years ago

1.7.0-beta.0

4 years ago

1.7.0-beta.1

4 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.2

6 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.7

6 years ago

1.3.6

6 years ago

1.3.5

6 years ago

1.3.4

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago