2017-02-28 45 views
0

以下是從我的Bot應用程序與LUIS-AI進行通信的源代碼。當我嘗試溝通時,我總是得到拒絕訪問的迴應。我不知道我在這裏錯過了什麼。BOT框架 - 無法連接Luis-AI對話框

[LuisModel("8c9285fb-198a-4f49-8fe4-b08ac5541ac2", "5c47c63887e346c2aee24d1755e07d29")] 
    [Serializable] 
    public class LUISDialog:LuisDialog<RoomReservation> 
    { 
     private readonly BuildFormDelegate<RoomReservation> Reservation; 

     public LUISDialog(BuildFormDelegate<RoomReservation> reservceRoom) 
     { 
      this.Reservation = reservceRoom; 
     } 
     [LuisIntent("")] 
     [LuisIntent("None")] 
     public async Task None(IDialogContext dialogContext, LuisResult luisResult) 
     { 
      await dialogContext.PostAsync("I am sorry I don't know what you mean "); 
      dialogContext.Wait(MessageReceived); 
     } 

     [LuisIntent("Greeting")] 
     public async Task Greeting(IDialogContext dialogContext, LuisResult luisResult) 
     { 
     dialogContext.Call(new GreetingDialog(), CallBack); 
     } 

     private async Task CallBack(IDialogContext context, IAwaitable<object> result) 
     { 
      context.Wait(MessageReceived); 
     } 

     [LuisIntent("Reservation")] 
     public async Task RoomReservation(IDialogContext dialogContext, LuisResult luisResult) 
     { 
      FormDialog<RoomReservation> enrollmentForm =new FormDialog<RoomReservation>(new RoomReservation(),this.Reservation, FormOptions.PromptInStart); 
      dialogContext.Call(enrollmentForm, CallBack); 
     } 

     [LuisIntent("QueryAmenities")] 
     public async Task QueryAmenities(IDialogContext dialogContext, LuisResult luisResult) 
     { 
      foreach (var entity in luisResult.Entities.Where(entity=>entity.Type=="Amenity")) 
      { 
       var value = entity.Entity.ToLower(); 
       if (value == "pool" || value == "gym" || value == "wifi" || value == "towels") 
       { 
        await dialogContext.PostAsync("Yes we have that"); 
        dialogContext.Wait(MessageReceived); 
        return; 
       } 
       await dialogContext.PostAsync("I'am sorry we don't have that"); 
       dialogContext.Wait(MessageReceived); 
       return; 
      } 
      await dialogContext.PostAsync("I'am sorry we don't have that"); 
      dialogContext.Wait(MessageReceived); 
     } 
    } 

錯誤的屏幕快照我越來越 enter image description here

控制器代碼

[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) 
      { 
       //ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); 
       //// calculate something for us to return 
       //int length = (activity.Text ?? string.Empty).Length; 

       //// return our reply to the user 
       //Activity reply = activity.CreateReply($"You sent {activity.Text} which was {length} characters"); 
       //await connector.Conversations.ReplyToActivityAsync(reply); 
       // await Conversation.SendAsync(activity,() => HotelBotDialog.dialog); 
       await Conversation.SendAsync(activity, MakeLuisDialog); 
      } 
      else 
      { 
       await HandleSystemMessage(activity); 
      } 
      var response = Request.CreateResponse(HttpStatusCode.OK); 
      return response; 
     } 

LUIS意向

enter image description here

請幫我解決這個

回答

1
+0

如果直接調用它的工作,那麼我建議調用LUIS的方法,而不是在頂部添加[LuisIntent(「***」)]。如果你想在將來實現更多的認知API,這更容易。 –

+0

另外,我總是像這樣調用對話框:await Conversation.SendAsync(activity,()=> new MakeLuisDialog());而不是等待Conversation.SendAsync(activity,MakeLuisDialog); –

+0

我不知道我的情況是什麼從機器人應用程序出錯。有什麼辦法可以解決LUIS問題嗎? – JEMI