microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
next/core-activitybuilder

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

50lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4using Microsoft.AspNetCore.Http;
5using Microsoft.AspNetCore.Mvc;
6using Microsoft.Bot.Builder;
7using Microsoft.Bot.Builder.Integration.AspNet.Core;
8using Microsoft.Extensions.Hosting;
9
10namespace Microsoft.Teams.Plugins.AspNetCore.BotBuilder
11{
12 [ApiController]
13 [Obsolete("Use Minimal APIs instead.")]
14 public class MessageController : ControllerBase
15 {
16 private readonly IBotFrameworkHttpAdapter _adapter;
17 private readonly IBot _bot;
18
19 private readonly AspNetCorePlugin _plugin;
20
21 private readonly IHostApplicationLifetime _lifetime;
22
23 public MessageController(IBotFrameworkHttpAdapter adapter, IBot bot, AspNetCorePlugin plugin, IHostApplicationLifetime lifetime)
24 {
25 _plugin = plugin;
26 _lifetime = lifetime;
27 _adapter = adapter;
28 _bot = bot;
29 }
30
31 [HttpPost("/api/messages")]
32 public async Task<IResult> PostAsync()
33 {
34 // Enable buffering so that the request can be read by the adapter and the plugin
35 HttpContext.Request.EnableBuffering();
36
37 // Delegate the processing of the HTTP POST to the adapter.
38 // The adapter will invoke the bot.
39 await _adapter.ProcessAsync(HttpContext.Request, HttpContext.Response, _bot);
40
41 if (Response.HasStarted)
42 {
43 return Results.Empty;
44 }
45
46 // Fallback logic use the plugin to process the activity
47 return await _plugin.Do(HttpContext, _lifetime.ApplicationStopping);
48 }
49 }
50}