Answer the question
In order to leave comments, you need to log in
Error 403 // Telegram Bot on webhooks?
Hello. I am writing a telegram bot on a pooling, I decided to upload it to the server and at the same time transfer it to webhooks. I rummaged through the Internet, from the source I found this code:
import logging
from aiogram import Bot, types, executor
from aiogram.contrib.middlewares.logging import LoggingMiddleware
from aiogram.dispatcher import Dispatcher
from aiogram.dispatcher.webhook import SendMessage
from aiogram.utils.executor import start_webhook
from aiogram.types import ParseMode
API_TOKEN = '000000:000000'
WEBHOOK_HOST = f'https://my domain'
WEBHOOK_PATH = f'/index.py'
WEBHOOK_URL = f'{WEBHOOK_HOST}{WEBHOOK_PATH}'
# webserver settings
WEBAPP_HOST = 'my domain.net' # or ip pip install --upgrade pip
WEBAPP_PORT = 8443
logging.basicConfig(level = logging.INFO)
bot = Bot(token = API_TOKEN)
dp = Dispatcher(bot)
dp.middleware.setup(LoggingMiddleware())
@dp.message_handler()
async def echo(message: types.Message):
print('echo enter')
return SendMessage(message.chat.id, message.text)
async def on_startup(dp):
await bot.delete_webhook()
await bot.set_webhook(url = WEBHOOK_URL)
# Пытаюсь отправить сразу на свой айдишник сообщение
return SendMessage(867690422, 'test')
async def on_shutdown(dp):
await bot.delete_webhook()
# Close DB connection (if used)
await dp.storage.close()
await dp.storage.wait_closed()
logging.warning('Bye!')
if __name__ == '__main__':
executor.start_webhook(
dispatcher = dp,
webhook_path = WEBHOOK_PATH,
on_startup = on_startup,
on_shutdown = on_shutdown,
skip_updates = True,
host = WEBAPP_HOST,
port = WEBAPP_PORT)
await bot.set_webhook(url = WEBHOOK_URL)
Displays a message that the webhooks have been successfully registered.Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question