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()