我成功地得到了一个简单的"天气和#34;机器人使用Luis在Skype和Twilio上运行并且非常出色。
我现在的任务是设置我只能将其描述为"会话"机器人。
我已经查看了尽可能多的示例,我可以在interweb上找到但我不确定如何开发它,我不知道我是否应该在我的场景中使用FormBuilder。
以下是我要做的部分内容的流程图...
我的表格已经完成了它分支的部分" Bill Available" ...
我无法弄清楚如何改变方向"基于答案。
答案 0 :(得分:1)
据我所知,这一点比我想象的要容易得多......
这是我的解决方案......
这是我的控制者:
/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
// check if activity is of type message
if (activity != null && activity.GetActivityType() == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new Dialogs.BillSharkDialog());
}
else
{
HandleSystemMessage(activity);
}
return new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
}
这是“对话”,只需两步......
[Serializable]
public class BillSharkDialog : IDialog<object>
{
Model.Customer customer = new Model.Customer();
public async Task StartAsync(IDialogContext context)
{
context.Wait(WelcomeMessageAsync);
}
public async Task WelcomeMessageAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
{
IMessageActivity message = await argument;
await context.PostAsync("We're excited to start helping you save! Let's start by getting your name?");
context.Wait(CaptureCustomerNameAsync);
}
public async Task CaptureCustomerNameAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
{
IMessageActivity message = await argument;
customer.customerName = message.Text;
await context.PostAsync($"Thanks {message.Text}. Now we need your email address?");
context.Wait(CaptureCustomerEmailAsync);
}
}
您可以通过检查收到的消息来明显改变路线..
以下是一个例子:
public async Task DoesCustomerHaveBillAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
{
IMessageActivity message = await argument;
switch (message.Text.ToLower())
{
case "yes":
await context.PostAsync($"Great. Go ahead and take a picture of the first couple of pages and attach them to this conversation.\n\n\nWhen you have finished, please send the message 'finished'.");
context.Wait(CustomerHasBillAsync);
break;
case "no":
await context.PostAsync($"That's OK. Do you happen to have the login information for your provider account?");
context.Wait(CustomerDoesntHaveBillAsync);
break;
default:
await context.PostAsync($"Sorry, I didn't undestand. Please reply with 'yes' or 'no'.");
context.Wait(DoesCustomerHaveBillAsync);
break;
}
}
答案 1 :(得分:0)
您可以考虑使用FormBuilder字段的SetNext方法根据另一个字段值来决定接下来会发生什么。
您可以查看ContosoFlowers示例。以Order形式;正在做类似的事情。
Severity Code Description Project File Line Suppression State
Error Unknown build error, 'Cannot resolve dependency to assembly 'log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=9fea11e3513f1a42' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.' VersionChecker C:\windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets 268