forked from MissionMarsFourthHorizon/operation-max
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AgentLoginScorable.cs
64 lines (54 loc) · 2.2 KB
/
AgentLoginScorable.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
namespace HelpDeskBot.Dialogs
{
using System;
using System.Threading;
using System.Threading.Tasks;
using HandOff;
using Microsoft.Bot.Builder.Dialogs.Internals;
using Microsoft.Bot.Builder.Internals.Fibers;
using Microsoft.Bot.Builder.Scorables.Internals;
using Microsoft.Bot.Connector;
public class AgentLoginScorable : ScorableBase<IActivity, string, double>
{
private const string TRIGGER = "/agent login";
private readonly Provider provider;
private readonly IBotData botData;
public AgentLoginScorable(IBotData botData, Provider provider)
{
SetField.NotNull(out this.botData, nameof(botData), botData);
SetField.NotNull(out this.provider, nameof(provider), provider);
}
protected override Task DoneAsync(IActivity item, string state, CancellationToken token)
{
return Task.CompletedTask;
}
protected override double GetScore(IActivity item, string state)
{
return 1.0;
}
protected override bool HasScore(IActivity item, string state)
{
return state != null;
}
protected async override Task PostAsync(IActivity item, string state, CancellationToken token)
{
await this.botData.SetAgent(true, token);
ConnectorClient connector = new ConnectorClient(new Uri(item.ServiceUrl));
var welcome = $"Welcome back human agent, there are {this.provider.Pending()} users waiting in the queue.\n\nType _agent help_ for more details.";
Activity reply = ((Activity)item).CreateReply(welcome);
await connector.Conversations.ReplyToActivityAsync(reply, token);
}
protected async override Task<string> PrepareAsync(IActivity item, CancellationToken token)
{
var message = item.AsMessageActivity();
if (message != null && !string.IsNullOrWhiteSpace(message.Text))
{
if (message.Text.Equals(TRIGGER, StringComparison.InvariantCultureIgnoreCase))
{
return message.Text;
}
}
return null;
}
}
}