-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
33 lines (27 loc) · 1.07 KB
/
Program.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.Connector;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
var msAppId = "<your microsoft app id>";
var msPwd = "<your microsoft password>";
app.MapPost("/api/messages", async (Activity activity, HttpContext context) => {
try
{
var authHeader = context.Request.Headers["Authorization"].SingleOrDefault();
await JwtTokenValidation.AuthenticateRequest(activity, authHeader, new SimpleCredentialProvider(msAppId, msPwd), null);
}
catch (UnauthorizedAccessException)
{
return Results.Unauthorized();
}
if (activity.Type == ActivityTypes.Message)
{
var reply = activity.CreateReply($"You said: {activity.Text}");
var connector = new ConnectorClient(new Uri(activity.ServiceUrl, UriKind.Absolute),
new MicrosoftAppCredentials(msAppId, msPwd));
await connector.Conversations.ReplyToActivityAsync(reply);
}
return Results.Ok();
});
app.Run();