Skip to content

Commit

Permalink
Modify controller to routing-based bot assignation
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorGrycuk committed May 24, 2019
1 parent b713026 commit 4affa1f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tests/Microsoft.Bot.Builder.TestBot/Controllers/BotController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
Expand All @@ -11,24 +12,28 @@ namespace Microsoft.BotBuilderSamples
// This ASP Controller is created to handle a request. Dependency Injection will provide the Adapter and IBot
// implementation at runtime. Multiple different IBot implementations running at different endpoints can be
// achieved by specifying a more specific type for the bot constructor argument.
[Route("api/messages")]
[Route("api")]
[ApiController]
public class BotController : ControllerBase
{
private readonly IBotFrameworkHttpAdapter _adapter;
private readonly IBot _bot;
private IBot _bot;
private readonly Func<string, IBot> _service;

public BotController(IBotFrameworkHttpAdapter adapter, IBot bot)
public BotController(IBotFrameworkHttpAdapter adapter, Func<string, IBot> service)
{
_adapter = adapter;
_bot = bot;
_service = service;
}

[Route("{*botname}")]
[HttpPost]
public async Task PostAsync()
public async Task PostAsync(string botname)
{
// Delegate the processing of the HTTP POST to the adapter.
// The adapter will invoke the bot.
_bot = _service(botname) ?? throw new Exception($"The endpoint '{botname}' is not associated with a bot.");

await _adapter.ProcessAsync(Request, Response, _bot);
}
}
Expand Down

0 comments on commit 4affa1f

Please sign in to comment.