BOT框架 - 无法连接Luis-AI Dialog

时间:2017-02-28 22:22:52

标签: c# botframework luis

以下是从我的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

请帮我解决此问题

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

可能您使用的是端点密钥而不是Programmatic Key API。检查一下: enter image description here