Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine Adapter and Bot into one class #145

Merged
merged 12 commits into from
Feb 21, 2018
Merged

Combine Adapter and Bot into one class #145

merged 12 commits into from
Feb 21, 2018

Conversation

tomlm
Copy link
Contributor

@tomlm tomlm commented Feb 16, 2018

BotBase

  • BotFrameworkBot
  • ConsoleBot
  • TestBot
  • etc.

Copy link
Contributor

@cleemullins cleemullins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the changes. The elimination of the Adapters via good-old-fashioned inheritance is nice.

This is going to be very difficult to merge, however. There have been changes (since this was written) to the TestAdapter, the Bot, MiddlewareSet, and other relevant classes.

@@ -16,7 +16,6 @@
<ItemGroup>
<ProjectReference Include="..\..\libraries\Microsoft.Bot.Builder.BotFramework\Microsoft.Bot.Builder.BotFramework.csproj" />
<ProjectReference Include="..\..\libraries\Microsoft.Bot.Builder\Microsoft.Bot.Builder.csproj" />
<ProjectReference Include="..\..\libraries\Microsoft.Bot.Connector.AspNetCore\Microsoft.Bot.Connector.AspNetCore.csproj" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see this going away.

Copy link
Contributor

@cleemullins cleemullins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

}

// Call any registered Middleware Components looking for SendActivity()
if (context.Responses != null && context.Responses.Any())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refer to #144

Given the current factoring (of state in middleware) this would still be an issue because of this line

return this;
}

public async Task ProcessActivty(string authHeader, Activity activity, Func<IBotContext,Task> callback)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do introduce a BotController class we could more the auth into that. That way the responsibility of this layer is to tie the inbound and outbound worlds together and so host the pipeline.
(This is not something we need to change for this checkin.)


namespace Microsoft.Bot.Builder
{
public abstract class BotServer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't the class name be "AdapterBase"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would also help have a nicer name for the current "BotFrameworkBotserver".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, BotFrameworkBotServer sucks pretty bad


namespace Microsoft.Bot.Builder.BotFramework
{
public class BotFrameworkBotServer : BotServer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given how central this class is going to be, I'd love to put more consideration in the name. BotFrameworkBotServer sounds really awkward. Could we think of something more concise and sticky?

if (adapter == null)
throw new ArgumentNullException(nameof(adapter));
}
//public static void AdapterNotNull(ActivityAdapterBase adapter)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented lines?

@@ -12,7 +12,7 @@ namespace Microsoft.Bot.Builder
{
public interface IBotContext
{
Bot Bot { get; }
BotServer Bot { get; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would developers get any benefit for providing their own implementation of a BotServer? If yes, maybe we could have the IBotContext depend on a IBotServer abstraction instead of a BotServer concrete (abstract) class.

@@ -38,13 +40,13 @@ public static class JwtTokenValidation
}

// Go through the standard authentication path.
await JwtTokenValidation.ValidateAuthHeader(authHeader, credentials, activity.ServiceUrl, httpClient);
await JwtTokenValidation.ValidateAuthHeader(authHeader, credentials, activity.ServiceUrl, httpClient ?? _httpClient);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.ConfigureAwait(false)?

@@ -22,27 +22,23 @@ namespace AlarmBot.Controllers
[Route("api/[controller]")]
public class MessagesController : Controller
{
public static BotFrameworkAdapter activityAdapter = null;
public static Bot bot = null;
public static BotFrameworkBotServer botServer = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need a public static member? For a different check in, might be worth revisiting the need for this pattern

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who accesses this static member from outside of the controller?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want it to be a singleton, the controller is created on every request.

Tom Laird-McConnell added 3 commits February 17, 2018 16:17
@@ -311,6 +311,9 @@ public TestFlow AssertReply(Action<IActivity> validateActivity, string descripti
// NOTE: See details code in above method.
task.Wait();

if (System.Diagnostics.Debugger.IsAttached)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice :)

@@ -15,13 +15,14 @@ public class QnAMaker
public const string APIManagementHeader = "Ocp-Apim-Subscription-Key";
public const string JsonMimeType = "application/json";

private static HttpClient g_httpClient = new HttpClient();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not create an instance level HttpClient when not specified rather than a global static one that is to be shared across instances of your QnAMaker claass?

@@ -49,7 +49,7 @@ public new BotFrameworkAdapter Use(Middleware.IMiddleware middleware)

protected async override Task SendActivityImplementation(IBotContext context, IActivity activity)
{
if (activity.Type == "delay")
if (activity.Type == ActivityTypesEx.Delay)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why "Ex"? ActivityTypes would be nicer probably

@tomlm tomlm merged commit 003de3f into master Feb 21, 2018
@tomlm tomlm deleted the tomlm/BotHost branch February 21, 2018 23:43
ceciliaavila added a commit that referenced this pull request Jun 25, 2019
[Botkit] Update README for SlackAdapter sample
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants