Facebook Messenger

Integration published by Jovo | 6,835 downloads

Build apps for Facebook's Messenger platform

Facebook Messenger Platform Integration

Learn more about the Facebook Messenger Platform and its platform-specific features that can be used with the Jovo Framework.

Installation

Install the module:

Import the installed module, initialize and add it to the app object:

Configure the module:

Configurations

Automatically set greeting-text

To set the greeting-text on startup you have to set the following configuration:

Automatically set launch-payload

To set the launch-payload on startup you have to set the following configuration:

Automatically set persistent menu

To set the persistent menu payload on startup you have to set the following configuration:

Disable synchronous response

By default, tell and ask generate a message that will be sent shortly before responding to the initial request. As a consequence, this message will always be the last message sent.

If you do not like this behavior, you can disable it by setting the shouldIgnoreSynchronousResponse-property to true in the configuration:

Introduction to Messenger Specific Features

You can access the messengerBot object like this:

The returned object will be an instance of MessengerBot if the current request comes from Facebook Messenger. Otherwise undefined will be returned.

Output

These sections provide an overview of Facebook Messenger specific features for output. For the basic concept, take a look here: Docs: Basic Concepts > Output.

No Reprompts

Facebook Messenger does not support reprompts. Any reprompt passed to ask will be ignored.

Asynchronous Responses

Facebook Messenger allows sending multiple messages asynchronously.

All asynchronous methods for sending messages return a AxiosResponse. It is recommended to wrap these call in a try-catch-block to catch possible errors thrown by the API.

INFO: The message that results from calling tell or ask will be the last message sent! This behavior can be disabled, read more here.

You can read more about sending messages here.

Overwrite default-output

The speech of tell and ask can be overwritten:

Additionally, quick-replies can be overwritten and added:

Sending Text

The following example shows how to send a text-message:

INFO: The message that was created by calling tell or ask will always be the last message to be displayed. Even if the showText-method was called after. Read more about disabling that behavior here.

Text Message Options

When calling the text-method an object with the following properties can be passed:

property type description
text string Required. The text that will be displayed
quickReplies Array<QuickReply | string> Optional. Quick-Replies that will be shown below the text.
messageType MessageType Optional. The type of the message. Defaults to MessageType.Response.

Sending Quick Replies

Quick-replies can be sent by passing the quickReplies property to the options of the showText- or showAttachment-method:

Read more about quick-replies here.

In addition to manually creating a QuickReply-object, the helper classes TextQuickReply and BuiltInQuickReply can be used.

INFO: When passing a string, a TextQuickReply will be created from that string.

TextQuickReply

TextQuickReply can be used to create a QuickReply-object that displays text.

BuiltInQuickReply

BuiltInQuickReply can be used to create QuickReply-object that either displays the user's email or phone number and provides an easy to way for the user to reply with this information.

Read more about built-in quick-replies here and here.

Sending Attachments

Facebook Messenger allows sending attachments, which includes audio, videos, images and files.

Read more about sending attachments here.

Attachment Options

property type description
type AttachmentType Required. The type of the attachment.
data Buffer | string | number Required. The data to be sent with the attachment.
quickReplies Array<QuickReply | string> Optional. Quick-Replies that will be shown below the attachment.
isReusable boolean Optional. Determines whether the resource is reusable.

Sending an Action

Actions allow controlling indicators for typing and read receipts.

SenderActionType

The following actions are supported:

  • MarkSeen = 'mark_seen'
  • TypingOn = 'typing_on'
  • TypingOff = 'typing_off'

There is also a helper method that sends the TypingOn and TypingOff action with a delay.

Read more here.

Sending Templates

Facebook Messenger allows sending templates.

Read more here.

GenericTemplate

The following example shows how to send a generic template:

Read more here.

ButtonTemplate

The following example shows how to send a button template:

Read more here.

MediaTemplate

The following example shows how to send a media template:

Read more here.

ReceiptTemplate

The following example shows how to send a receipt template:

Read more here.

AirlineTemplate

The following example shows how to send an airline template:

Read more here.

Facebook Messenger Changelog

Current version might be higher than the latest changes displayed below because of updates of dependencies.

2021-10-06 [3.5.5]

2020-09-29 [3.1.0]

  • #817 :recycle: ✨ Refactor Facebook Messenger platform - asynchronous Responses (@m-ripper)

3.0.17 (2020-05-28)

🐛 Bug Fix

3.0.15 (2020-05-04)

  • jovo-platform-facebookmessenger Improve session handling
  • jovo-platform-facebookmessenger Add configurable fetchProfile functionality

Committers: 1

3.0.11 (2020-04-06)

  • Updated Typescript to 3.8.x
  • Updated Prettier to 2.x

Committers: 2

2.x

Find the 2.x changelog here.

Join Our Newsletter

Be the first to get our free tutorials, courses, and other resources for voice app developers.