Created
May 24, 2016 01:18
-
-
Save JuanPotato/f36ea91beb2274c7072f5056727104c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import time | |
TOKEN = '' | |
url = 'https://api.telegram.org/bot' + TOKEN | |
offset = 0 | |
answerInlineQueryUrl = url + '/answerInlineQuery' | |
sendVoiceUrl = url + '/sendVoice' | |
getUpdates = url + '/getUpdates' | |
inlineResult = { | |
'cache_time': 9999999999999999, | |
'inline_query_id': "", | |
'results': json.dumps([ | |
{ | |
'type': 'voice', | |
'voice_file_id': 'AwADBAAD8gADFZWtAAH3YgdiZ4DFbAI', | |
'id': 'jop', | |
'title': 'Jop Punch' | |
} | |
]) | |
} | |
while 1: | |
try: | |
res = requests.get(getUpdates, params={'offset':offset,'timeout':60}) | |
res = res.json() | |
except: | |
print("Something happened. Trying again in 3 seconds..." | |
time.sleep(3) | |
continue | |
if len(res['result']) and res['result'][-1]['update_id'] >= offset: | |
offset = res['result'][-1]['update_id'] + 1 | |
print(res) | |
for msg in res['result']: | |
if 'message' in msg: | |
paramaters = { | |
'chat_id': msg['message']['chat']['id'], | |
'voice': 'AwADBAAD8gADFZWtAAH3YgdiZ4DFbAI' | |
} | |
requests.get(sendVoiceUrl, params=paramaters) | |
if 'inline_query' in msg: | |
inlineResult["inline_query_id"] = msg["inline_query"]["id"] | |
requests.get(answerInlineQueryUrl, params=inlineResult) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment