Constructor
new MessageModel(payload)
- Description:
- To create a MessageModel object using a javascript object representing the conversation message,
or a string for plain text message.
The object is of Conversation Message Model (CMM) message type such as Text, Card, Attachment, Location, Postback, or Raw type. This message object may be created using the static methods in this class. Or the message object may be received from a sender, and a MessageModel can then be created to validate the message object.
The payload will be validated. If it is a valid message, messagePayload() will return the valid message object. If not, the message content can be retrieved via payload().
To support older message format, the object can also be of the 'choice' type.
- To create a MessageModel object using a javascript object representing the conversation message,
or a string for plain text message.
- Source:
- Deprecated:
- Use MessageFactory instead
Parameters:
Name | Type | Description |
---|---|---|
payload |
string | object | The payload to be parsed into a MessageModel object |
Methods
isValid() → {boolean}
- Description:
- returns if the instance contains a valid message according to Conversation Message Model (CMM)
- Source:
Returns:
if the message conforms to Conversation Message Model (CMM)
- Type
- boolean
messagePayload() → {object}
- Description:
- Retrieves the validated common message model payload.
- Source:
Returns:
The common message model payload
- Type
- object
rawPayload() → {object}
- Description:
- If messagePayload() returns null or if isValid() is false, this method can be used to retrieve the payload that could not be converted to a Conversation Message Model (CMM) payload.
- Source:
Returns:
The payload which may not comply to Conversation Message Model (CMM)
- Type
- object
validationError() → {object}
- Description:
- Retrieves the validation error messages, if any. Use if messagePayload() returns null or isValid() is false, signifying validation errors.
- Source:
Returns:
The validation error encountered when converting the payload to the
Conversation Message Model (CMM). The validation error object is produced by joi.
- Type
- object
(static) addChannelExtensions(message, channel, extensions) → {object}
- Description:
- Static method to add channel extensions to a payload object.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
message |
object | The message, card or action object to add channel extensions to. |
channel |
string | The channel type ('facebook', 'webhook', etc) to set extensions on. |
extensions |
object | The channel-specific extensions to be added. |
Returns:
The message object with channel extensions.
- Type
- object
(static) addGlobalAction(message, globalAction) → {object}
- Description:
- Static method to add a global action to a message payload object.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
message |
object | The message to add the global action to. |
globalAction |
object | The global action to be added. |
Returns:
A ConversationMessage with global actions.
- Type
- object
(static) addGlobalActions(message, globalActions) → {object}
- Description:
- Static method to add global actions to a message payload object. This method replaces any existing global actions.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
message |
object | The message to add global actions to. |
globalActions |
object | The global actions to be added. |
Returns:
A ConversationMessage with global actions.
- Type
- object
(static) attachmentConversationMessage(type, url, actionsopt, footerTextopt, headerTextopt, keywordsopt) → {object}
- Description:
- Static method to create an AttachmentConversationMessage
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
string | type of attachment - file, image, video or audio. | |
url |
string | the url of the attachment. | |
actions |
Array.<object> |
<optional> |
A list of actions for the attachmentConversationMessage. |
footerText |
string |
<optional> |
The footerText to be added at the bottom of the message. |
headerText |
string |
<optional> |
The headerText to be added at the top of the message. |
keywords |
Array.<object> |
<optional> |
A list of postback keywords that can be created with the postbackKeyword function |
Returns:
An AttachmentConversationMessage.
- Type
- object
(static) callActionObject(labelopt, imageUrlopt, phoneNumber) → {object}
- Description:
- Static method to create a call Action. A label or an imageUrl is required.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
label |
string |
<optional> |
label of the action. |
imageUrl |
string |
<optional> |
image to show for the action. |
phoneNumber |
string | phoneNumber to call if action is taken. |
Returns:
A callActionObject.
- Type
- object
(static) cardConversationMessage(layoutopt, cards, actionsopt, footerTextopt, headerTextopt, keywordsopt) → {object}
- Description:
- Static method to create a CardConversationMessage.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
layout |
string |
<optional> |
'vertical' or 'horizontal'. Whether to display the cards horizontally or vertically. Default is vertical. |
cards |
Array.<object> | The list of cards to be rendered. | |
actions |
Array.<object> |
<optional> |
A list of actions for the cardConversationMessage. |
footerText |
string |
<optional> |
The footerText to be added at the bottom of the message. |
headerText |
string |
<optional> |
The headerText to be added at the top of the message. |
keywords |
Array.<object> |
<optional> |
A list of postback keywords that can be created with the postbackKeyword function |
Returns:
A CardConversationMessage.
- Type
- object
(static) cardObject(title, descriptionopt, imageUrlopt, urlopt, actionsopt) → {object}
- Description:
- Static method to create a card object for CardConversationMessage.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
title |
string | The title of the card. | |
description |
string |
<optional> |
The description of the card. |
imageUrl |
string |
<optional> |
URL of the image. |
url |
string |
<optional> |
URL for a hyperlink of the card. |
actions |
Array.<object> |
<optional> |
A list of actions available for this card. |
Returns:
A Card.
- Type
- object
(static) form(fieldsopt, titleopt, actionsopt) → {object}
- Description:
- Static method to create a Form object.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fields |
Array.<object> |
<optional> |
The fields in the form, can be created with formField function |
title |
string |
<optional> |
The title of the form object |
actions |
Array.<object> |
<optional> |
A list of actions added to the form |
Returns:
A Form object.
- Type
- object
(static) formConversationMessage(formsopt, formColumnsopt, paginationInfoopt, actionsopt, footerTextopt, headerTextopt, keywordsopt) → {object}
- Description:
- Static method to create a FormConversationMessage.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
forms |
Array.<object> |
<optional> |
The list of forms, can be created with form function |
formColumns |
integer |
<optional> |
The number of columns used in the form layout, defaults to 1 |
paginationInfo |
Array.<object> |
<optional> |
The pagination info, can be created with the paginationInfo function |
actions |
Array.<object> |
<optional> |
A list of actions added to the message |
footerText |
string |
<optional> |
The footerText to be added at the bottom of the message. |
headerText |
string |
<optional> |
The headerText to be added at the top of the message. |
keywords |
Array.<object> |
<optional> |
A list of postback keywords that can be created with the postbackKeyword function |
Returns:
A FormConversationMessage.
- Type
- object
(static) formField(labelopt, valueopt, displayTypeopt, linkLabelopt) → {object}
- Description:
- Static method to create a FormField object.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
label |
string |
<optional> |
The label of the form field |
value |
object |
<optional> |
The value of the field |
displayType |
string |
<optional> |
The display type (text or link, defaults to text) |
linkLabel |
string |
<optional> |
The label used when the displayType is set to 'link'. |
Returns:
A FormField object.
- Type
- object
(static) locationActionObject(labelopt, imageUrlopt) → {object}
- Description:
- Static method to create a location Action. A label or an imageUrl is required.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
label |
string |
<optional> |
label of the action. |
imageUrl |
string |
<optional> |
image to show for the action. |
Returns:
A locationActionObject.
- Type
- object
(static) locationConversationMessage(latitude, longitude, titleopt, urlopt, actionsopt) → {object}
- Description:
- Static method to create a LocationConversationMessage.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
latitude |
number | The latitude. | |
longitude |
number | The longitude. | |
title |
string |
<optional> |
The title for the location. |
url |
string |
<optional> |
A url for displaying a map of the location. |
actions |
Array.<object> |
<optional> |
A list of actions for the locationConversationMessage. |
Returns:
A LocationConversationMessage.
- Type
- object
(static) paginationInfo(totalCountopt, rangeSizeopt, rangeStartopt, statusopt) → {object}
- Description:
- Static method to create a PaginationInfo object.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
totalCount |
integer |
<optional> |
The total number of items that are paginated |
rangeSize |
integer |
<optional> |
The number of items shown at once |
rangeStart |
integer |
<optional> |
The current range start index within the list of items |
status |
string |
<optional> |
Pagination status message |
Returns:
A PaginationInfo object.
- Type
- object
(static) postbackActionObject(labelopt, imageUrlopt, postback, keywordsopt, skipAutoNumberopt) → {object}
- Description:
- Static method to create a postback Action. A label or an imageUrl is required.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
label |
string |
<optional> |
label of the action. |
imageUrl |
string |
<optional> |
image to show for the action. |
postback |
object | string | object or string to send as postback if action is taken. | |
keywords |
Array.<string> |
<optional> |
array of keywords that can be used to trigger the postback action. |
skipAutoNumber |
boolean |
<optional> |
Boolean flag that can be used to exclude a postback action from auto-numbering. Only applicable when 'autoNumberPostbackActions' context variable or 'autoNumberPostbackActions' component property is set to true. |
Returns:
A postbackActionObject.
- Type
- object
(static) postbackConversationMessage(postback, labelopt, actionsopt) → {object}
- Description:
- Static method to create a postackConversationMessage
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
postback |
object | string | object or string to send as postback. | |
label |
string |
<optional> |
The label associated with the postback. |
actions |
Array.<object> |
<optional> |
A list of actions for the postbackConversationMessage. |
Returns:
A PostbackConversationMessage.
- Type
- object
(static) postbackKeyword(keywordsopt, postback, skipAutoNumberopt) → {object}
- Description:
- Static method to create a keyword for a postack payload that is not associated to a postback action button
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
keywords |
Array.<string> |
<optional> |
array of keywords that can be used to trigger the postback action. |
postback |
object | string | object to send as postback if keyword is entered | |
skipAutoNumber |
boolean |
<optional> |
Boolean flag that can be used to exclude the keyword from autoNumbering |
Returns:
A Keyword object.
- Type
- object
(static) rawConversationMessage(payload) → {object}
- Description:
- Static method to create a RawConversationMessage.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
payload |
object | The raw (channel-specific) payload, |
Returns:
A RawConversationMessage.
- Type
- object
(static) shareActionObject(labelopt, imageUrlopt) → {object}
- Description:
- Static method to create a share Action. A label or an imageUrl is required.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
label |
string |
<optional> |
label of the action. |
imageUrl |
string |
<optional> |
image to show for the action. |
Returns:
A shareActionObject.
- Type
- object
(static) tableColumn(valueopt, alignmentopt, displayTypeopt, linkLabelopt) → {object}
- Description:
- Static method to create a TableColumn object.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
object |
<optional> |
The value of the column |
alignment |
string |
<optional> |
The alignment of the column value (left, right or center, defaults to left) |
displayType |
string |
<optional> |
The display type (text or link, defaults to text) |
linkLabel |
string |
<optional> |
The label used when the displayType is set to 'link'. |
Returns:
A TableColumn object.
- Type
- object
(static) tableConversationMessage(headingsopt, rowsopt, paginationInfoopt, actionsopt, footerTextopt, headerTextopt, keywordsopt) → {object}
- Description:
- Static method to create a TableConversationMessage.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
headings |
Array.<object> |
<optional> |
The table header columns, can be created with tableHeaderColumn function |
rows |
Array.<object> |
<optional> |
The table rows, can be created with tableRow function |
paginationInfo |
Array.<object> |
<optional> |
The pagination info, can be created with the paginationInfo function |
actions |
Array.<object> |
<optional> |
A list of actions added to the message |
footerText |
string |
<optional> |
The footerText to be added at the bottom of the message. |
headerText |
string |
<optional> |
The headerText to be added at the top of the message. |
keywords |
Array.<object> |
<optional> |
A list of postback keywords that can be created with the postbackKeyword function |
Returns:
A TableConversationMessage.
- Type
- object
(static) tableFormConversationMessage(headingsopt, rowsopt, formsopt, formColumnsopt, showFormButtonLabelopt, paginationInfoopt, actionsopt, footerTextopt, headerTextopt, keywordsopt) → {object}
- Description:
- Static method to create a TableFormConversationMessage.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
headings |
Array.<object> |
<optional> |
The table header columns, can be created with tableHeaderColumn function |
rows |
Array.<object> |
<optional> |
The table rows, can be created with tableRow function |
forms |
Array.<object> |
<optional> |
The list of forms, can be created with form function |
formColumns |
integer |
<optional> |
The number of columns used in the form layout, defaults to 1 |
showFormButtonLabel |
string |
<optional> |
The label used for the button to open the form when the form is displayed in a dialog (Slack only) |
paginationInfo |
Array.<object> |
<optional> |
The pagination info, can be created with the paginationInfo function |
actions |
Array.<object> |
<optional> |
A list of actions added to the message |
footerText |
string |
<optional> |
The footerText to be added at the bottom of the message. |
headerText |
string |
<optional> |
The headerText to be added at the top of the message. |
keywords |
Array.<object> |
<optional> |
A list of postback keywords that can be created with the postbackKeyword function |
Returns:
A TableFormConversationMessage.
- Type
- object
(static) tableHeaderColumn(labelopt, widthopt, alignmentopt) → {object}
- Description:
- Static method to create a TableHeaderColumn object.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
label |
string |
<optional> |
The label of the column header |
width |
integer |
<optional> |
The width of the column header (optional) |
alignment |
string |
<optional> |
The alignment of the column header label (left, right or center, defaults to left) |
Returns:
A TableHeaderColumn object.
- Type
- object
(static) tableRow(columnsopt) → {object}
- Description:
- Static method to create a TableRow object.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
columns |
Array.<object> |
<optional> |
The columns in the row, can be created with tableColumn function |
Returns:
A TableRow object.
- Type
- object
(static) textConversationMessage(text, actionsopt, footerTextopt, headerTextopt, keywordsopt) → {object}
- Description:
- Static method to create a TextConversationMessage.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
text |
string | The text of the message payload. | |
actions |
Array.<object> |
<optional> |
A list of actions related to the text. |
footerText |
string |
<optional> |
The footerText to be added at the bottom of the message. |
headerText |
string |
<optional> |
The headerText to be added at the top of the message. |
keywords |
Array.<object> |
<optional> |
A list of postback keywords that can be created with the postbackKeyword function |
Returns:
A TextConversationMessage.
- Type
- object
(static) urlActionObject(labelopt, imageUrlopt, url) → {object}
- Description:
- Static method to create a url Action. A label or an imageUrl is required.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
label |
string |
<optional> |
label of the action. |
imageUrl |
string |
<optional> |
image to show for the action. |
url |
string | url to open if action is taken. |
Returns:
A urlActionObject.
- Type
- object
(static) validateConversationMessage(payload) → {boolean|object}
- Description:
- Static method to validate a common ConversationMessage
- Source:
Parameters:
Name | Type | Description |
---|---|---|
payload |
object | The payload object to be verified |
Returns:
true if valid; return Validation Error object (error & value) if invalid
- Type
- boolean | object