- Notifications
You must be signed in to change notification settings - Fork 843
/
Copy pathTeamsBot.cs
66 lines (60 loc) · 3.12 KB
/
TeamsBot.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
usingSystem.Collections.Generic;
usingSystem.Threading;
usingSystem.Threading.Tasks;
usingMicrosoft.Bot.Builder;
usingMicrosoft.Bot.Builder.Dialogs;
usingMicrosoft.Bot.Schema;
usingMicrosoft.Extensions.Logging;
namespaceMicrosoft.BotBuilderSamples
{
/// <summary>
/// This bot is derived from the <see cref="DialogBot{T}"/> class and handles Teams-specific activities.
/// </summary>
/// <typeparam name="T">The type of Dialog to be run.</typeparam>
publicclassTeamsBot<T>:DialogBot<T>whereT:Dialog
{
/// <summary>
/// Initializes a new instance of the <see cref="TeamsBot{T}"/> class.
/// </summary>
/// <param name="conversationState">The conversation state.</param>
/// <param name="userState">The user state.</param>
/// <param name="dialog">The dialog to be run.</param>
/// <param name="logger">The logger.</param>
publicTeamsBot(ConversationStateconversationState,UserStateuserState,Tdialog,ILogger<DialogBot<T>>logger)
:base(conversationState,userState,dialog,logger)
{
}
/// <summary>
/// Handles the event when members are added to the conversation.
/// </summary>
/// <param name="membersAdded">The list of members added to the conversation.</param>
/// <param name="turnContext">The context object for this turn.</param>
/// <param name="cancellationToken">A cancellation token.</param>
/// <returns>A task that represents the work queued to execute.</returns>
protectedoverrideasyncTaskOnMembersAddedAsync(IList<ChannelAccount>membersAdded,ITurnContext<IConversationUpdateActivity>turnContext,CancellationTokencancellationToken)
{
foreach(varmemberinturnContext.Activity.MembersAdded)
{
if(member.Id!=turnContext.Activity.Recipient.Id)
{
awaitturnContext.SendActivityAsync(MessageFactory.Text("Welcome to AuthenticationBot. Type anything to get logged in. Type 'logout' to sign-out."),cancellationToken);
}
}
}
/// <summary>
/// Handles the Teams Sign-in verification state.
/// </summary>
/// <param name="turnContext">The context object for this turn.</param>
/// <param name="cancellationToken">A cancellation token.</param>
/// <returns>A task that represents the work queued to execute.</returns>
protectedoverrideasyncTaskOnTeamsSigninVerifyStateAsync(ITurnContext<IInvokeActivity>turnContext,CancellationTokencancellationToken)
{
_logger.LogInformation("Running dialog with signin/verifystate from an Invoke Activity.");
// The OAuth Prompt needs to see the Invoke Activity in order to complete the login process.
// Run the Dialog with the new Invoke Activity.
await_dialog.RunAsync(turnContext,_conversationState.CreateProperty<DialogState>(nameof(DialogState)),cancellationToken);
}
}
}