Message class

Message builder class that simplifies building complex messages with attachments.

Constructors

Message(Session)

Creates a new Message builder.

Methods

addAttachment(AttachmentType)

Adds an attachment to the message. See IAttachment for examples.

addEntity(Object)

Adds an entity to the message.

address(IAddress)

Address routing information for the message. Save this field to external storage somewhere to later compose a proactive message to the user.

attachmentLayout(string)

Hint for how clients should layout multiple attachments. The default value is 'list'.

attachments(AttachmentType[])

Cards or images to send to the user.

code(string)

Code indicating why the conversation has ended.

compose(string[][], any[])

Composes a complex and randomized reply to the user.

composePrompt(Session, string[][], any[])

DEPRECATED use compose() instead.

composePrompt(Session, string[][], any[])

Combines an array of prompts into a single localized prompt and then optionally fills the prompts template slots with the passed in arguments.

entities(Object[])

Structured objects passed to the bot or user.

inputHint(string)

Hint for clients letting them know if the bot is expecting further input or not. The built-in prompts will automatically populate this value for outgoing messages.

localTimestamp(string)

Local time when message was sent (set by client or bot, Ex: 2016-09-23T13:07:49.4714686-07:00.)

name(string)

Name of the operation to invoke or the name of the event.

nspeak(TextType, TextType, number)

Conditionally set the speak field of the message given a specified count.

ntext(TextType, TextType, number)

Conditionally set the message text given a specified count.

originalEvent(any)

Message in original/native format of the channel for incoming messages.

randomPrompt(TextType)

Selects a prompt at random.

relatesTo(IAddress)

Reference to another conversation or message.

setChannelData(any)

DEPRECATED use sourceEvent() instead.

setLanguage(string)

DEPRECATED use local() instead.

setNText(Session, string, string, number)

DEPRECATED use ntext() instead.

setText(Session, TextType, any[])

DEPRECATED use text() instead.

sourceEvent(ISourceEventMap)

For outgoing messages can be used to pass source specific event data like custom attachments.

speak(TextType, any[])

Sets the speak field of the message as Speech Synthesis Markup Language (SSML). This will be spoken to the user on supported devices.

suggestedActions(ISuggestedActions | IIsSuggestedActions)

Optional suggested actions to send to the user. Suggested actions will be displayed only on the channels that support suggested actions.

summary(TextType, any[])

Text to be displayed by as fall-back and as short description of the message content in e.g. list of recent conversations.

text(TextType, any[])

Sets the message text.

textFormat(string)

Format of text fields.

textLocale(string)

Language of the message.

timestamp(string)

Set by connectors service. Use localTimestamp() instead.

toMessage()

Returns the JSON for the message.

value(any)

Open-ended value.

Constructor Details

Message(Session)

Creates a new Message builder.

new Message(session?: Session)

Parameters

session
Session

(Optional) will be used to populate the messages address and localize any text.

Method Details

addAttachment(AttachmentType)

Adds an attachment to the message. See IAttachment for examples.

function addAttachment(attachment: AttachmentType)

Parameters

attachment
AttachmentType

The attachment to add.

Returns

addEntity(Object)

Adds an entity to the message.

function addEntity(obj: Object)

Parameters

obj

Object

Returns

address(IAddress)

Address routing information for the message. Save this field to external storage somewhere to later compose a proactive message to the user.

function address(adr: IAddress)

Parameters

adr
IAddress

Returns

attachmentLayout(string)

Hint for how clients should layout multiple attachments. The default value is 'list'.

function attachmentLayout(style: string)

Parameters

style

string

Returns

attachments(AttachmentType[])

Cards or images to send to the user.

function attachments(list: AttachmentType[])

Parameters

Returns

code(string)

Code indicating why the conversation has ended.

function code(value: string)

Parameters

value

string

Returns

compose(string[][], any[])

Composes a complex and randomized reply to the user.

function compose(prompts: string[][], args: any[])

Parameters

prompts

string[][]

args

any[]

Returns

composePrompt(Session, string[][], any[])

DEPRECATED use compose() instead.

function composePrompt(session: Session, prompts: string[][], args: any[])

Parameters

session
Session
prompts

string[][]

args

any[]

Returns

composePrompt(Session, string[][], any[])

Combines an array of prompts into a single localized prompt and then optionally fills the prompts template slots with the passed in arguments.

static function composePrompt(session: Session, prompts: string[][], args?: any[])

Parameters

session
Session

Session object used to localize the individual prompt parts.

prompts

string[][]

Array of prompt lists. Each entry in the array is another array of prompts which will be chosen at random. The combined output text will be space delimited.

args

any[]

(Optional) array of arguments used to format the output text when the prompt is a template.

Returns

string

entities(Object[])

Structured objects passed to the bot or user.

function entities(list: Object[])

Parameters

list

Object[]

Returns

inputHint(string)

Hint for clients letting them know if the bot is expecting further input or not. The built-in prompts will automatically populate this value for outgoing messages.

function inputHint(hint: string)

Parameters

hint

string

Returns

localTimestamp(string)

Local time when message was sent (set by client or bot, Ex: 2016-09-23T13:07:49.4714686-07:00.)

function localTimestamp(time?: string)

Parameters

time

string

(Optional) time expressed as an ISO string. Defaults to new Date().toISOString().

Returns

name(string)

Name of the operation to invoke or the name of the event.

function name(name: string)

Parameters

name

string

Returns

nspeak(TextType, TextType, number)

Conditionally set the speak field of the message given a specified count.

function nspeak(ssml: TextType, ssml_plural: TextType, count: number)

Parameters

ssml
TextType
ssml_plural
TextType
count

number

Returns

ntext(TextType, TextType, number)

Conditionally set the message text given a specified count.

function ntext(msg: TextType, msg_plural: TextType, count: number)

Parameters

msg
TextType
msg_plural
TextType
count

number

Returns

originalEvent(any)

Message in original/native format of the channel for incoming messages.

function originalEvent(event: any)

Parameters

event

any

Returns

randomPrompt(TextType)

Selects a prompt at random.

static function randomPrompt(prompts: TextType)

Parameters

prompts
TextType

Array of prompts to choose from. When prompts is type string the prompt will simply be returned unmodified.

Returns

string

relatesTo(IAddress)

Reference to another conversation or message.

function relatesTo(adr: IAddress)

Parameters

adr
IAddress

Returns

setChannelData(any)

DEPRECATED use sourceEvent() instead.

function setChannelData(data: any)

Parameters

data

any

Returns

setLanguage(string)

DEPRECATED use local() instead.

function setLanguage(language: string)

Parameters

language

string

Returns

setNText(Session, string, string, number)

DEPRECATED use ntext() instead.

function setNText(session: Session, msg: string, msg_plural: string, count: number)

Parameters

session
Session
msg

string

msg_plural

string

count

number

Returns

setText(Session, TextType, any[])

DEPRECATED use text() instead.

function setText(session: Session, prompt: TextType, args: any[])

Parameters

session
Session
prompt
TextType
args

any[]

Returns

sourceEvent(ISourceEventMap)

For outgoing messages can be used to pass source specific event data like custom attachments.

function sourceEvent(map: ISourceEventMap)

Parameters

Returns

speak(TextType, any[])

Sets the speak field of the message as Speech Synthesis Markup Language (SSML). This will be spoken to the user on supported devices.

function speak(ssml: TextType, args: any[])

Parameters

ssml
TextType
args

any[]

Returns

suggestedActions(ISuggestedActions | IIsSuggestedActions)

Optional suggested actions to send to the user. Suggested actions will be displayed only on the channels that support suggested actions.

function suggestedActions(suggestedActions: ISuggestedActions | IIsSuggestedActions)

Parameters

Returns

summary(TextType, any[])

Text to be displayed by as fall-back and as short description of the message content in e.g. list of recent conversations.

function summary(text: TextType, args: any[])

Parameters

text
TextType
args

any[]

Returns

text(TextType, any[])

Sets the message text.

function text(text: TextType, args: any[])

Parameters

text
TextType
args

any[]

Returns

textFormat(string)

Format of text fields.

function textFormat(style: string)

Parameters

style

string

Returns

textLocale(string)

Language of the message.

function textLocale(locale: string)

Parameters

locale

string

Returns

timestamp(string)

Set by connectors service. Use localTimestamp() instead.

function timestamp(time?: string)

Parameters

time

string

Returns

toMessage()

Returns the JSON for the message.

function toMessage()

Returns

value(any)

Open-ended value.

function value(param: any)

Parameters

param

any

Returns