Telegram Bot fails to send admin-triggered reply to user

Despite processing messages correctly, user updates remain missing until admin clicks a button.

from telebot import TeleBot, types

bot_token = 'your_new_token'
chat_bot = TeleBot(bot_token)
admin_chat = 87654321
user_holder = None

@chat_bot.message_handler(commands=['initiate'])
def greet_user(msg):
    if msg.chat.id == admin_chat:
        chat_bot.send_message(admin_chat, 'Hello, Admin!')
    else:
        welcome = f'Hello {msg.from_user.first_name}, press the button for payment details.'
        markup = types.InlineKeyboardMarkup()
        markup.add(types.InlineKeyboardButton('Details', callback_data='detail'))
        chat_bot.send_message(msg.chat.id, welcome, reply_markup=markup)

@chat_bot.callback_query_handler(func=lambda c: True)
def process_callback(c):
    chat_id = c.message.chat.id
    info = 'Pay using card 1111 2222 3333 4444 and send receipt.'
    if c.data == 'detail':
        chat_bot.send_message(chat_id, info)

@chat_bot.message_handler(content_types=['photo', 'text'])
def handle_media(msg):
    global user_holder
    if msg.from_user.id != admin_chat:
        if msg.content_type == 'photo':
            user_holder = msg.from_user.id
            file_id = msg.photo[-1].file_id
            kb = types.InlineKeyboardMarkup()
            kb.add(types.InlineKeyboardButton('Accept', callback_data='accept'), types.InlineKeyboardButton('Deny', callback_data='deny'))
            chat_bot.send_photo(admin_chat, file_id, reply_markup=kb)
        else:
            chat_bot.send_message(msg.chat.id, 'Submit a payment screenshot as a photo.')

@chat_bot.callback_query_handler(func=lambda c: True)
def final_step(c):
    global user_holder
    if c.data == 'accept':
        chat_bot.send_message(user_holder, 'Payment accepted. See updated channel info separately.')
    elif c.data == 'deny':
        chat_bot.send_message(user_holder, 'Payment not confirmed. Please resend receipt.')
    chat_bot.answer_callback_query(c.id)

chat_bot.polling()

hey, maybe having two callback handlers is messin up your user update flow. try merging them to see if user_holder gets updated properly. could also be a race condtion issue

Based on my experience while troubleshooting similar issues, I found that splitting the logic for different types of callbacks into clearly separated functions usually yields more predictable results. I’ve seen that mixing administrative commands with user updates in a single control flow might lead to interference, especially when updating global variables. Adding more granular logging can help pinpoint exactly when and where the flow falters. Consider restructuring your callback handlers to separate concerns more clearly and test each section in isolation to ensure user_holder is updated correctly.

The issue might also be caused by the way telebot handles separate callback functions rather than solely by the global variable manipulation. I encountered a similar situation where callbacks with overlapping conditions resulted in unexpected behavior. In my experience, consolidating or clearly separating the logic with unique filters in each callback function helps prevent misrouting of updates. Using logging to track the flow has proven effective. I recommend verifying that each callback function is strictly handling its designated task and that there is no race condition in updating variables.

mabe its the global var interfering; try resetting user_holder right after use so each msg is handled separately. also add logging to check if null values occures in callbacks.