diff --git a/CSharp/Samples/Microsoft.Bot.Sample.AspNetCore.AnnotatedSandwichBot/AnnotatedSandwich.cs b/CSharp/Samples/Microsoft.Bot.Sample.AspNetCore.AnnotatedSandwichBot/AnnotatedSandwich.cs index a8a594e64..8e7ab6384 100644 --- a/CSharp/Samples/Microsoft.Bot.Sample.AspNetCore.AnnotatedSandwichBot/AnnotatedSandwich.cs +++ b/CSharp/Samples/Microsoft.Bot.Sample.AspNetCore.AnnotatedSandwichBot/AnnotatedSandwich.cs @@ -300,7 +300,8 @@ public static IForm BuildLocalizedForm() .Field(nameof(Toppings), validate: async (state, value) => { - var values = ((List)value).OfType(); + // CXuesong: Fix for Microsoft/BotBuilder#2780 + var values = ((List)value)?.OfType(); var result = new ValidateResult { IsValid = true, Value = values }; if (values != null && values.Contains(ToppingOptions.Everything)) { diff --git a/CSharp/Samples/Microsoft.Bot.Sample.AspNetCore.EchoBot/Controllers/MessagesController.cs b/CSharp/Samples/Microsoft.Bot.Sample.AspNetCore.EchoBot/Controllers/MessagesController.cs index 2aaf63208..90d46f8bb 100644 --- a/CSharp/Samples/Microsoft.Bot.Sample.AspNetCore.EchoBot/Controllers/MessagesController.cs +++ b/CSharp/Samples/Microsoft.Bot.Sample.AspNetCore.EchoBot/Controllers/MessagesController.cs @@ -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; @@ -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 @@ -22,6 +24,22 @@ public class MessagesController : Controller private readonly Conversation conversation; private readonly ILogger 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)); diff --git a/CSharp/Samples/Microsoft.Bot.Sample.AspNetCore.EchoBot/Startup.cs b/CSharp/Samples/Microsoft.Bot.Sample.AspNetCore.EchoBot/Startup.cs index bd197654e..a0c3a3afa 100644 --- a/CSharp/Samples/Microsoft.Bot.Sample.AspNetCore.EchoBot/Startup.cs +++ b/CSharp/Samples/Microsoft.Bot.Sample.AspNetCore.EchoBot/Startup.cs @@ -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 { @@ -34,7 +35,12 @@ public void ConfigureServices(IServiceCollection services) // Authentication for Microsoft Bot Framework. services.AddSingleton(_ => new MicrosoftAppCredentials(Configuration, _.GetService().CreateLogger())); - services.AddSingleton(); + services.AddSingleton(_ => + { + var c = new Conversation(_.GetService()); + MessagesController.ConfigureConversation(c); + return c; + }); // Add framework services. services.AddMvc(options =>