Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional channel/chat lifecycle events #2471

Merged
merged 15 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 131 additions & 3 deletions libraries/botbuilder/src/teamsActivityHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,27 @@ export class TeamsActivityHandler extends ActivityHandler {
case 'channelRenamed':
return await this.onTeamsChannelRenamed(context);

case 'teamArchived':
return await this.onTeamsTeamArchived(context);

case 'teamDeleted':
return await this.onTeamsTeamDeleted(context);

case 'teamHardDeleted':
return await this.onTeamsTeamHardDeleted(context);

case 'channelRestored':
return await this.onTeamsChannelRestored(context);

case 'teamRenamed':
return await this.onTeamsTeamRenamed(context);


case 'teamRestored':
return await this.onTeamsTeamRestored(context);

case 'teamUnarchived':
return await this.onTeamsTeamUnarchived(context);

default:
return await super.dispatchConversationUpdateActivity(context);
}
Expand Down Expand Up @@ -499,6 +514,38 @@ export class TeamsActivityHandler extends ActivityHandler {
}

/**
* Invoked when a Team Archived event activity is received from the connector.
* Team Archived correspond to the user archiving a team.
* @param context The context for this turn.
* @returns A promise that represents the work queued.
*/
protected async onTeamsTeamArchived(context): Promise<void> {
await this.handle(context, 'TeamsTeamArchived', this.defaultNextEvent(context));
}

/**
* Invoked when a Team Deleted event activity is received from the connector.
* Team Deleted correspond to the user deleting a team.
* @param context The context for this turn.
* @returns A promise that represents the work queued.
*/
protected async onTeamsTeamDeleted(context): Promise<void> {
await this.handle(context, 'TeamsTeamDeleted', this.defaultNextEvent(context));
}

/**
* Invoked when a Team Hard Deleted event activity is received from the connector.
* Team Hard Deleted correspond to the user hard-deleting a team.
* @param context The context for this turn.
* @returns A promise that represents the work queued.
*/
protected async onTeamsTeamHardDeleted(context): Promise<void> {
await this.handle(context, 'TeamsTeamHardDeleted', this.defaultNextEvent(context));
}

/**
*
* @param context
* Invoked when a Channel Restored event activity is received from the connector.
* Channel Restored correspond to the user restoring a previously deleted channel.
* @param context The context for this turn.
Expand All @@ -519,6 +566,27 @@ export class TeamsActivityHandler extends ActivityHandler {
}

/**
* Invoked when a Team Restored event activity is received from the connector.
* Team Restored correspond to the user restoring a team.
* @param context The context for this turn.
* @returns A promise that represents the work queued.
*/
protected async onTeamsTeamRestored(context): Promise<void> {
await this.handle(context, 'TeamsTeamRestored', this.defaultNextEvent(context));
}

/**
* Invoked when a Team Unarchived event activity is received from the connector.
* Team Unarchived correspond to the user unarchiving a team.
* @param context The context for this turn.
* @returns A promise that represents the work queued.
*/
protected async onTeamsTeamUnarchived(context): Promise<void> {
await this.handle(context, 'TeamsTeamUnarchived', this.defaultNextEvent(context));
}

/**
*
* Override this in a derived class to provide logic for when members other than the bot
* join the channel, such as your bot's welcome logic.
* @param handler
Expand Down Expand Up @@ -580,6 +648,42 @@ export class TeamsActivityHandler extends ActivityHandler {
});
}

/**
* Override this in a derived class to provide logic for when a team is archived.
* @param handler
* @returns A promise that represents the work queued.
*/
public onTeamsTeamArchivedEvent(handler: (teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>): this {
return this.on('TeamsTeamArchived', async (context, next) => {
const teamsChannelData = context.activity.channelData as TeamsChannelData;
await handler(teamsChannelData.team, context, next);
});
}

/**
* Override this in a derived class to provide logic for when a team is deleted.
* @param handler
* @returns A promise that represents the work queued.
*/
public onTeamsTeamDeletedEvent(handler: (teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>): this {
return this.on('TeamsTeamDeleted', async (context, next) => {
const teamsChannelData = context.activity.channelData as TeamsChannelData;
await handler(teamsChannelData.team, context, next);
});
}

/**
* Override this in a derived class to provide logic for when a team is hard-deleted.
* @param handler
* @returns A promise that represents the work queued.
*/
public onTeamsTeamHardDeletedEvent(handler: (teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>): this {
return this.on('TeamsTeamHardDeleted', async (context, next) => {
const teamsChannelData = context.activity.channelData as TeamsChannelData;
await handler(teamsChannelData.team, context, next);
});
}

/**
* Override this in a derived class to provide logic for when a channel is restored.
* @param handler
Expand All @@ -603,4 +707,28 @@ export class TeamsActivityHandler extends ActivityHandler {
await handler(teamsChannelData.team, context, next);
});
}
}

/**
* Override this in a derived class to provide logic for when a team is restored.
* @param handler
* @returns A promise that represents the work queued.
*/
public onTeamsTeamRestoredEvent(handler: (teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>): this {
return this.on('TeamsTeamRestored', async (context, next) => {
const teamsChannelData = context.activity.channelData as TeamsChannelData;
await handler(teamsChannelData.team, context, next);
});
}

/**
* Override this in a derived class to provide logic for when a team is unarchived.
* @param handler
* @returns A promise that represents the work queued.
*/
public onTeamsTeamUnarchivedEvent(handler: (teamInfo: TeamInfo, context: TurnContext, next: () => Promise<void>) => Promise<void>): this {
return this.on('TeamsTeamUnarchived', async (context, next) => {
const teamsChannelData = context.activity.channelData as TeamsChannelData;
await handler(teamsChannelData.team, context, next);
});
}
}
Loading