폴링 워커로 실행하기
Python 프로세스를 계속 실행하고 requirements를 설치하는 호스트를 쓰세요. Bothosting에서는 Python 폴링 봇 프로필을 고르고, main.py와 requirements.txt를 업로드하고, BotFather 토큰을 TELEGRAM_BOT_TOKEN로 저장한 뒤 시작하세요. 도메인이나 열린 포트는 필요 없어요. Spark는 256 MB RAM으로 무료 실행하고, 7일마다 갱신해요.
모델 번호: aiogram 3
aiogram>=3.13import asyncio, os
from aiogram import Bot, Dispatcher
from aiogram.filters import CommandStart
from aiogram.types import Message
dp = Dispatcher()
@dp.message(CommandStart())
async def start(message: Message):
await message.answer('Hosted and running.')
async def main():
bot = Bot(os.environ['TELEGRAM_BOT_TOKEN'])
await dp.start_polling(bot)
asyncio.run(main())모델 번호: python-telegram-bot 21+
python-telegram-bot>=21import os
from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text('Hosted and running.')
app = Application.builder().token(os.environ['TELEGRAM_BOT_TOKEN']).build()
app.add_handler(CommandHandler('start', start))
app.run_polling()시작하고 답장을 확인하기
- Python 폴링 봇 프로필로 배포를 만드세요. 두 파일을 루트에 올리고
MAIN_FILE을main.py로 설정하세요. TELEGRAM_BOT_TOKEN을 변수에 저장하고 배포를 시작하세요.- 노트북에 있는 사본을 모두 중지한 다음, 휴대폰에서
/start을 보내세요.
아무것도 도착하지 않고 로그에 충돌 오류가 보이면, 다른 프로세스나 webhook이 토큰을 쓰는 중이에요. 웹훅에서 polling으로 전환하기를 참고하세요. 재시작 뒤에도 상태를 유지하려면 대화를 기억하기를 참고하세요.