Do it yourself to realize four free chat robots

Chatterbot is a computer program that talks through dialogue or words. It can simulate human dialogue and pass Turing test, such as Siri, Xiaoai classmates, Microsoft Xiaobing, etc.


This tutorial will teach you to use Python to realize four free and easy-to-use chat robots: Microsoft Xiaobing, Turing robot, Tencent chat, Qingyun guest robot!


Start with simplicity!


Qingyun guest robot

brief introduction

Completely free, supporting functions: weather, translation, hidden poems, jokes, lyrics, calculation, domain name information / filing / collection query, IP query, mobile phone number ownership, artificial intelligence chat

No need to register, no need to apply for key, just use it!



def qingyunke(msg):    url = '{}'.format(urllib.parse.quote(msg))    html = requests.get(url)    return html.json()["content"]msg = 'Do I look good?'print("Original words>>", msg)res = qingyunke(msg)print("Qingyun guest>>", res)



Do I look good? Qingyun guest


Turing robot

brief introduction

Turing robot is committed to "making machines understand the world", and its product services include robot open platform, robot OS and scene scheme. Through Turing robot, developers and manufacturers can create exclusive chat robots, customer service robots, domain dialogue question answering robots, children / service robots, etc. in an efficient way.


If you need to register an account, you can apply for 5 robots. Each robot with an uncertified account can only return 3 robots / day, and each robot with an authenticated account can use 100 robots / day.



After login, apply for robot creation and fill in relevant information


You can access WeChat personal numbers, WeChat official account numbers, QQ personal numbers and API calls.


Opening the expansion function in the expansion center

Get the API key, and note that the following key should not be opened!



def tuling(msg):    api_key = "1234"    url = ''    data = {        "perception": {            "inputText": {                "text": msg            },        },        "userInfo": {            "apiKey": api_key,            "userId": "1"        }    }    datas = json.dumps(data)    html =, datas).json()    if html['intent']['code'] == 4003:        print("Run out of times")        return None    return html['results'][0]['values']['text']msg = 'Do I look good?'print("Original words>>", msg)res = tuling(msg)print("Turing>>", res)



Do I look good Turing? Do you get angry when I say it's not?


Microsoft Wheatgrass

brief introduction

Microsoft Xiaobing is a leading cross platform artificial intelligence robot. Microsoft Xiaobing pays attention to the development of artificial intelligence in the dimension of fitting human EQ, and emphasizes the basic value of artificial intelligence EQ rather than task completion in human-computer interaction.

Need to adopt Xiaobing first! Follow Microsoft Xiaobing through Weibo, send her a message and click her back link to adopt.

After adoption, press F12 to open the debugging window and find the SUB value in the Cookie interface (very important)

Send a random message to Xiaobing, and find the source value and uid value in the head interface (very important)

Note that Weibo cannot manually click logout to exit, or the value obtained above will fail!! (very important)



def xiaobing(msg):    uid = '123'    source = '123'    SUB = '123'    url_send = ''    data = {        'text': msg,        'uid': uid,        'source': source    }    headers = {        'cookie': 'SUB='+SUB,        'Content-Type': 'application/x-www-form-urlencoded',        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36',        'Referer': ''    }    response =, data=data, headers=headers).json()    sendMsg = response['text']    time.sleep(1)    while True:        url_get = '{}&source={}'.format(uid, source)        response = requests.get(url_get, headers=headers).json()        getMsg = response['direct_messages'][0]['text']        if sendMsg == getMsg:            time.sleep(1)        else:            return getMsg            msg = 'Do I look good?'print("Original words>>", msg)res = xiaobing(msg)print("Little ice>>", res)



How do I look? Xiaobing. Well, I'll try my best to identify you:


Tencent chat

brief introduction

Tencent chat service is based on the NLP engine capability, data operation capability and 100 billion level internet corpus data support of AI Lab, and integrates a wide range of Knowledge Q & A capabilities. It can realize hundreds of custom attribute configurations, as well as different language styles and speaking ways of men and women, so that chat becomes more intelligent, simple and interesting.

Registration, application and encryption are required.

There is a pit here. The user-defined configuration of chat portraits must not be opened, otherwise the call always goes wrong. I have checked it for a long time!!!



Create app first

Get ID and KEY



def tencent(msg):    APPID = '123'    APPKEY = '123'    url = ''    params = {        'app_id': APPID,        'time_stamp': str(int(time.time())),        'nonce_str': ''.join(random.choice(string.ascii_letters + string.digits) for x in range(16)),        'session': '10000'.encode('utf-8'),        'question': msg.encode('utf-8')    }    sign_before = ''    for key in sorted(params):        # Key value splicing process value Partial needs URL Code, URL The coding algorithm uses capital letters, for example%E8. quote Default uppercase.        sign_before += '{}={}&'.format(key, urllib.parse.quote(params[key], safe=''))        # The key will be applied to app_key Key name, concatenate to string sign_before End    sign_before += 'app_key={}'.format(APPKEY)    # Pair string sign_before Conduct MD5 Operation, get interface request signature    sign = hashlib.md5(sign_before.encode('UTF-8')).hexdigest().upper()    params['sign'] = sign    # print(params)    html =, data=params).json()    return html['data']['answer']msg= 'Do I look good?'print("Original words>>", msg)res = tencent(msg)print("tencent>>", res)



How do I look? Tencent

53 original articles published, 39 praised, 30000 visitors+

Tags: JSON Python Mobile PHP

Posted on Tue, 03 Mar 2020 22:10:37 -0800 by Sa177ir