Bot Framework-多个延迟答案 [英] Bot Framework - Multiple delayed answers

查看:72
本文介绍了Bot Framework-多个延迟答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Microsft BotFramework。

I'm using the Microsft BotFramework.

过程:
客户要求我的机器人生成特定代码
1.该机器人回答客户他正在生成代码。
2.大约10秒钟后,机器人将代码发送给客户端,而没有任何其他请求。

Process: the clients ask my bot to generate a specific code 1. The bot answer to the client that he is generating the code. 2. After about 10 seconds, the bot send the code to the client, without any other request.

问题:我正在使用的

Problem: I'm using the

ReplyToActivityAsync(...)

方法在返回语句之前发送两个答案。
在这种情况下,两个答案之间有一个发布超时错误。

method to send both answers, before the return statement. In that case there is a post timeout error between the 2 answers.

这是我的代码:

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

            // return our reply to the user
            string welcomeMessage = "[...] Reply 1 [...]"
            await connector.Conversations.ReplyToActivityAsync(activity.CreateReply(welcomeMessage));

            // MyApi.GetCode() takes about 10 secs
            await connector.Conversations.ReplyToActivityAsync(activity.CreateReply(MyAPI.GetCode()));
        }

如何在不等待用户请求的情况下开始回复?
谢谢!

How to start a reply without waiting for a user request ? Thanks !

推荐答案

您可以使用收件人的ID发送消息,而无需用户的请求,如下所示。因此,您也可以在另一个函数中,通过api调用获得成功的响应后并延迟地向用户发送消息。

You can send a message using recipient's id without user's request like the following. Therefore, you can send a message to user after getting successful response from your api calling and with delay, also in another function.

string userId ="123456789"; // For Example
string serviceUrl = "https://telegram.botframework.com"; // For Example

var connector = new ConnectorClient(new Uri(serviceUrl));
IMessageActivity newMessage = Activity.CreateMessageActivity();
newMessage.Type = ActivityTypes.Message;
newMessage.From = new ChannelAccount("<BotId>", "<BotName>");
newMessage.Conversation = new ConversationAccount(false, userId);
newMessage.Recipient = new ChannelAccount(userId);
newMessage.Text = "<MessageText>";
await connector.Conversations.SendToConversationAsync((Activity)newMessage);

在上面,您可以在相关频道中使用其ID向用户发送消息。另外, serviceUrl 是根据相关的渠道定义的(这里以Telegram为例)。

In the above, you can send a message to a user using his Id in the related channel. Also, serviceUrl is defined based on the related channel (here, Telegram is as an example).

这篇关于Bot Framework-多个延迟答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆