Skip to content

Instantly share code, notes, and snippets.

@JuanPotato
Created May 24, 2016 01:18
Show Gist options
  • Save JuanPotato/f36ea91beb2274c7072f5056727104c8 to your computer and use it in GitHub Desktop.
Save JuanPotato/f36ea91beb2274c7072f5056727104c8 to your computer and use it in GitHub Desktop.
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