将此消息发送到您的bot时出错:HTTP状态代码InternalServerError

时间:2017-06-15 07:57:52

标签: c# azure botframework luis

我的机器人突然停止了wirking ......

我使用botframework创建了一个机器人,luis.ai c#。我已经在azure中部署了。

机器人工作得非常好,但是现在当我向我的机器人发送消息时我得到了这个代码:将此消息发送到您的机器人时出错:HTTP状态代码InternalServerError。

我尝试在我的luis.ai中生成另一个密钥,并在我的代码中添加...但我仍然遇到同样的问题。

P.S我的botframework用最新版本更新。

MessagesController.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)
        {

        }
        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;
      }
     }
    }

AllTheBot.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("xxxxxxxx", 
                        "yyyyyyy")]

public class AllTheBot : LuisDialog<object>
{
    // internal static string results;
    [LuisIntent("None")]
    [LuisIntent("")]
    public async Task None(IDialogContext context, LuisResult result)
    {
        string message = $"Sorry, I did not understand '{result.Query}'. Please reformulate your question";

        await context.PostAsync(message);

        context.Wait(this.MessageReceived);

}


    // private const string HeroCard = "Hero card";




    [LuisIntent("grettings")]
    [LuisIntent("intentfr")]
    public async Task Greeting(IDialogContext context, 
    IAwaitable<IMessageActivity> activity, LuisResult result)
    {


            await context.PostAsync("Welcome  ");

            context.Wait(MessageReceived);

    }`
       }}

2 个答案:

答案 0 :(得分:0)

您在此处发布的代码是否与您的代码完全匹配,如果是这样,您可能需要查看格式错误。

我认为主要问题是你的宣言

[LuisIntent("grettings")]
[LuisIntent("intentfr")]
public async Task Greeting(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
    await context.PostAsync("Welcome");

    context.Wait(MessageReceived);
}

根据我的经验,当我不仅仅是

时,我会遇到错误

IDialogContextLuisResult作为LUIS任务的参数。尝试从参数中删除IAwaitable<IMessageActivity> activity

[LuisIntent("grettings")]
[LuisIntent("intentfr")]
public async Task Greeting(IDialogContext context, LuisResult result)
{
    await context.PostAsync("Welcome");

    context.Wait(MessageReceived);
}

答案 1 :(得分:0)

我有同样的问题。我最终重新创建机器人并重新启动我的机器。像魅力一样工作