【问题标题】:Bot Framework - Bot initiates the conversation on SkypeBot Framework - Bot 在 Skype 上发起对话
【发布时间】:2017-07-12 21:46:30
【问题描述】:

我希望我的机器人在用户开始新对话时显示介绍性消息。我在 Skype 中看到了这种与机器人一起工作的情况,其中机器人在用户输入任何内容之前发送消息。

我已经使用 Bot Framework Channel Emulator 和 MessagesController 类中的此代码来完成这项工作:

    public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
    {
        if (activity.Type == ActivityTypes.Message)
        {
            await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
        }
        else
        {
            await this.HandleSystemMessage(activity);
        }
        var response = Request.CreateResponse(HttpStatusCode.OK);
        return response;
    }

    private async Task HandleSystemMessage(Activity message)
    {
        if (message.Type == ActivityTypes.ConversationUpdate)
        {
            var reply = message.CreateReply("Hello World!");

            var connector = new ConnectorClient(new Uri(message.ServiceUrl));

            await connector.Conversations.SendToConversationAsync(reply);
        }
    }

这将显示“Hello World!”在新对话开始时。无需输入。但是,在 Skype 上,不会出现此介绍性消息。我在这里误解了什么?我知道这是可能的。

【问题讨论】:

标签: c# botframework


【解决方案1】:

鉴于这种情况,Skype 会抛出不同的 ActivityType:

  • 在您的联系人中添加机器人后,您将获得一个contactRelationUpdate。然后我们你开始和机器人对话,没有特殊的Activity

  • 当您启动包含机器人的对话组时,您将收到conversationUpdate

因此,如果您想欢迎您的用户,您应该在测试中添加 contactRelationUpdate 活动类型,例如:

private async Task HandleSystemMessage(Activity message)
{
    if (message.Type == ActivityTypes.ConversationUpdate || message.Type == ActivityTypes.ContactRelationUpdate)
    {
        var reply = message.CreateReply("Hello World!");

        var connector = new ConnectorClient(new Uri(message.ServiceUrl));

        await connector.Conversations.SendToConversationAsync(reply);
    }
}

添加机器人时收到的消息内容摘录:

这里From 是我的用户,Recipient 是机器人。可以看到Action的值为add

【讨论】:

    猜你喜欢
    • 2019-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多