Skip to content

Instantly share code, notes, and snippets.

@Leva-kleva
Created February 4, 2019 09:20
Show Gist options
  • Save Leva-kleva/7536edb6b39e4e2f4f51908d7d08eae2 to your computer and use it in GitHub Desktop.
Save Leva-kleva/7536edb6b39e4e2f4f51908d7d08eae2 to your computer and use it in GitHub Desktop.
import requests
class BotHandler:
def __init__(self, token):
self.token = token
self.api_url = "https://api.telegram.org/bot{}/".format(token)
def set_webhook(self):
method = "setwebhook"
params = {"url": }
resp = requests.post(self.api_url + method, params)
return resp
def get_updates(self, timeout=90):
method = 'getUpdates'
params = {'timeout': timeout}
resp = requests.get(self.api_url + method, params)
result_json = resp.json()['result']
return result_json
def send_message(self, chat_id, text):
params = {'chat_id': chat_id, 'text': text}
method = 'sendMessage'
resp = requests.post(self.api_url + method, params)
return resp
def get_last_update(self):
get_result = self.get_updates()
if len(get_result) > 0:
last_update = get_result[-1]
else:
last_update = get_result[len(get_result)]
return last_update
def command_start(self) :
return "GO!!!"
def command_help(self) :
CMD = ["/start",
"/help",
"/setting",
"/shedule"]
s = ""
for el in CMD :
s += el + "\n"
return s
def comand_setting(self) :
return "no setting. :("
def command_shedule(self, args) :
return myparser.main_parse(*args)
def update(bot) :
update = bot.get_last_update()
update_id = update["update_id"]
chat_text = update["message"]["text"]
chat_id = update["message"]["chat"]["id"]
chat_name = update["message"]["chat"]["first_name"]
return update_id, chat_text, chat_id, chat_name
if __name__ == "__main__" :
print("bot.py")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment