TeamsActivityHandler class
Adds support for Microsoft Teams specific events and interactions.
- Extends
-
ActivityHandler
Remarks
Developers may handle Conversation Update activities sent from Microsoft Teams via two methods:
- Overriding methods starting with
on..
and not ending in..Event()
(e.g.onTeamsMembersAdded()
), or instead - Passing callbacks to methods starting with
on..
and ending in...Event()
(e.g.onTeamsMembersAddedEvent()
), to stay in line with older {@see ActivityHandler} implementation.
Developers should use either #1 or #2, above for all Conversation Update activities and not both #2 and #3 for the same activity. Meaning,
developers should override onTeamsMembersAdded()
and not use both onTeamsMembersAdded()
and onTeamsMembersAddedEvent()
.
Developers wanting to handle Invoke activities must override methods starting with handle...()
(e.g. handleTeamsTaskModuleFetch()
).
Methods
Inherited Methods
on |
Registers an activity event handler for the command activity. |
on |
Registers an activity event handler for the CommandResult activity. |
on |
Registers an activity event handler for the conversation update event, emitted for every incoming conversation update activity. |
on |
Registers an activity event handler for the dialog event, emitted as the last event for an incoming activity. |
on |
Registers an activity event handler for the end of conversation activity. |
on |
Registers an activity event handler for the event event, emitted for every incoming event activity. |
on |
Registers an activity event handler for the installationupdate activity. |
on |
Registers an activity event handler for the installationupdate add activity. |
on |
Registers an activity event handler for the installationupdate remove activity. |
on |
Registers an activity event handler for the members added event, emitted for any incoming conversation update activity that includes members added to the conversation. |
on |
Registers an activity event handler for the members removed event, emitted for any incoming conversation update activity that includes members removed from the conversation. |
on |
Registers an activity event handler for the message event, emitted for every incoming message activity. |
on |
Registers an activity event handler for the message reaction event, emitted for every incoming message reaction activity. |
on |
Registers an activity event handler for the reactions added event, emitted for any incoming message reaction activity that describes reactions added to a message. |
on |
Registers an activity event handler for the reactions removed event, emitted for any incoming message reaction activity that describes reactions removed from a message. |
on |
Registers an activity event handler for the tokens-response event, emitted for any incoming
|
on |
Registers an activity event handler for the turn event, emitted for every incoming activity, regardless of type. |
on |
Registers an activity event handler for the typing activity. |
on |
Registers an activity event handler for the unrecognized activity type event, emitted for an incoming activity with a type for which the ActivityHandler doesn't provide an event handler. |
run(Turn |
Called to initiate the event emission process. |
Method Details
onTeamsChannelCreatedEvent((channelInfo: ChannelInfo, teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>)
Registers a handler for TeamsChannelCreated events, such as for when a channel is created.
function onTeamsChannelCreatedEvent(handler: (channelInfo: ChannelInfo, teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>): this
Parameters
- handler
-
(channelInfo: ChannelInfo, teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>
A callback to handle the teams channel created event.
Returns
this
A promise that represents the work queued.
onTeamsChannelDeletedEvent((channelInfo: ChannelInfo, teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>)
Registers a handler for TeamsChannelDeleted events, such as for when a channel is deleted.
function onTeamsChannelDeletedEvent(handler: (channelInfo: ChannelInfo, teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>): this
Parameters
- handler
-
(channelInfo: ChannelInfo, teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>
A callback to handle the teams channel deleted event.
Returns
this
A promise that represents the work queued.
onTeamsChannelRenamedEvent((channelInfo: ChannelInfo, teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>)
Registers a handler for TeamsChannelRenamed events, such as for when a channel is renamed.
function onTeamsChannelRenamedEvent(handler: (channelInfo: ChannelInfo, teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>): this
Parameters
- handler
-
(channelInfo: ChannelInfo, teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>
A callback to handle the teams channel renamed event.
Returns
this
A promise that represents the work queued.
onTeamsChannelRestoredEvent((channelInfo: ChannelInfo, teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>)
Registers a handler for TeamsChannelRestored events, such as for when a channel is restored.
function onTeamsChannelRestoredEvent(handler: (channelInfo: ChannelInfo, teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>): this
Parameters
- handler
-
(channelInfo: ChannelInfo, teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>
A callback to handle the teams channel restored event.
Returns
this
A promise that represents the work queued.
onTeamsMeetingEndEvent((meeting: MeetingEndEventDetails, context: TurnContext, next: () => Promise<void>) => Promise<void>)
Registers a handler for when a Teams meeting ends.
function onTeamsMeetingEndEvent(handler: (meeting: MeetingEndEventDetails, context: TurnContext, next: () => Promise<void>) => Promise<void>): this
Parameters
- handler
-
(meeting: MeetingEndEventDetails, context: TurnContext, next: () => Promise<void>) => Promise<void>
A callback that handles Meeting End events.
Returns
this
A promise that represents the work queued.
onTeamsMeetingStartEvent((meeting: MeetingStartEventDetails, context: TurnContext, next: () => Promise<void>) => Promise<void>)
Registers a handler for when a Teams meeting starts.
function onTeamsMeetingStartEvent(handler: (meeting: MeetingStartEventDetails, context: TurnContext, next: () => Promise<void>) => Promise<void>): this
Parameters
- handler
-
(meeting: MeetingStartEventDetails, context: TurnContext, next: () => Promise<void>) => Promise<void>
A callback that handles Meeting Start events.
Returns
this
A promise that represents the work queued.
onTeamsMembersAddedEvent((membersAdded: TeamsChannelAccount[], teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>)
Registers a handler for TeamsMembersAdded events, such as for when members other than the bot join the channel, such as your bot's welcome logic.
function onTeamsMembersAddedEvent(handler: (membersAdded: TeamsChannelAccount[], teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>): this
Parameters
- handler
-
(membersAdded: TeamsChannelAccount[], teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>
A callback to handle the teams members added event.
Returns
this
A promise that represents the work queued.
onTeamsMembersRemovedEvent((membersRemoved: TeamsChannelAccount[], teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>)
Registers a handler for TeamsMembersRemoved events, such as for when members other than the bot leave the channel, such as your bot's good-bye logic.
function onTeamsMembersRemovedEvent(handler: (membersRemoved: TeamsChannelAccount[], teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>): this
Parameters
- handler
-
(membersRemoved: TeamsChannelAccount[], teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>
A callback to handle the teams members removed event.
Returns
this
A promise that represents the work queued.
onTeamsReadReceiptEvent((receiptInfo: ReadReceiptInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>)
Registers a handler for when a Read Receipt is sent.
function onTeamsReadReceiptEvent(handler: (receiptInfo: ReadReceiptInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>): this
Parameters
- handler
-
(receiptInfo: ReadReceiptInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>
A callback that handles Read Receipt events.
Returns
this
A promise that represents the work queued.
onTeamsTeamArchivedEvent((teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>)
Registers a handler for TeamsTeamArchived events, such as for when a team is archived.
function onTeamsTeamArchivedEvent(handler: (teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>): this
Parameters
- handler
-
(teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>
A callback to handle the teams team archived event.
Returns
this
A promise that represents the work queued.
onTeamsTeamDeletedEvent((teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>)
Registers a handler for TeamsTeamDeleted events, such as for when a team is deleted.
function onTeamsTeamDeletedEvent(handler: (teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>): this
Parameters
- handler
-
(teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>
A callback to handle the teams team deleted event.
Returns
this
A promise that represents the work queued.
onTeamsTeamHardDeletedEvent((teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>)
Registers a handler for TeamsTeamHardDeleted events, such as for when a team is hard-deleted.
function onTeamsTeamHardDeletedEvent(handler: (teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>): this
Parameters
- handler
-
(teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>
A callback to handle the teams team hard deleted event.
Returns
this
A promise that represents the work queued.
onTeamsTeamRenamedEvent((teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>)
Registers a handler for TeamsTeamRenamed events, such as for when a team is renamed.
function onTeamsTeamRenamedEvent(handler: (teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>): this
Parameters
- handler
-
(teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>
A callback to handle the teams team renamed event.
Returns
this
A promise that represents the work queued.
onTeamsTeamRestoredEvent((teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>)
Registers a handler for TeamsTeamRestored events, such as for when a team is restored.
function onTeamsTeamRestoredEvent(handler: (teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>): this
Parameters
- handler
-
(teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>
A callback to handle the teams team restored event.
Returns
this
A promise that represents the work queued.
onTeamsTeamUnarchivedEvent((teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>)
Registers a handler for TeamsTeamUnarchived events, such as for when a team is unarchived.
function onTeamsTeamUnarchivedEvent(handler: (teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>): this
Parameters
- handler
-
(teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>
A callback to handle the teams team unarchived event.
Returns
this
A promise that represents the work queued.
Inherited Method Details
onCommand(BotHandler)
Registers an activity event handler for the command activity.
function onCommand(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object.
Remarks
To handle a Command event, use the onCommand type-specific event handler.
Inherited From ActivityHandler.onCommand
onCommandResult(BotHandler)
Registers an activity event handler for the CommandResult activity.
function onCommandResult(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object.
Remarks
To handle a CommandResult event, use the onCommandResult type-specific event handler.
Inherited From ActivityHandler.onCommandResult
onConversationUpdate(BotHandler)
Registers an activity event handler for the conversation update event, emitted for every incoming conversation update activity.
function onConversationUpdate(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object.
Remarks
Conversation update activities describe a changes to a conversation's metadata, such as title, participants, or other channel-specific information.
To handle when members are added to or removed from the conversation, use the onMembersAdded and onMembersRemoved sub-type event handlers.
Inherited From ActivityHandler.onConversationUpdate
onDialog(BotHandler)
Registers an activity event handler for the dialog event, emitted as the last event for an incoming activity.
function onDialog(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object.
Inherited From ActivityHandler.onDialog
onEndOfConversation(BotHandler)
Registers an activity event handler for the end of conversation activity.
function onEndOfConversation(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object.
Remarks
This activity is typically send from a Skill to a Skill caller indicating the end of that particular child conversation.
To handle an End of Conversation, use the onEndOfConversation type-specific event handler.
Inherited From ActivityHandler.onEndOfConversation
onEvent(BotHandler)
Registers an activity event handler for the event event, emitted for every incoming event activity.
function onEvent(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object.
Remarks
Event activities communicate programmatic information from a client or channel to a bot. The meaning of an event activity is defined by the activity's name property, which is meaningful within the scope of a channel. Event activities are designed to carry both interactive information (such as button clicks) and non-interactive information (such as a notification of a client automatically updating an embedded speech model).
To handle a tokens/response
event event, use the
onTokenResponseEvent sub-type
event handler. To handle other named events, add logic to this handler.
Inherited From ActivityHandler.onEvent
onInstallationUpdate(BotHandler)
Registers an activity event handler for the installationupdate activity.
function onInstallationUpdate(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object.
Remarks
To handle a InstallationUpdate event, use the onInstallationUpdate type-specific event handler.
Inherited From ActivityHandler.onInstallationUpdate
onInstallationUpdateAdd(BotHandler)
Registers an activity event handler for the installationupdate add activity.
function onInstallationUpdateAdd(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object. To handle a InstallationUpdateAdd event, use the onInstallationUpdateAdd type-specific event handler.
Inherited From ActivityHandler.onInstallationUpdateAdd
onInstallationUpdateRemove(BotHandler)
Registers an activity event handler for the installationupdate remove activity.
function onInstallationUpdateRemove(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object.
Remarks
To handle a InstallationUpdateRemove event, use the onInstallationUpdateRemove type-specific event handler.
Inherited From ActivityHandler.onInstallationUpdateRemove
onMembersAdded(BotHandler)
Registers an activity event handler for the members added event, emitted for any incoming conversation update activity that includes members added to the conversation.
function onMembersAdded(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object.
Remarks
The activity's membersAdded property contains the members added to the conversation, which can include the bot.
To handle conversation update events in general, use the onConversationUpdate type-specific event handler.
Inherited From ActivityHandler.onMembersAdded
onMembersRemoved(BotHandler)
Registers an activity event handler for the members removed event, emitted for any incoming conversation update activity that includes members removed from the conversation.
function onMembersRemoved(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object.
Remarks
The activity's membersRemoved property contains the members removed from the conversation, which can include the bot.
To handle conversation update events in general, use the onConversationUpdate type-specific event handler.
Inherited From ActivityHandler.onMembersRemoved
onMessage(BotHandler)
Registers an activity event handler for the message event, emitted for every incoming message activity.
function onMessage(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object.
Remarks
Message activities represent content intended to be shown within a conversational interface
and can contain text, speech, interactive cards, and binary or unknown attachments.
Not all message activities contain text, the activity's text
property can be null
or undefined
.
Inherited From ActivityHandler.onMessage
onMessageReaction(BotHandler)
Registers an activity event handler for the message reaction event, emitted for every incoming message reaction activity.
function onMessageReaction(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object.
Remarks
Message reaction activities represent a social interaction on an existing message activity within a conversation. The original activity is referred to by the message reaction activity's replyToId property. The from property represents the source of the reaction, such as the user that reacted to the message.
To handle when reactions are added to or removed from messages in the conversation, use the onReactionsAdded and onReactionsRemoved sub-type event handlers.
Inherited From ActivityHandler.onMessageReaction
onReactionsAdded(BotHandler)
Registers an activity event handler for the reactions added event, emitted for any incoming message reaction activity that describes reactions added to a message.
function onReactionsAdded(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object.
Remarks
The activity's reactionsAdded property includes one or more reactions that were added.
To handle message reaction events in general, use the onMessageReaction type-specific event handler.
Inherited From ActivityHandler.onReactionsAdded
onReactionsRemoved(BotHandler)
Registers an activity event handler for the reactions removed event, emitted for any incoming message reaction activity that describes reactions removed from a message.
function onReactionsRemoved(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object.
Remarks
The activity's reactionsRemoved property includes one or more reactions that were removed.
To handle message reaction events in general, use the onMessageReaction type-specific event handler.
Inherited From ActivityHandler.onReactionsRemoved
onTokenResponseEvent(BotHandler)
Registers an activity event handler for the tokens-response event, emitted for any incoming
tokens/response
event activity. These are generated as part of the OAuth authentication flow.
function onTokenResponseEvent(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object.
Remarks
The activity's value property contains the user token.
If your bot handles authentication using an OAuthPrompt within a dialog, then the dialog will need to receive this activity to complete the authentication flow.
To handle other named events and event events in general, use the onEvent type-specific event handler.
Inherited From ActivityHandler.onTokenResponseEvent
onTurn(BotHandler)
Registers an activity event handler for the turn event, emitted for every incoming activity, regardless of type.
function onTurn(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object.
Inherited From ActivityHandler.onTurn
onTyping(BotHandler)
Registers an activity event handler for the typing activity.
function onTyping(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object.
Remarks
To handle a Typing event, use the onTyping type-specific event handler.
Inherited From ActivityHandler.onTyping
onUnrecognizedActivityType(BotHandler)
Registers an activity event handler for the unrecognized activity type event, emitted for an incoming activity with a type for which the ActivityHandler doesn't provide an event handler.
function onUnrecognizedActivityType(handler: BotHandler): this
Parameters
- handler
-
BotHandler
The event handler.
Returns
this
A reference to the ActivityHandler object.
Remarks
The ActivityHandler
does not define events for all activity types defined in the
Bot Framework Activity schema. In addition,
channels and custom adapters can create Activities with
types not in the schema. When the activity handler receives such an event, it emits an unrecognized activity type event.
The activity's type property contains the activity type.
Inherited From ActivityHandler.onUnrecognizedActivityType
run(TurnContext)
Called to initiate the event emission process.
function run(context: TurnContext): Promise<void>
Parameters
- context
-
TurnContext
The context object for the current turn.
Returns
Promise<void>
Remarks
Typically, you would provide this method as the function handler that the adapter calls to perform the bot's logic after the received activity has been pre-processed by the adapter and routed through any middleware.
For example:
server.post('/api/messages', (req, res) => {
adapter.processActivity(req, res, async (context) => {
// Route to bot's activity logic.
await bot.run(context);
});
});
See also
Inherited From ActivityHandler.run