microsoft/teams.net

Public

mirrored from https://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
aacebo/mcp-client

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

Libraries/Microsoft.Teams.Plugins/Microsoft.Teams.Plugins.AspNetCore/Controllers/MessageController.cs

33lines · modecode

1using Microsoft.AspNetCore.Http;
2using Microsoft.AspNetCore.Mvc;
3using Microsoft.Extensions.DependencyInjection;
4using Microsoft.Extensions.Hosting;
5using Microsoft.Teams.Api.Activities;
6using Microsoft.Teams.Api.Auth;
7using Microsoft.Teams.Apps.Extensions;
8
9namespace Microsoft.Teams.Plugins.AspNetCore.Controllers;
10
11[ApiController]
12public class MessageController : ControllerBase
13{
14 private readonly AspNetCorePlugin _plugin;
15 private readonly IHostApplicationLifetime _lifetime;
16
17 public MessageController(AspNetCorePlugin plugin, IHostApplicationLifetime lifetime)
18 {
19 _plugin = plugin;
20 _lifetime = lifetime;
21 }
22
23 [HttpPost("/api/messages")]
24 public async Task<IResult> OnMessage([FromBody] Activity activity)
25 {
26 var authHeader = HttpContext.Request.Headers.Authorization.FirstOrDefault() ?? throw new UnauthorizedAccessException();
27 var token = new JsonWebToken(authHeader.Replace("Bearer ", ""));
28 var context = HttpContext.RequestServices.GetRequiredService<TeamsContext>();
29 context.Token = token;
30 var res = await _plugin.Do(token, activity, _lifetime.ApplicationStopping);
31 return Results.Json(res.Body, statusCode: (int)res.Status);
32 }
33}