Share via


AgentBuilderCloudAdapter module

Classes

BotSsoExecutionDialog

Sso execution dialog, use to handle sso command

CardActionBot

A card action bot to respond to adaptive card universal actions.

Channel

A NotificationTarget that represents a team channel.

CommandBot

A command bot for receiving commands and sending responses in Teams.

ConversationBot

Provide utilities for bot conversation, including:

  • handle command and response.
  • send notification to varies targets (e.g., member, group, channel).

Example

For command and response, you can register your commands through the constructor, or use the registerCommand and registerCommands API to add commands later.

import { BotBuilderCloudAdapter } from "@microsoft/teamsfx";
import ConversationBot = BotBuilderCloudAdapter.ConversationBot;

// register through constructor
const conversationBot = new ConversationBot({
  command: {
    enabled: true,
    commands: [ new HelloWorldCommandHandler() ],
  },
});

// register through `register*` API
conversationBot.command.registerCommand(new HelpCommandHandler());

For notification, you can enable notification at initialization, then send notifications at any time.

import { BotBuilderCloudAdapter } from "@microsoft/teamsfx";
import ConversationBot = BotBuilderCloudAdapter.ConversationBot;

// enable through constructor
const conversationBot = new ConversationBot({
  notification: {
    enabled: true,
  },
});

// get all bot installations and send message
for (const target of await conversationBot.notification.installations()) {
  await target.sendMessage("Hello Notification");
}

// alternative - send message to all members
for (const target of await conversationBot.notification.installations()) {
  for (const member of await target.members()) {
    await member.sendMessage("Hello Notification");
  }
}
Member

A NotificationTarget that represents a team member.

NotificationBot

Provide utilities to send notification to varies targets (e.g., member, group, channel).

TeamsBotInstallation

A NotificationTarget that represents a bot installation. Teams Bot could be installed into

  • Personal chat
  • Group chat
  • Team (by default the General channel)

Interfaces

ConversationOptions

Options to initialize ConversationBot

NotificationOptions

Options to initialize NotificationBot.

Enums

SearchScope

The search scope when calling findMember and findAllMembers. The search scope is a flagged enum and it can be combined with |. For example, to search from personal chat and group chat, use SearchScope.Person | SearchScope.Group.

Functions

sendAdaptiveCard(NotificationTarget, unknown, (context: TurnContext, error: Error) => Promise<void>)

Send an adaptive card message to a notification target.

sendMessage(NotificationTarget, string, (context: TurnContext, error: Error) => Promise<void>)

Send a plain text message to a notification target.

Function Details

sendAdaptiveCard(NotificationTarget, unknown, (context: TurnContext, error: Error) => Promise<void>)

Send an adaptive card message to a notification target.

function sendAdaptiveCard(target: NotificationTarget, card: unknown, onError?: (context: TurnContext, error: Error) => Promise<void>): Promise<MessageResponse>

Parameters

target
NotificationTarget

The notification target.

card

unknown

The adaptive card raw JSON.

onError

(context: TurnContext, error: Error) => Promise<void>

An optional error handler that can catch exceptions during adaptive card sending. If not defined, error will be handled by BotAdapter.onTurnError.

Returns

Promise<MessageResponse>

The response of sending adaptive card message.

sendMessage(NotificationTarget, string, (context: TurnContext, error: Error) => Promise<void>)

Send a plain text message to a notification target.

function sendMessage(target: NotificationTarget, text: string, onError?: (context: TurnContext, error: Error) => Promise<void>): Promise<MessageResponse>

Parameters

target
NotificationTarget

The notification target.

text

string

The plain text message.

onError

(context: TurnContext, error: Error) => Promise<void>

An optional error handler that can catch exceptions during message sending. If not defined, error will be handled by BotAdapter.onTurnError.

Returns

Promise<MessageResponse>

The response of sending message.