-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
40 lines (26 loc) · 1.28 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
import logging
from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes
import os
# Replace 'YOUR_BOT_TOKEN' with the token you get from BotFather on Telegram
TOKEN = os.environ["TELEGRAM_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 send_chat_id(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Send a message when the command /chat_id is issued."""
username = update.effective_user.full_name
await update.message.reply_text(f"Olá! {username}\n\nO seu chat ID é:\n{update.message.chat_id}")
logger.info("Sent chat id.")
def main() -> None:
"""Start the bot."""
# Create the Application and pass it your bot's token.
application = Application.builder().token(TOKEN).build()
# on different commands - answer in Telegram
application.add_handler(CommandHandler("chat_id", send_chat_id))
# Run the bot until the user presses Ctrl-C
application.run_polling(allowed_updates=Update.ALL_TYPES)
if __name__ == "__main__":
main()