Freigeben über


MessageBuilder class

Provides utility method to build bot message with cards that supported in Teams.

Methods

attachAdaptiveCard<TData>(unknown, TData)

Build a bot message activity attached with adaptive card.

Example

const cardTemplate = {
  type: "AdaptiveCard",
  body: [
    {
      "type": "TextBlock",
      "text": "${title}",
      "size": "Large"
    },
    {
      "type": "TextBlock",
      "text": "${description}"
    }],
    $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
    version: "1.4"
 };

type CardData = {
  title: string,
  description: string
};
const card = MessageBuilder.attachAdaptiveCard<CardData>(
  cardTemplate, {
  title: "sample card title",
  description: "sample card description"
});
attachAdaptiveCardWithoutData(unknown)

Build a bot message activity attached with an adaptive card.

attachContent(Attachment)

Add an attachement to a bot activity.

attachHeroCard(string, (string | CardImage)[], (string | CardAction)[], Partial<HeroCard>)

Build a bot message activity attached with an hero card.

Example

const message = MessageBuilder.attachHeroCard(
     'sample title',
     ['https://example.com/sample.jpg'],
     ['action']
);
attachO365ConnectorCard(O365ConnectorCard)

Build a bot message activity attached with an Office 365 connector card.

AttachReceiptCard(ReceiptCard)

Build a message activity attached with a receipt card.

attachSigninCard(string, string, string)

Returns an attachment for a sign-in card.

attachThumbnailCard(string, (string | CardImage)[], (string | CardAction)[], Partial<ThumbnailCard>)

Method Details

attachAdaptiveCard<TData>(unknown, TData)

Build a bot message activity attached with adaptive card.

Example

const cardTemplate = {
  type: "AdaptiveCard",
  body: [
    {
      "type": "TextBlock",
      "text": "${title}",
      "size": "Large"
    },
    {
      "type": "TextBlock",
      "text": "${description}"
    }],
    $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
    version: "1.4"
 };

type CardData = {
  title: string,
  description: string
};
const card = MessageBuilder.attachAdaptiveCard<CardData>(
  cardTemplate, {
  title: "sample card title",
  description: "sample card description"
});
static function attachAdaptiveCard<TData>(cardTemplate: unknown, data: TData): Partial<Activity>

Parameters

cardTemplate

unknown

The adaptive card template.

data

TData

card data used to render the template.

Returns

Partial<Activity>

A bot message activity attached with an adaptive card.

attachAdaptiveCardWithoutData(unknown)

Build a bot message activity attached with an adaptive card.

static function attachAdaptiveCardWithoutData(card: unknown): Partial<Activity>

Parameters

card

unknown

The adaptive card content.

Returns

Partial<Activity>

A bot message activity attached with an adaptive card.

attachContent(Attachment)

Add an attachement to a bot activity.

static function attachContent(attachement: Attachment): Partial<Activity>

Parameters

attachement

Attachment

The attachment object to attach.

Returns

Partial<Activity>

A message activity with an attachment.

attachHeroCard(string, (string | CardImage)[], (string | CardAction)[], Partial<HeroCard>)

Build a bot message activity attached with an hero card.

Example

const message = MessageBuilder.attachHeroCard(
     'sample title',
     ['https://example.com/sample.jpg'],
     ['action']
);
static function attachHeroCard(title: string, images?: (string | CardImage)[], buttons?: (string | CardAction)[], other?: Partial<HeroCard>): Partial<Activity>

Parameters

title

string

The card title.

images

(string | CardImage)[]

Optional. The array of images to include on the card.

buttons

(string | CardAction)[]

Optional. The array of buttons to include on the card. Each string in the array is converted to an imBack button with a title and value set to the value of the string.

other

Partial<HeroCard>

Optional. Any additional properties to include on the card.

Returns

Partial<Activity>

A bot message activity attached with a hero card.

attachO365ConnectorCard(O365ConnectorCard)

Build a bot message activity attached with an Office 365 connector card.

static function attachO365ConnectorCard(card: O365ConnectorCard): Partial<Activity>

Parameters

card

O365ConnectorCard

A description of the Office 365 connector card.

Returns

Partial<Activity>

A bot message activity attached with an Office 365 connector card.

AttachReceiptCard(ReceiptCard)

Build a message activity attached with a receipt card.

static function AttachReceiptCard(card: ReceiptCard): Partial<Activity>

Parameters

card

ReceiptCard

A description of the receipt card.

Returns

Partial<Activity>

A message activity attached with a receipt card.

attachSigninCard(string, string, string)

Returns an attachment for a sign-in card.

static function attachSigninCard(title: string, url: string, text?: string): Partial<Activity>

Parameters

title

string

The title for the card's sign-in button.

url

string

The URL of the sign-in page to use.

text

string

Optional. Additional text to include on the card.

Returns

Partial<Activity>

A bot message activity attached with a sign-in card.

Remarks

For channels that don't natively support sign-in cards, an alternative message is rendered.

attachThumbnailCard(string, (string | CardImage)[], (string | CardAction)[], Partial<ThumbnailCard>)

static function attachThumbnailCard(title: string, images?: (string | CardImage)[], buttons?: (string | CardAction)[], other?: Partial<ThumbnailCard>): Partial<Activity>

Parameters

title

string

The card title.

images

(string | CardImage)[]

Optional. The array of images to include on the card.

buttons

(string | CardAction)[]

Optional. The array of buttons to include on the card. Each string in the array is converted to an imBack button with a title and value set to the value of the string.

other

Partial<ThumbnailCard>

Optional. Any additional properties to include on the card.

Returns

Partial<Activity>

A message activity attached with a thumbnail card