Skip to content

Commit

Permalink
Upgrade existing samples. Make them work.
Browse files Browse the repository at this point in the history
  • Loading branch information
CXuesong committed May 17, 2017
1 parent cfcd3ea commit 634e3ae
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ public static IForm<SandwichOrder> BuildLocalizedForm()
.Field(nameof(Toppings),
validate: async (state, value) =>
{
var values = ((List<object>)value).OfType<ToppingOptions>();
// CXuesong: Fix for Microsoft/BotBuilder#2780
var values = ((List<object>)value)?.OfType<ToppingOptions>();
var result = new ValidateResult { IsValid = true, Value = values };
if (values != null && values.Contains(ToppingOptions.Everything))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using Microsoft.AspNetCore.Authorization;
Expand All @@ -12,6 +13,7 @@
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Dialogs.Internals;
using Autofac;
using Microsoft.Bot.Builder.Scorables;
using Microsoft.Extensions.Logging;

namespace Microsoft.Bot.Sample.AspNetCore.Echo.Controllers
Expand All @@ -22,6 +24,22 @@ public class MessagesController : Controller
private readonly Conversation conversation;
private readonly ILogger<MessagesController> logger;

public static void ConfigureConversation(Conversation conversation)
{
conversation.UpdateContainer(builder =>
{
var scorable = Actions
.Bind(async (IBotToUser botToUser, IMessageActivity message) =>
{
await botToUser.PostAsync("polo");
})
.When(new Regex("marco"))
.Normalize();

builder.RegisterInstance(scorable).AsImplementedInterfaces().SingleInstance();
});
}

public MessagesController(Conversation conversation, ILoggerFactory loggerFactory)
{
if (conversation == null) throw new ArgumentNullException(nameof(conversation));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Bot.Connector;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Sample.AspNetCore.Echo.Controllers;

namespace Microsoft.Bot.Sample.AspNetCore.Echo
{
Expand All @@ -34,7 +35,12 @@ public void ConfigureServices(IServiceCollection services)
// Authentication for Microsoft Bot Framework.
services.AddSingleton(_ => new MicrosoftAppCredentials(Configuration,
_.GetService<ILoggerFactory>().CreateLogger<MicrosoftAppCredentials>()));
services.AddSingleton<Conversation>();
services.AddSingleton(_ =>
{
var c = new Conversation(_.GetService<MicrosoftAppCredentials>());
MessagesController.ConfigureConversation(c);
return c;
});

// Add framework services.
services.AddMvc(options =>
Expand Down

0 comments on commit 634e3ae

Please sign in to comment.