@@ -0,0 +1,1572 @@
+import requests%0Aimport json%0Aimport os%0Afrom time import sleep%0Afrom pprint import pprint%0A%0A# Read token from untracked credentials file.%0A# We wouldn't want this on Github now, would we?%0Af = open(%22creds.txt%22)%0Alines = f.readlines()%0Af.close%0Atoken = lines%5B0%5D.strip()%0Aprint %22Token loaded%22%0A%0A# If it exists, read the previous last update id from file%0Alast_update = 0%0Aif os.path.isfile(%22offset%22):%0A    f = open(%22offset%22, 'r')%0A    last_update = int(f.read())%0A    f.close%0A    print %22Offset loaded%22%0Aelse:%0A    print %22No offset - starting new%22%0A%0Aurl = 'https://api.telegram.org/bot%25s/' %25 token%0A%0Awhile True:%0A    gotUpdate = False%0A    get_updates = json.loads(requests.get(url + 'getUpdates').content)%0A    for update in get_updates%5B'result'%5D:%0A        if last_update %3C update%5B'update_id'%5D:%0A            gotUpdate = True%0A            msg = update%5B'message'%5D%5B'text'%5D%0A            if msg == %22/first%22:%0A                reply = %22You sent the first command%22%0A                out = %22First command received%22%0A            elif msg == %22/second%22:%0A                reply = %22You sent the second command%22%0A                out = %22Second command received%22%0A            else:%0A                reply = %22You sent: %22 + msg%0A                out = msg + %22 received%22%0A            print out%0A            last_update = update%5B'update_id'%5D%0A            requests.get(url + 'sendMessage', params=dict(chat_id=update%5B'message'%5D%5B'chat'%5D%5B'id'%5D, text=reply))%0A            print %22Acknowledged%22%0A    if gotUpdate:%0A        f = open(%22offset%22, 'w')%0A        f.write(str(last_update))%0A        f.close%0A        print %22Stored new offset%22%0A    sleep(3)%0A

Bot which understands commands