-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.py
More file actions
39 lines (35 loc) · 1.14 KB
/
index.py
File metadata and controls
39 lines (35 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Simple Bot to reply to Telegram messages
# This program is dedicated to the public domain under the CC0 license.
import logging
import telegram
from telegram.error import NetworkError, Unauthorized
from time import sleep
def main():
bot = telegram.Bot('212766013:AAH4tIpm6hHZREsxYNuYdCdNbw6CDlwV094')
try:
update_id = bot.getUpdates()[0].update_id
except IndexError:
update_id = None
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
while True:
try:
update_id = echo(bot, update_id)
except NetworkError:
sleep(1)
except Unauthorized:
update_id += 1
def echo(bot, update_id):
for update in bot.getUpdates(offset=update_id, timeout=10):
chat_id = update.message.chat_id
update_id = update.update_id + 1
voice = update.message.voice
if voice:
newFile = bot.getFile(voice.file_id)
newFile.download('voice.ogg')
bot.sendMessage(chat_id=chat_id, text="Voice!")
return update_id
if __name__ == '__main__':
main()