패키지 설치
pip install python-telegram-bot
코드
기본 입출력
import os
from dotenv import load_dotenv
from telegram import Update
from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("안녕하세요! 이름을 입력해주세요.")
async def handle_text(update: Update, context: ContextTypes.DEFAULT_TYPE):
user_input = update.message.text
await update.message.reply_text(f"입력하신 텍스트는: {user_input}")
def main():
load_dotenv()
token = os.getenv('TELEGRAM_TOKEN')
application = Application.builder().token(token).build()
application.add_handler(CommandHandler('start', start))
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_text))
application.run_polling()
if __name__ == '__main__':
main()