0

ここに画像の説明を入力

DirectLine API を使用してボットにメッセージを送信しています。ここの手順で説明されているように、負荷テストのポスト リクエストを実行するには、公開されたボットのサービス URL が必要です。https://blog.botframework.com/2017/06/19/Load-Testing-A-Bot/

これはコードです。誰でも私が間違っているところを指摘できますか

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

1 に答える 1