microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/sub-pr-338

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

core/samples/TeamsChannelBot/Program.cs

141lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using Microsoft.Teams.Bot.Apps;
5using Microsoft.Teams.Bot.Apps.Handlers;
6
7var builder = TeamsBotApplication.CreateBuilder(args);
8var app = builder.Build();
9
10
11//TODO : implement next();
12/*app.OnConversationUpdate(async (context, cancellationToken) =>
13{
14 Console.WriteLine($"[ConversationUpdate] Conversation updated");
15}
16);
17;*/
18
19// ==================== CHANNEL EVENT HANDLERS ====================
20
21app.OnChannelCreated(async (context, cancellationToken) =>
22{
23 var channelName = context.Activity.ChannelData?.Channel?.Name ?? "unknown";
24 Console.WriteLine($"[ChannelCreated] Channel '{channelName}' was created");
25 await context.SendActivityAsync($"New channel created: {channelName}", cancellationToken);
26});
27
28app.OnChannelDeleted(async (context, cancellationToken) =>
29{
30 var channelName = context.Activity.ChannelData?.Channel?.Name ?? "unknown";
31 Console.WriteLine($"[ChannelDeleted] Channel '{channelName}' was deleted");
32 await context.SendActivityAsync($"Channel deleted: {channelName}", cancellationToken);
33});
34
35app.OnChannelRenamed(async (context, cancellationToken) =>
36{
37 var channelName = context.Activity.ChannelData?.Channel?.Name ?? "unknown";
38 Console.WriteLine($"[ChannelRenamed] Channel renamed to '{channelName}'");
39 await context.SendActivityAsync($"Channel renamed to: {channelName}", cancellationToken);
40});
41
42/*
43//not able to test - no activity received
44app.OnChannelRestored(async (context, cancellationToken) =>
45{
46 var channelName = context.Activity.ChannelData?.Channel?.Name ?? "unknown";
47 Console.WriteLine($"[ChannelRestored] Channel '{channelName}' was restored");
48 await context.SendActivityAsync($"Channel restored: {channelName}", cancellationToken);
49});
50
51// not able to test - can't add bot to shared channel
52app.OnChannelShared(async (context, cancellationToken) =>
53{
54 var channelName = context.Activity.ChannelData?.Channel?.Name ?? "unknown";
55 Console.WriteLine($"[ChannelShared] Channel '{channelName}' was shared");
56 await context.SendActivityAsync($"Channel shared: {channelName}", cancellationToken);
57});
58
59// not able to test - can't add bot to shared channel
60app.OnChannelUnshared(async (context, cancellationToken) =>
61{
62 var channelName = context.Activity.ChannelData?.Channel?.Name ?? "unknown";
63 Console.WriteLine($"[ChannelUnshared] Channel '{channelName}' was unshared");
64 await context.SendActivityAsync($"Channel unshared: {channelName}", cancellationToken);
65});
66
67// not able to test - can't add bot to private/shared channel
68app.OnChannelMemberAdded(async (context, cancellationToken) =>
69{
70 Console.WriteLine($"[ChannelMemberAdded] Member added to channel");
71 await context.SendActivityAsync("A member was added to the channel", cancellationToken);
72});
73
74// not able to test - can't add bot to private/shared channel
75app.OnChannelMemberRemoved(async (context, cancellationToken) =>
76{
77 Console.WriteLine($"[ChannelMemberRemoved] Member removed from channel");
78 await context.SendActivityAsync("A member was removed from the channel", cancellationToken);
79});
80*/
81
82// ==================== TEAM EVENT HANDLERS ====================
83
84app.OnTeamMemberAdded(async (context, cancellationToken) =>
85{
86 Console.WriteLine($"[TeamMemberAdded] Member added to team");
87 await context.SendActivityAsync("A member was added to the team", cancellationToken);
88});
89
90app.OnTeamMemberRemoved(async (context, cancellationToken) =>
91{
92 Console.WriteLine($"[TeamMemberRemoved] Member removed from team");
93 await context.SendActivityAsync("A member was removed from the team", cancellationToken);
94});
95
96app.OnTeamArchived((context, cancellationToken) =>
97{
98 var teamName = context.Activity.ChannelData?.Team?.Name ?? "unknown";
99 Console.WriteLine($"[TeamArchived] Team '{teamName}' was archived");
100 return Task.CompletedTask;
101});
102
103app.OnTeamDeleted((context, cancellationToken) =>
104{
105 var teamName = context.Activity.ChannelData?.Team?.Name ?? "unknown";
106 Console.WriteLine($"[TeamDeleted] Team '{teamName}' was deleted");
107 return Task.CompletedTask;
108});
109
110app.OnTeamRenamed(async (context, cancellationToken) =>
111{
112 var teamName = context.Activity.ChannelData?.Team?.Name ?? "unknown";
113 Console.WriteLine($"[TeamRenamed] Team renamed to '{teamName}'");
114 await context.SendActivityAsync($"Team renamed to: {teamName}", cancellationToken);
115});
116
117app.OnTeamUnarchived(async (context, cancellationToken) =>
118{
119 var teamName = context.Activity.ChannelData?.Team?.Name ?? "unknown";
120 Console.WriteLine($"[TeamUnarchived] Team '{teamName}' was unarchived");
121 await context.SendActivityAsync($"Team unarchived: {teamName}", cancellationToken);
122});
123/*
124// how to test ?
125app.OnTeamHardDeleted((context, cancellationToken) =>
126{
127 var teamName = context.Activity.ChannelData?.Team?.Name ?? "unknown";
128 Console.WriteLine($"[TeamHardDeleted] Team '{teamName}' was permanently deleted");
129 return Task.CompletedTask;
130});
131
132// how to test ? Restore is unarchived
133app.OnTeamRestored(async (context, cancellationToken) =>
134{
135 var teamName = context.Activity.ChannelData?.Team?.Name ?? "unknown";
136 Console.WriteLine($"[TeamRestored] Team '{teamName}' was restored");
137 await context.SendActivityAsync($"Team restored: {teamName}", cancellationToken);
138});
139*/
140
141app.Run();
142