[英]How to get the Service URL of a deployed bot application in Microsoft Bot framework?
I am using DirectLine API to send message to the bot, I need the service URL of the Published Bot to perform a post request for the load test as mentioned in the steps here https://blog.botframework.com/2017/06/19/Load-Testing-A-Bot/
我正在使用DirectLine API将消息发送到机器人,我需要发布机器人的服务URL来执行负载测试的发布请求,如此处步骤中所述
https://blog.botframework.com/2017/06/19/Load-Testing-A-Bot/
This is the code, can anyone point where I am going wrong 这是代码,任何人都可以指出我要去哪里了
private static async Task<Chat> TalkToTheBot(string Message)
{
Chat objChat = null;
// Connect to the DirectLine service
try
{
DirectLineClient client = new DirectLineClient(directLineSecret);
Conversation conversation = await client.Conversations.StartConversationAsync();
string watermark = null;
Activity reply = new Activity
{
From = new ChannelAccount("User1", "User Name"),
Text = "Hello",
Type = ActivityTypes.Message,
};
//await client.Conversations.PostActivityAsync(conversation.ConversationId, reply.CreateReply(text: Message, locale: "en-US"), CancellationToken.None);
await client.Conversations.PostActivityAsync(conversation.ConversationId,reply , CancellationToken.None);
// Get the response as a Chat object
objChat = await ReadBotMessagesAsync(client, conversation.ConversationId, watermark);
}
catch (Exception e)
{
throw;
}
// Return the response as a Chat object
return objChat;
}
private static async Task<Chat> ReadBotMessagesAsync(DirectLineClient client, string conversationId, string watermark)
{
// Create an Instance of the Chat object
Chat objChat = new Chat();
// We want to keep waiting until a message is received
bool messageReceived = false;
while (!messageReceived)
{
// Get any messages related to the conversation since the last watermark
ActivitySet messages = await client.Conversations.GetActivitiesAsync(conversationId, watermark, CancellationToken.None);
// Set the watermark to the message received
watermark = messages?.Watermark;
// Get all the messages
var messagesFromBotText = from message in messages.Activities
where message.From.Id == botId
select message;
// Loop through each message
foreach (var message in messagesFromBotText)
{
// We have Text
if (message.Text != null)
{
// Set the text response
// to the message text
objChat.ChatResponse
+= " "
+ message.Text.Replace("\n\n", "<br />");
}
}
// Mark messageReceived so we can break
// out of the loop
messageReceived = true;
}
// Set watermark on the Chat object that will be
// returned
objChat.watermark = watermark;
// Return a response as a Chat object
return objChat;
}
The serviceUrl property here is critical to note, and needs to be set to the endpoint of your message sink/client.
此处的serviceUrl属性非常重要,需要将其设置为邮件接收器/客户端的端点。
and: 和:
In order to test your bot, you'll need to create a custom UI/message sink to send and receive messages to your bot.
为了测试您的机器人,您需要创建一个自定义UI /消息接收器,以向机器人发送和接收消息。 This message sink will effectively act like a channel and accept HTTP POST messages with JSON-serialized bot framework activities.
该消息接收器将有效地充当通道,并通过JSON序列化的bot框架活动接受HTTP POST消息。
Which basically means that you will have to build a "message client" and the url of that client is the one that you will have to provide in the serviceUrl of your request. 基本上,这意味着您将必须构建“消息客户端”,并且该客户端的url是您必须在请求的serviceUrl中提供的URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.