MessageFactory Class

  • java.lang.Object
    • com.microsoft.bot.builder.MessageFactory

public final class MessageFactory

Contains utility methods for various message types a bot can return.

Create and send a message. Activity message = MessageFactory.text("Hello World"); conext.sendActivity(message);

The following apply to message actions in general. See the channel's documentation for limits imposed upon the contents of the text of the message to send.

To control various characteristics of your bot's speech such as voice, rate, volume, pronunciation, and pitch, specify test to speak in Speech Synthesis Markup Language (SSML) format.

Channels decide how each card action manifests in their user experience. In most cases, the cards are clickable. In others, they may be selected by speech input. In cases where the channel does not offer an interactive activation experience (e.g., when interacting over SMS), the channel may not support activation whatsoever. The decision about how to render actions is controlled by normative requirements elsewhere in this document (e.g. within the card format, or within the suggested actions definition).

Method Summary

Modifier and Type Method and Description
static Activity attachment(Attachment attachment)

Returns a message activity that contains an attachment.

static Activity attachment(Attachment attachment, String text)

Returns a message activity that contains an attachment.

static Activity attachment(Attachment attachment, String text, String ssml, InputHints inputHint)

Returns a message activity that contains an attachment.

static Activity attachment(List<Attachment> attachments)

Returns a message activity that contains an attachment.

static Activity attachment(List<Attachment> attachments, String text, String ssml, InputHints inputHint)

Returns a message activity that contains an attachment.

static Activity carousel(List<Attachment> attachments, String text)

Returns a message activity that contains a collection of attachments, in a list.

static Activity carousel(List<Attachment> attachments, String text, String ssml, InputHints inputHint)

Returns a message activity that contains a collection of attachments, in a list.

static Activity contentUrl(String url, String contentType)

Returns a message activity that contains a single image or video.

static Activity contentUrl(String url, String contentType, String name, String text, String ssml, InputHints inputHint)

Returns a message activity that contains a single image or video.

static Activity suggestedActions(List<String> actions, String text)

Returns a message that includes a set of suggested actions and optional text.

static Activity suggestedActions(List<String> actions, String text, String ssml, InputHints inputHint)

Returns a message that includes a set of suggested actions and optional text.

static Activity suggestedCardActions(List<CardAction> actions, String text)

Returns a message that includes a set of suggested actions and optional text.

static Activity suggestedCardActions(List<CardAction> actions, String text, String ssml, InputHints inputHint)

Returns a message that includes a set of suggested actions and optional text.

static Activity text(String text)

Returns a simple text message.

static Activity text(String text, String ssml, InputHints inputHint)

Returns a simple text message.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Method Details

attachment

public static Activity attachment(Attachment attachment)

Returns a message activity that contains an attachment.

Parameters:

attachment - Attachment to include in the message.

Returns:

A message activity containing the attachment.

attachment

public static Activity attachment(Attachment attachment, String text)

Returns a message activity that contains an attachment.

Parameters:

attachment - Attachment to include in the message.
text - Optional, the text of the message to send.

Returns:

A message activity containing the attachment.

attachment

public static Activity attachment(Attachment attachment, String text, String ssml, InputHints inputHint)

Returns a message activity that contains an attachment.

Parameters:

attachment - Attachment to include in the message.
text - Optional, the text of the message to send.
ssml - Optional, text to be spoken by your bot on a speech-enable channel.
inputHint - Optional, indicates whether your bot is accepting, expecting, or ignoring user input after the message is delivered to the client. Default is ACCEPTING_INPUT.

Returns:

A message activity containing the attachment.

attachment

public static Activity attachment(List attachments)

Returns a message activity that contains an attachment.

Parameters:

attachments - Attachments to include in the message.

Returns:

A message activity containing the attachment.

attachment

public static Activity attachment(List attachments, String text, String ssml, InputHints inputHint)

Returns a message activity that contains an attachment.

Parameters:

attachments - Attachments to include in the message.
text - Optional, the text of the message to send.
ssml - Optional, text to be spoken by your bot on a speech-enable channel.
inputHint - Optional, indicates whether your bot is accepting, expecting, or ignoring user input after the message is delivered to the client. Default is ACCEPTING_INPUT.

Returns:

A message activity containing the attachment.

carousel

public static Activity carousel(List attachments, String text)

Returns a message activity that contains a collection of attachments, in a list.

Parameters:

attachments - Attachments to include in the message.
text - Optional, the text of the message to send.

Returns:

A message activity containing the attachment.

carousel

public static Activity carousel(List attachments, String text, String ssml, InputHints inputHint)

Returns a message activity that contains a collection of attachments, in a list.

Parameters:

attachments - Attachments to include in the message.
text - Optional, the text of the message to send.
ssml - Optional, text to be spoken by your bot on a speech-enable channel.
inputHint - Optional, indicates whether your bot is accepting, expecting, or ignoring user input after the message is delivered to the client. Default is ACCEPTING_INPUT.

Returns:

A message activity containing the attachment.

contentUrl

public static Activity contentUrl(String url, String contentType)

Returns a message activity that contains a single image or video.

Parameters:

url - The URL of the image or video to send.
contentType - The MIME type of the image or video.

Returns:

A message activity containing the attachment.

contentUrl

public static Activity contentUrl(String url, String contentType, String name, String text, String ssml, InputHints inputHint)

Returns a message activity that contains a single image or video.

Parameters:

url - The URL of the image or video to send.
contentType - The MIME type of the image or video.
name - Optional, the name of the image or video file.
text - Optional, the text of the message to send.
ssml - Optional, text to be spoken by your bot on a speech-enable channel.
inputHint - Optional, indicates whether your bot is accepting, expecting, or ignoring user input after the message is delivered to the client. Default is ACCEPTING_INPUT.

Returns:

A message activity containing the attachment.

suggestedActions

public static Activity suggestedActions(List actions, String text)

Returns a message that includes a set of suggested actions and optional text. // Create the activity and add suggested actions. Activity activity = MessageFactory.suggestedActions( new String[] { "red", "green", "blue" }, "Choose a color");

// Send the activity as a reply to the user. context.sendActivity(activity);

Parameters:

actions - The text of the actions to create.
text - Optional. The text of the message to send.

Returns:

A message activity containing the suggested actions.

suggestedActions

public static Activity suggestedActions(List actions, String text, String ssml, InputHints inputHint)

Returns a message that includes a set of suggested actions and optional text. // Create the activity and add suggested actions. Activity activity = MessageFactory.suggestedActions( new String[] { "red", "green", "blue" }, "Choose a color");

// Send the activity as a reply to the user. context.sendActivity(activity);

Parameters:

actions - The text of the actions to create.
text - Optional. The text of the message to send.
ssml - Optional, text to be spoken by your bot on a speech-enable channel.
inputHint - Optional, indicates whether your bot is accepting, expecting, or ignoring user input after the message is delivered to the client. Default is ACCEPTING_INPUT.

Returns:

A message activity containing the suggested actions.

suggestedCardActions

public static Activity suggestedCardActions(List actions, String text)

Returns a message that includes a set of suggested actions and optional text.

Parameters:

actions - The card actions to include.
text - Optional, the text of the message to send.

Returns:

A message activity that contains the suggested actions.

suggestedCardActions

public static Activity suggestedCardActions(List actions, String text, String ssml, InputHints inputHint)

Returns a message that includes a set of suggested actions and optional text.

Parameters:

actions - The card actions to include.
text - Optional, the text of the message to send.
ssml - Optional, text to be spoken by your bot on a speech-enable channel.
inputHint - Optional, indicates whether your bot is accepting, expecting, or ignoring user input after the message is delivered to the client. Default is ACCEPTING_INPUT.

Returns:

A message activity that contains the suggested actions.

text

public static Activity text(String text)

Returns a simple text message.

Parameters:

text - The text of the message to send.

Returns:

A message activity containing the text.

text

public static Activity text(String text, String ssml, InputHints inputHint)

Returns a simple text message.

Parameters:

text - The text of the message to send.
ssml - Optional, text to be spoken by your bot on a speech-enabled channel.
inputHint - Optional, indicates whether your bot is accepting, expecting, or ignoring user input after the message is delivered to the client. Default is ACCEPTING_INPUT.

Returns:

A message activity containing the text.

Applies to