Example #1
0
        internal static async Task <CleverbotResponse> CreateAsync(string message, string conversationId, string apiKey)

        {
            WebClient c = new WebClient();

            string conversationLine = (string.IsNullOrWhiteSpace(conversationId) ? "" : $"&cs={conversationId}");

            byte[] bytesRecieved = await c.DownloadDataTaskAsync($"https://www.cleverbot.com/getreply?key={ apiKey }&wrapper=cleverbot.net&input={ message }{ conversationLine }");

            if (bytesRecieved == null)
            {
                return(null);
            }
            string            result   = Encoding.UTF8.GetString(bytesRecieved);
            CleverbotResponse response = JsonConvert.DeserializeObject <CleverbotResponse>(result);

            if (response == null)
            {
                return(null);
            }
            response.apiKey = apiKey;
            response.CreateInteractionsList();

            return(response);
        }
        internal static async Task <CleverbotResponse> CreateAsync(string message, string conversationId, string apiKey, int?wacky = null, int?talkative = null, int?attentive = null)
        {
            HttpClient c = new HttpClient();

            string conversationLine = (string.IsNullOrWhiteSpace(conversationId) ? "" : $"&cs={conversationId}");

            string tweak_1 = wacky.HasValue ? $"&cb_settings_tweak1={wacky.Value}" : "";
            string tweak_2 = talkative.HasValue ? $"&cb_settings_tweak2={talkative.Value}" : "";
            string tweak_3 = attentive.HasValue ? $"&cb_settings_tweak3={attentive.Value}" : "";

            byte[] bytesReceived = await c.GetByteArrayAsync($"https://www.cleverbot.com/getreply?key={ apiKey }&wrapper=cleverbot.net&input={ message }{ conversationLine }{tweak_1}{tweak_2}{tweak_3}").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;
            response.CreateInteractionsList();

            return(response);
        }
Example #3
0
        /// <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 async Task <CleverbotResponse> GetResponseAsync(string message)
        {
            LastMessageSent = DateTime.Now;
            var resp = await CleverbotResponse.CreateAsync(message, _conversationState, _apiKey);

            _conversationState = resp.ConversationState;
            return(resp);
        }
Example #4
0
 /// <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));
 }
Example #5
0
 public CleverbotResponse GetResponse(string message)
 {
     return(CleverbotResponse.CreateAsync(message, "", ApiKey).GetAwaiter().GetResult());
 }
 /// <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, int?wacky = null, int?talkative = null, int?attentive = null)
 {
     return(CleverbotResponse.CreateAsync(message, "", ApiKey, wacky, talkative, attentive));
 }