1

我有一个通过直线调用机器人的代码。直线间歇性地停止给出响应或开始给出与输出相同的输入问题。我只得到一个消息数组,它只包含相同的输入请求消息,没有来自机器人的响应。我附上了我在调试过程中得到的机器人响应。有人对此有任何线索吗?

调试期间的机器人响应

    using DirectLineConsole;
using DirectLineConsole.Models;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace DirectLineConsole
{
    class RequestOrchestrator
    {
        Conversation objconversation = new Conversation();

        public static string secret_key = "BotConnector abc";

        public static string Service_URL = "https://directline.botframework.com/api/conversations/";

        static void Main(string[] args)
        {

            RequestOrchestrator objprogram = new RequestOrchestrator();

            var task = objprogram.PostMessage("how can i change my phone number?").GetAwaiter().GetResult();

                Console.WriteLine("The get static message is " + objprogram.PostMessage("Its 93091").GetAwaiter().GetResult());
            Console.ReadKey();
            Console.ReadLine();


        }


        private async Task<bool> PostMessage(string message)
        {

            bool IsReplyReceived = false;

            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri("https://directline.botframework.com/api/conversations/");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

             client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("BotConnector", "abc");
            HttpResponseMessage response = await client.GetAsync("/api/tokens/");
            if (response.IsSuccessStatusCode)
            {
                var conversation = new Conversation();
                response = await client.PostAsJsonAsync("/api/conversations/", conversation);
                if (response.IsSuccessStatusCode)
                {
                    CathyDirectConversation ConversationInfo = response.Content.ReadAsAsync(typeof(CathyDirectConversation)).Result as CathyDirectConversation;
                        string conversationUrl = ConversationInfo.conversationID + "/messages/";

                    MessageNew msg = new MessageNew() { text = message };
                    response = await client.PostAsJsonAsync(conversationUrl, msg);
                    if (response.IsSuccessStatusCode)
                    {
                        response = await client.GetAsync(conversationUrl);
                        if (response.IsSuccessStatusCode)
                        {
                            MessageSetNew BotMessage = response.Content.ReadAsAsync(typeof(MessageSetNew)).Result as MessageSetNew;
                            foreach (Message responseMessage in BotMessage.messages)
                            {

                                Console.WriteLine("The response text " + responseMessage.text);


                            }
                            IsReplyReceived = true;
                        }
                    }
                }

            }
            return IsReplyReceived;

        }
4

0 回答 0