-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
43 lines (27 loc) · 1.29 KB
/
main.py
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
40
41
42
43
import logging
import os
from dotenv import load_dotenv
from telegram import Update
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes, MessageHandler, filters
# Enable logging
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
)
load_dotenv() # take environment variables from .env.
TELEGRAM_TOKEN = os.getenv('TELEGRAM_TOKEN')
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await update.message.reply_text(f'Start {update.effective_user.first_name}')
async def hello(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await update.message.reply_text(f'Hello {update.effective_user.first_name}')
async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
message = update.message.text.lower()
if 'привіт' in message:
reply_text = f'Привіт {update.effective_user.first_name}!'
else:
reply_text = 'Я тебе не розумію.'
await update.message.reply_text(reply_text)
app = ApplicationBuilder().token(TELEGRAM_TOKEN).build()
app.add_handler(CommandHandler("start", start))
app.add_handler(CommandHandler("hello", hello))
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
app.run_polling()