ReplyToActivityAsync 在 Bot Framework v3.0 上使用 Slack 连接器抛出异常

ReplyToActivityAsync throwing exception with Slack connector on Bot Framework v3.0

我创建了一个 bot v3.0 项目并将其连接到 Slack 和 Skype。 Skype 连接器运行良好,但我在使用 Slack 连接器时遇到问题。

这是默认项目中我的 Post 处理程序。

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);
    }
    else
    {
        HandleSystemMessage(activity);
    }

    var response = Request.CreateResponse(HttpStatusCode.OK);
    return response;
}

当我从 Slack 发送消息时,它被传送到 post 处理程序并且 activity 对象看起来很好。我可以看到松弛数据,包括消息、收件人等。然后调用:

await connector.Conversations.ReplyToActivityAsync(reply);

抛出消息 "Unable to deserialize the response" 的异常和错误 "Unexpected character encountered while parsing value: <. Path '', line 0, position 0."

的内部异常

补充几点。

  1. 同样的代码也适用于 Skype。
  2. 我成功地使用了 Bot Framework v1 项目中的这个 slack 机器人。

我需要为 Slack 频道做些不同的事情吗?

谢谢!

更新: 此问题发生在 Microsoft.Bot.Builder v3.0.0 中,已在 Microsoft.Bot.Builder v3.0.1 中修复。我现在可以通过 Slack 和 Skype 与我的机器人正常通信。

https://github.com/Microsoft/BotBuilder/releases/tag/botbuilder%403.0.1

谢谢斯蒂芬尼克!

其他人也有这样的经历。这是相关问题:https://github.com/Microsoft/BotBuilder/issues/618

此问题出现在 Microsoft.Bot.Builder v3.0.0 中,已在 Microsoft.Bot.Builder v3.0.1 中修复。我现在可以通过 Slack 和 Skype 与我的机器人正常通信。

https://github.com/Microsoft/BotBuilder/releases/tag/botbuilder%403.0.1

谢谢斯蒂芬尼克!