-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbot.py
More file actions
32 lines (23 loc) · 943 Bytes
/
bot.py
File metadata and controls
32 lines (23 loc) · 943 Bytes
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
import logging
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import settings
logging.basicConfig(filename="bot.log", level=logging.INFO)
PROXY = {'proxy_url': settings.PROXY_URL,
'urllib3_proxy_kwargs': {'username': settings.PROXY_USERNAME, 'password': settings.PROXY_PASSWORD}}
def greet_user(update, context):
print("Вызван /start")
update.message.reply_text("Здравствуй, пользователь!")
def talk_to_me(update, context):
text = update.message.text
print(text)
update.message.reply_text(text)
def main():
mybot = Updater(settings.API_KEY, use_context=True, request_kwargs=PROXY)
dp = mybot.dispatcher
dp.add_handler(CommandHandler("start", greet_user))
dp.add_handler(MessageHandler(Filters.text, talk_to_me))
logging.info("Бот стартовал")
mybot.start_polling()
mybot.idle()
if __name__ == "__main__":
main()