Smart chat robot with fast implementation in C #

Source: Internet
Author: User

This is a chat robot, very convenient, direct call Turing machine Person API can, dialogue way a ask a answer!
There are only PHP and Java examples on the Turing network, so I wrote a Windows.

Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.windows.forms;using system.net;using System.IO;using     newtonsoft.json;//program needs to refer to Newtonsoft.json http://json.codeplex.com/namespace tuling{public partial class Mainform:form        {HttpWebResponse Response = null;        Public MainForm () {InitializeComponent (); }//////<summary> dialogue Turing person///</summary>//<param name= "p_strmess        Age "></param>///<returns></returns> public string connecttuling (string p_strmessage)            {string result = NULL;                try {//Registration code yourself to online registration to String APIKEY = "C32ccaa805b6441be76bc18074f12e51";                String _strmessage = p_strmessage; String INFO = Encoding.UTF8.GetString (Encoding.UTF8.GetBytes (_strmeSsage));                String GetURL = "http://www.tuling123.com/openapi/api?key=" + APIKEY + "&info=" + info;                HttpWebRequest myrequest = (HttpWebRequest) httpwebrequest.create (GetURL);                HttpWebResponse myresponse = (HttpWebResponse) myrequest.getresponse ();                Response = Myresponse; using (Stream MyStream = Myresponse.getresponsestream ()) {Long progmaximum = Myresponse .                    ContentLength;                    Long totaldownloadedbyte = 0;                    Byte[] by = new byte[1024]; int osize = Mystream.read (by, 0, by.)                    Length);                    Encoding Encoding = Encoding.UTF8;                        while (Osize > 0) {totaldownloadedbyte = osize + totaldownloadedbyte; Result + = encoding.                        GetString (by, 0, osize);                        Long progvalue = Totaldownloadedbyte; Osize = MYSTREAM.READ (by, 0, by.)                    Length); }}//parsing json jsonreader reader = new JsonTextReader (new StringReader (Result))                ; while (reader. Read ()) {The content in//text is the IF (reader) you need. path== "text") {//Results assignment result = reader.                    Value.tostring (); } Console.WriteLine (reader. Tokentype + "\t\t" + reader. ValueType + "\t\t" + reader.                  Value);            }} catch (Exception) {throw;        } return result; private void Btn_send_click (object sender, EventArgs e) {string returnmess = Connec Ttuling (rtb_send.            Text); Rtb_mess.        Text = returnmess; private void Btn_close_click (object sender, EventArgs e) {this.this.FindForm ().        Close ();    }     <summary>///Enter shortcut keys///</summary>//<param name= "Sender" ></param>        <param name= "E" ></param> private void Rtb_send_keydown (object sender, KeyEventArgs e) {if (E.keycode = = keys.enter) {rtb_mess. text= connecttuling (rtb_send.            Text); }        }    }  }

Smart chat robot with fast implementation in C #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.