#!/usr/bin/python # This is a simple echo bot using the decorator mechanism. # It echoes any incoming text messages. # Example on built-in function to receive and process webhooks. from telebot.async_telebot import AsyncTeleBot import asyncio bot = AsyncTeleBot('TOKEN') WEBHOOK_SSL_CERT = './webhook_cert.pem' # Path to the ssl certificate WEBHOOK_SSL_PRIV = './webhook_pkey.pem' # Path to the ssl private key DOMAIN = '1.2.3.4' # either domain, or ip address of vps # Quick'n'dirty SSL certificate generation: # # openssl genrsa -out webhook_pkey.pem 2048 # openssl req -new -x509 -days 3650 -key webhook_pkey.pem -out webhook_cert.pem # # When asked for "Common Name (e.g. server FQDN or YOUR name)" you should reply # with the same value in you put in WEBHOOK_HOST # Handle '/start' and '/help' @bot.message_handler(commands=['help', 'start']) async def send_welcome(message): await bot.reply_to(message, """\ Hi there, I am EchoBot. I am here to echo your kind words back to you. Just say anything nice and I'll say the exact same thing to you!\ """) # Handle all other messages with content_type 'text' (content_types defaults to ['text']) @bot.message_handler(func=lambda message: True) async def echo_message(message): await bot.reply_to(message, message.text) # it uses fastapi + uvicorn asyncio.run(bot.run_webhooks( listen=DOMAIN, certificate=WEBHOOK_SSL_CERT, certificate_key=WEBHOOK_SSL_PRIV ))