我正在使用luis.ai和botframework:
我的问题是,当我尝试发送消息时(这不是话语的一部分,所以未知的输入我不会收到消息:$"抱歉,我不理解' {result.Query}'。请再试一次"; ...但每次都会出现欢迎信息,来自问候意图。
我不知道为什么会发生这种情况。 请你帮助我好吗 ?
这是我的代码:MessagController.cs
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
namespace FirstBotApplication
{
//[BotAuthentication]
public class MessagesController : ApiController
{
/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new AllTheBot());
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
private Activity HandleSystemMessage(Activity message)
{
if (message.Type == ActivityTypes.DeleteUserData)
{
// Implement user deletion here
// If we handle user deletion, return a real message
}
else if (message.Type == ActivityTypes.ConversationUpdate)
{
// Handle conversation state changes, like members being added and removed
// Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
// Not available in all channels
}
else if (message.Type == ActivityTypes.ContactRelationUpdate)
{
// Handle add/remove from contact lists
// Activity.From + Activity.Action represent what happened
}
else if (message.Type == ActivityTypes.Typing)
{
// Handle knowing tha the user is typing
}
else if (message.Type == ActivityTypes.Ping)
{
}
return null;
}
}
}
luis.cs
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Luis;
using Microsoft.Bot.Builder.Luis.Models;
using Microsoft.Bot.Connector;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
namespace FirstBotApplication
{
// [LuisModel("Please Enter Your LUIS Model ID", "Please Enter Your LUIS
Subscription Key")]
[Serializable]
[LuisModel("xxxxxxx", "xxxxxxxxxxxx")]
public class AllTheBot : LuisDialog<object>
{
// internal static string results;
public async Task None(IDialogContext context, LuisResult result)
{
string message = $"Sorry, I did not understand '{result.Query}'. Please try again";
await context.PostAsync(message);
context.Wait(this.MessageReceived);
}
[LuisIntent("grettings")]
[LuisIntent("intentfr")]
public async Task Greeting(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
//await context.PostAsync
//("Yes, you can leave your baggage at the Left Baggage counters located in all terminals. This service is available 24 hours daily at:"
//+ Environment.NewLine + "\n\n Terminal 1" +Environment.NewLine + " - Departure Transit Lounge West, Level 2" + Environment.NewLine + " - Level 3, Public Area"
//+ Environment.NewLine + "\n\n Terminal 2" +Environment.NewLine + " - Departure Transit Lounge Central, Level 2" + Environment.NewLine + " - Arrival Hall North, Level 1, Public Area"
//+ Environment.NewLine + "\n\n Terminal 3" + Environment.NewLine + " - Departure Transit Lounge North, Level 2" + Environment.NewLine + " - Departure Transit Lounge North, Level 2"
await context.PostAsync("Welcome :) ");
context.Wait(MessageReceived);
// results = "BaggageStorage";
}
[LuisIntent("test")]
public async Task test(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
await context.PostAsync("Do you want to test our bot ? We suggest to type : hi or who are you, help etc..");
context.Wait(MessageReceived);
}
[LuisIntent("thankyou")]
public async Task thankyou(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
await context.PostAsync("I want to thank you for your time.");
context.Wait(MessageReceived);
}
[LuisIntent("exit")]
[LuisIntent("Utilities.Stop")]
public async Task exit(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
await context.PostAsync("Thank you for your time ! You are welcome again here :) ");
context.Wait(MessageReceived);
}
}
}
答案 0 :(得分:1)
你的None方法没有用&#34; None&#34;和空意图。更新您的方法,使其如下所示:
[LuisIntent("None")]
[LuisIntent("")]
public async Task None(IDialogContext context, LuisResult result)
{
string message = $"Sorry, I did not understand '{result.Query}'. Please try again";
await context.PostAsync(message);
context.Wait(this.MessageReceived);
}