Commands are not being acknowledged by my Telegram bot

I am experiencing an issue with my Telegram bot, which fails to respond to any commands I send. The logs indicate that the webhook is set up correctly, and the bot itself is running, yet it doesn’t log any interactions or respond to messages. Can anyone assist in diagnosing the cause of this issue?

import telebot
from telebot.types import InlineKeyboardButton, InlineKeyboardMarkup, CallbackQuery
import logging
from datetime import datetime, timezone
from flask import Flask, request, abort

# Configure logging
logging.basicConfig(
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    level=logging.DEBUG
)
logger = logging.getLogger(__name__)

# Your bot token
TOKEN = "YOUR_BOT_TOKEN"
# Webhook URL
WEBHOOK_URL = "YOUR_WEBHOOK_URL"

# Initialize the bot
bot = telebot.TeleBot(TOKEN)

# Start command handler
@bot.message_handler(commands=['init'])
def welcome_user(message):
    logger.info(f"/init command received from user {message.from_user.id}")

    keyboard = InlineKeyboardMarkup()
    keyboard.add(InlineKeyboardButton("Select time", callback_data='select_time'))

    bot.send_message(
        message.chat.id,
        "Greetings! This bot will provide you with a word along with its meaning daily. Please select a convenient time for reading it.",
        reply_markup=keyboard
    )

# Button callback handler
@bot.callback_query_handler(func=lambda call: True)
def process_callback(call: CallbackQuery):
    logger.info(f"Callback data received: {call.data}")

    if call.data == 'select_time':
        keyboard = InlineKeyboardMarkup()
        keyboard.add(InlineKeyboardButton("Morning", callback_data='morning'))
        keyboard.add(InlineKeyboardButton("Afternoon", callback_data='afternoon'))
        keyboard.add(InlineKeyboardButton("Evening", callback_data='evening'))
        keyboard.add(InlineKeyboardButton("Night", callback_data='night'))
        bot.edit_message_text(
            chat_id=call.message.chat.id,
            message_id=call.message.message_id,
            text="Select a time of day:",
            reply_markup=keyboard
        )

# Flask app to handle webhooks
app = Flask(__name__)

@app.route("/", methods=['POST'])
def handle_webhook():
    logger.info("Webhook request received")
    if request.headers.get('content-type') == 'application/json':
        json_data = request.get_data().decode('utf-8')
        logger.debug(f"JSON received: {json_data}")
        update = telebot.types.Update.de_json(json_data)
        bot.process_new_updates([update])
        return 'OK', 200
    else:
        logger.warning("Invalid request header")
        abort(400)

if __name__ == '__main__':
    bot.remove_webhook()
    bot.set_webhook(url=WEBHOOK_URL)
    app.run(host='0.0.0.0', port=8443)

Another possible issue could be related to your webhook certificate configuration. Telegram requires the use of a valid, trusted SSL certificate for webhooks. If your server is running with a self-signed certificate or if there are issues with the certificate chain, Telegram may not be able to connect properly. Additionally, ensure your WEBHOOK_URL is accessible publicly from Telegram’s servers. You could also test your setup locally without webhooks using long polling as a troubleshooting step to see if the bot’s core functionalities are working as expected.

I’ve faced a similar issue with my Telegram bot before. Have you confirmed that your server is able to handle the incoming POST requests? It might be worth checking that your server’s firewall is configured to allow traffic through the port specified for your webhook (in your case, port 8443). Another thing to verify is whether your public URL endpoint correctly points to your Flask app and that there’s no NAT or proxy issues affecting communication to your server. Ensuring there’s no issue in these setups helped me resolve my bot’s non-responsiveness.

Sometimes its as simple as a mismatched TOKEN that causes bot not to respond. Double-check your YOUR_BOT_TOKEN is correct. Also, make sure that your handle_webhook function properly parses updates - any inconsistencies there could mean commands aren’t being processed properly. hope it helps!