forked from rvinothrajendran/BotTutorialSample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmptyBot.cs
More file actions
47 lines (39 loc) · 1.76 KB
/
Copy pathEmptyBot.cs
File metadata and controls
47 lines (39 loc) · 1.76 KB
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Collections.Concurrent;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Schema;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace ProactiveDemo
{
public class EmptyBot : ActivityHandler
{
private ConcurrentDictionary<string, ConversationReference> _userConversationReferences;
public EmptyBot(ConcurrentDictionary<string, ConversationReference> userConversationReferences)
{
_userConversationReferences = userConversationReferences;
}
protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
{
foreach (var member in membersAdded)
{
if (member.Id != turnContext.Activity.Recipient.Id)
{
await turnContext.SendActivityAsync(MessageFactory.Text($"Hello world!"), cancellationToken);
}
}
}
protected override Task OnConversationUpdateActivityAsync(ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
{
if (turnContext.Activity is Activity activity)
{
var conReference = activity.GetConversationReference();
_userConversationReferences.AddOrUpdate(conReference.User.Id, conReference,
(key, newValue) => conReference);
}
return base.OnConversationUpdateActivityAsync(turnContext, cancellationToken);
}
}
}