简体   繁体   中英

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/

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;
        }

Per the article ,

The serviceUrl property here is critical to note, and needs to be set to the endpoint of your message sink/client.

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. This message sink will effectively act like a channel and accept HTTP POST messages with JSON-serialized bot framework activities.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM