Created
July 1, 2025 16:26
-
-
Save rajan-chari/6992613c22dacda359c89125433cb58c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [HttpPost("/api/messages")] | |
| public async Task<IResult> OnMessage() | |
| { | |
| // [PA POC] Handle reactive scenario w/ BotBuilder adapter. | |
| // [PA POC] For phased migration, BotBuilder adapter still used. | |
| HttpContext.Request.EnableBuffering(); | |
| var body = await new StreamReader(Request.Body).ReadToEndAsync(); | |
| Activity? activity = JsonSerializer.Deserialize<Activity>(body); | |
| HttpContext.Request.Body.Position = 0; | |
| if (activity == null) | |
| { | |
| return Results.BadRequest("Missing activity"); | |
| } | |
| // Delegate the processing of the HTTP POST to the adapter. | |
| // The adapter will invoke the bot. | |
| await _adapter.ProcessAsync(HttpContext.Request, HttpContext.Response, _bot); | |
| if (Response.HasStarted) | |
| { | |
| return Results.Empty; | |
| } | |
| // Fallback logic | |
| var authHeader = HttpContext.Request.Headers.Authorization.FirstOrDefault() ?? throw new UnauthorizedAccessException(); | |
| var token = new JsonWebToken(authHeader.Replace("Bearer ", "")); | |
| var context = HttpContext.RequestServices.GetRequiredService<TeamsContext>(); | |
| context.Token = token; | |
| var res = await _plugin.Do(token, activity, _lifetime.ApplicationStopping); | |
| return Results.Json(res.Body, statusCode: (int)res.Status); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment