internal static async Task <CleverbotResponse> CreateAsync(string message, string conversationId, string apiKey) { HttpClient c = new HttpClient(); string conversationLine = (string.IsNullOrWhiteSpace(conversationId) ? "" : $"&cs={conversationId}"); byte[] bytesReceived = await c .GetByteArrayAsync( $"https://www.cleverbot.com/getreply?key={apiKey}&wrapper=cleverbot.net&input={message}{conversationLine}") .ConfigureAwait(false); if (bytesReceived == null) { return(null); } string result = Encoding.UTF8.GetString(bytesReceived, 0, bytesReceived.Length); CleverbotResponse response = JsonConvert.DeserializeObject <CleverbotResponse>(result); if (response == null) { return(null); } response.apiKey = apiKey; return(response); }
/// <summary> /// Send a message to cleverbot asynchronously and get a response. /// </summary> /// <param name="message">your message sent to cleverbot</param> /// <returns>response from the cleverbot.com api</returns> public Task <CleverbotResponse> GetResponseAsync(string message) { return(CleverbotResponse.CreateAsync(message, "", ApiKey)); }