-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
55 lines (39 loc) · 1.52 KB
/
bot.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
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
import logging
from typing import List
from telegram import ForceReply, Update
from telegram.ext import (
Application,
CommandHandler,
ContextTypes,
MessageHandler,
filters,
)
from .config import FORWARD_FROM, CHAT_ID, BOT_TOKEN
# Enable logging
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
)
# set higher logging level for httpx to avoid all GET and POST requests being logged
logging.getLogger("httpx").setLevel(logging.WARNING)
logger = logging.getLogger(__name__)
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
user = update.effective_user
await update.message.reply_html(
rf"Hi {user.mention_html()}! I'm Alive. :p",
reply_markup=ForceReply(selective=True),
)
async def forward(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await update.message.forward(CHAT_ID)
def main() -> None:
"""Start the bot."""
# Create the Application and pass it your bot's token.
application = Application.builder().token(BOT_TOKEN).build()
# on different commands - answer in Telegram
application.add_handler(CommandHandler("start", start))
application.add_handler(CommandHandler("ping", start))
# on non command i.e message - echo the message on Telegram
application.add_handler(MessageHandler(filters.User(user_id=FORWARD_FROM), forward))
application.run_polling(allowed_updates=Update.ALL_TYPES)
if __name__ == "__main__":
main()