using System; using System.Collections.Generic; using Aliyun.Acs.Core; using Aliyun.Acs.Core.Exceptions; using Aliyun.Acs.Core.Profile; using Aliyun.Acs.Chatbot.Model.V20171011; using Newtonsoft.Json; namespace ChatbotDemo { class Program { static void Main(string[] args) { while (true) { string txt = Console.ReadLine(); IClientProfile profile = DefaultProfile.GetProfile("cn-shanghai", "<accessKeyId>", "<accessSecret>"); DefaultAcsClient client = new DefaultAcsClient(profile); var request = new ChatRequest(); //request.SenderNick = "1"; //request.SenderId = "3"; //request.KnowledgeId = "2"; //request.SessionId = "1"; request.Utterance = txt; request.InstanceId = "chatbot-cn-mp913ow5x0004l"; try { var response = client.GetAcsResponse(request); ChatResponse entity = null; var msg = System.Text.Encoding.Default.GetString(response.HttpResponse.Content); if (!string.IsNullOrEmpty(msg)) { entity = JsonConvert.DeserializeObject<ChatResponse>(msg); } Console.WriteLine($"a:{txt} \\p {entity.Messages[0].Text}"); } catch (ServerException e) { Console.WriteLine(e); } catch (ClientException e) { Console.WriteLine(e); } } } } }