1

我正在尝试为我的机器人/网页设置反向通道,以便我可以在两者之间发送事件。我已经添加了这个问题中显示的示例Bot framework get the ServiceUrl of embedded chat control page

public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
    if (activity.Type == ActivityTypes.Event &&
        string.Equals(activity.Name, "buttonClicked", StringComparison.InvariantCultureIgnoreCase))
    {
        ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));

        // return our reply to the user
        Activity reply = activity.CreateReply("I see that you just pushed that button");
        await connector.Conversations.ReplyToActivityAsync(reply);
    }

    if (activity.Type == ActivityTypes.Message)
    {
        ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));

        // return our reply to the user
        var reply = activity.CreateReply();
        reply.Type = ActivityTypes.Event;
        reply.Name = "changeBackground";
        reply.Value = activity.Text;
        await connector.Conversations.ReplyToActivityAsync(reply);
    }
    else
    {
        HandleSystemMessage(activity);
    }
    var response = Request.CreateResponse(HttpStatusCode.OK);
    return response;
}

但是 ActivityTypes.Event 和 activity.Name 一样不存在。我需要一个特殊的包来处理机器人框架的反向通道吗?

4

1 回答 1

3

根据您的评论,您似乎使用的是旧版本的 BotBuilder nuget 包;这就是为什么你没有这些属性/值。

请更新到最新版本的BotBuilder v3.5.5,这样就可以了。

于 2017-04-18T19:18:33.813 回答