Compartir a través de


MessageFactory class

Un conjunto de funciones de utilidad para ayudar con el formato de los distintos tipos de mensajes que puede devolver un bot.

Comentarios

En el ejemplo siguiente se muestra cómo enviar un mensaje que contiene una sola tarjeta prominente:

const { MessageFactory, CardFactory } = require('botbuilder');

const card = CardFactory.heroCard(
     'White T-Shirt',
     ['https://example.com/whiteShirt.jpg'],
     ['buy']
);
const message = MessageFactory.attachment(card);
await context.sendActivity(message);

Métodos

attachment(Attachment, string, string, InputHints | string)

Devuelve una sola actividad de mensaje que contiene datos adjuntos.

carousel(Attachment[], string, string, InputHints | string)

Devuelve un mensaje que mostrará un conjunto de datos adjuntos mediante un diseño de carrusel.

contentUrl(string, string, string, string, string, InputHints | string)

Devuelve un mensaje que mostrará una sola imagen o vídeo a un usuario.

list(Attachment[], string, string, InputHints | string)

Devuelve un mensaje que mostrará un conjunto de datos adjuntos en el formulario de lista.

suggestedActions(string | CardAction[], string, string, InputHints | string)

Devuelve un mensaje que incluye un conjunto de acciones sugeridas y texto opcional.

text(string, string, InputHints | string)

Devuelve un mensaje de texto simple.

Detalles del método

attachment(Attachment, string, string, InputHints | string)

Devuelve una sola actividad de mensaje que contiene datos adjuntos.

static function attachment(attachment: Attachment, text?: string, speak?: string, inputHint?: InputHints | string): Partial<Activity>

Parámetros

attachment

Attachment

Tarjeta adaptable que se va a incluir en el mensaje.

text

string

(Opcional) texto del mensaje.

speak

string

(Opcional) SSML que se va a incluir con el mensaje.

inputHint

InputHints | string

(Opcional) sugerencia de entrada para el mensaje. Tiene como valor predeterminado acceptingInput.

Devoluciones

Partial<Activity>

Actividad de mensaje que contiene los datos adjuntos.

Comentarios

En este ejemplo se muestra cómo crear un mensaje con datos adjuntos de tarjeta prominente:

const message = MessageFactory.attachment(
    CardFactory.heroCard(
        'White T-Shirt',
        ['https://example.com/whiteShirt.jpg'],
        ['buy']
     )
);

Devuelve un mensaje que mostrará un conjunto de datos adjuntos mediante un diseño de carrusel.

static function carousel(attachments: Attachment[], text?: string, speak?: string, inputHint?: InputHints | string): Partial<Activity>

Parámetros

attachments

Attachment[]

Matriz de datos adjuntos que se van a incluir en el mensaje.

text

string

(Opcional) texto del mensaje.

speak

string

(Opcional) SSML que se va a incluir con el mensaje.

inputHint

InputHints | string

(Opcional) sugerencia de entrada para el mensaje.

Devoluciones

Partial<Activity>

Actividad de mensaje que mostrará un conjunto de datos adjuntos mediante un diseño de carrusel.

Comentarios

En este ejemplo se muestra cómo crear un mensaje con un carrusel de tarjetas prominentes:

const message = MessageFactory.carousel([
   CardFactory.heroCard('title1', ['imageUrl1'], ['button1']),
   CardFactory.heroCard('title2', ['imageUrl2'], ['button2']),
   CardFactory.heroCard('title3', ['imageUrl3'], ['button3'])
]);

contentUrl(string, string, string, string, string, InputHints | string)

Devuelve un mensaje que mostrará una sola imagen o vídeo a un usuario.

static function contentUrl(url: string, contentType: string, name?: string, text?: string, speak?: string, inputHint?: InputHints | string): Partial<Activity>

Parámetros

url

string

Dirección URL de la imagen o vídeo que se va a enviar.

contentType

string

Tipo MIME de la imagen o vídeo.

name

string

(Opcional) Nombre del archivo de imagen o vídeo.

text

string

(Opcional) texto del mensaje.

speak

string

(Opcional) SSML que se va a incluir con el mensaje.

inputHint

InputHints | string

(Opcional) sugerencia de entrada para el mensaje.

Devoluciones

Partial<Activity>

Actividad de mensaje que mostrará una sola imagen o vídeo a un usuario.

Comentarios

En este ejemplo se muestra cómo enviar una imagen al usuario:

const message = MessageFactory.contentUrl('https://example.com/hawaii.jpg', 'image/jpeg', 'Hawaii Trip', 'A photo from our family vacation.');

list(Attachment[], string, string, InputHints | string)

Devuelve un mensaje que mostrará un conjunto de datos adjuntos en el formulario de lista.

static function list(attachments: Attachment[], text?: string, speak?: string, inputHint?: InputHints | string): Partial<Activity>

Parámetros

attachments

Attachment[]

Matriz de datos adjuntos que se van a incluir en el mensaje.

text

string

(Opcional) texto del mensaje.

speak

string

(Opcional) SSML que se va a incluir con el mensaje.

inputHint

InputHints | string

(Opcional) sugerencia de entrada para el mensaje.

Devoluciones

Partial<Activity>

Actividad de mensaje que mostrará un conjunto de datos adjuntos en el formulario de lista.

Comentarios

En este ejemplo se muestra cómo crear un mensaje con una lista de tarjetas prominentes:

const message = MessageFactory.list([
   CardFactory.heroCard('title1', ['imageUrl1'], ['button1']),
   CardFactory.heroCard('title2', ['imageUrl2'], ['button2']),
   CardFactory.heroCard('title3', ['imageUrl3'], ['button3'])
]);

suggestedActions(string | CardAction[], string, string, InputHints | string)

Devuelve un mensaje que incluye un conjunto de acciones sugeridas y texto opcional.

static function suggestedActions(actions: string | CardAction[], text?: string, speak?: string, inputHint?: InputHints | string): Partial<Activity>

Parámetros

actions

string | CardAction[]

Matriz de acciones o cadenas de tarjeta que se van a incluir. Las cadenas se convertirán en messageBack acciones.

text

string

(Opcional) texto del mensaje.

speak

string

(Opcional) SSML que se va a incluir con el mensaje.

inputHint

InputHints | string

(Opcional) sugerencia de entrada para el mensaje. Tiene como valor predeterminado acceptingInput.

Devoluciones

Partial<Activity>

Actividad de mensaje que contiene las acciones sugeridas.

Comentarios

En este ejemplo se muestra cómo crear un mensaje con acciones sugeridas:

const message = MessageFactory.suggestedActions(['red', 'green', 'blue'], `Choose a color`);

text(string, string, InputHints | string)

Devuelve un mensaje de texto simple.

static function text(text: string, speak?: string, inputHint?: InputHints | string): Partial<Activity>

Parámetros

text

string

Texto que se va a incluir en el mensaje.

speak

string

(Opcional) SSML que se va a incluir en el mensaje.

inputHint

InputHints | string

(Opcional) sugerencia de entrada para el mensaje. Tiene como valor predeterminado acceptingInput.

Devoluciones

Partial<Activity>

Actividad de mensaje que contiene el texto.

Comentarios

En este ejemplo se muestra cómo enviar un mensaje de texto simple:

const message = MessageFactory.text('Greetings from example message');