c# - 将此消息发送到您的机器人时出错 : HTTP status code InternalServerError

标签 c# azure botframework azure-language-understanding

我的机器人突然停止运行......

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

该机器人工作得很好,但现在当我向我的机器人发送消息时,我收到此代码:向您的机器人发送此消息时出错:HTTP 状态代码 InternalServerError 。

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

P.S 我的机器人框架已更新为最新版本。

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

    }`
       }}

最佳答案

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

我认为主要问题是你的声明

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

关于c# - 将此消息发送到您的机器人时出错 : HTTP status code InternalServerError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44561850/

相关文章:

c# - 在 C# 中处理群发邮件的最佳方式

javascript - 无法从 javascript 连接到 ASP.NET Core websocket

azure - 需要多少个 Hive 动态分区?

azure - Teams 中的 Microsoft Bot Framework 是否可以免费使用我自己的端点?

Azure 测试网络聊天无法正常工作

c# - 限制来自 Actor 的异步调用

c# - 在 EntityFramework 中更新或删除多个实体的推荐做法是什么?

azure - 使用地形。 azurerm_autoscale_setting 或 azurerm_monitor_autoscale_setting 是否具有内存指标

azure - 值不能为空。参数名称: provider when using a ServiceBus Trigger in Azure

botframework - Luis 可以用于在 MSFT Bot Framework 以外的平台上设计的机器人吗