本文介绍了Bot Framework v3.0上带有Slack连接器的ReplyToActivityAsync引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个bot v3.0项目并将其连接到Slack和Skype. Skype连接器效果很好,但是我在使用Slack连接器时遇到了麻烦.

I have created a bot v3.0 project and connected it to both Slack and Skype. The Skype connector works great, but I am having trouble with the Slack connector.

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

Here is my Post handler from the default project.

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发送一条消息时,它被传递到后处理程序,并且活动对象看起来还不错.我可以看到松弛的数据,包括邮件,收件人等.然后调用:

When I send a message from Slack, it is delivered to the post handler and the activity object looks fine. I can see the slack data including the message, recipient, etc. Then the call to:

await connector.Conversations.ReplyToActivityAsync(reply);

抛出一条异常,消息为无法反序列化响应",并抛出内部异常,错误为解析值时出现意外字符:< ;.路径",第0行,位置0."

throws an exception with the message "Unable to deserialize the response" and an inner exception with the error "Unexpected character encountered while parsing value: <. Path '', line 0, position 0."

其他几点.

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

对于Slack频道,我需要做些不同的事情吗?

Is there something that I need to do differently for the Slack channel?

谢谢!

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

UPDATE:This issue occurred in Microsoft.Bot.Builder v3.0.0 and it is fixed in Microsoft.Bot.Builder v3.0.1. I am now able to communicate with my bot properly from both Slack and Skype.

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

谢谢stevenic!

Thanks stevenic!

推荐答案

其他人也会遇到这种情况.这是相关的问题: https://github.com/Microsoft/BotBuilder/issues/618

Others also experience this. Here's the relevant issue: https://github.com/Microsoft/BotBuilder/issues/618

这篇关于Bot Framework v3.0上带有Slack连接器的ReplyToActivityAsync引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 21:10