forked from BotBuilderCommunity/botbuilder-community-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SentimentMiddleware.cs
33 lines (28 loc) · 957 Bytes
/
SentimentMiddleware.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
using Microsoft.Bot.Builder;
using Microsoft.Bot.Schema;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Bot.Builder.Community.Middleware.SentimentAnalysis
{
public class SentimentMiddleware : IMiddleware
{
public SentimentMiddleware(string apiKey)
{
ApiKey = apiKey;
}
public SentimentMiddleware() { }
public string ApiKey { get; }
public async Task OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken = default(CancellationToken))
{
if (turnContext.Activity.Type is ActivityTypes.Message)
{
turnContext.TurnState.Add<string>("Sentiment", await turnContext.Activity.Text.Sentiment(ApiKey));
}
await next(cancellationToken);
}
}
}