0% found this document useful (0 votes)
12 views

Code To Recieve & Reply Message From Users

code to recieve & reply message from users

Uploaded by

pupswind.com
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Code To Recieve & Reply Message From Users

code to recieve & reply message from users

Uploaded by

pupswind.com
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

import telebot

from config import TOKEN1, ADMIN

bot = telebot.TeleBot(TOKEN1)

# Admin's chat ID (replace with your admin chat ID)

admin_chat_id = ADMIN

#------------------------------

# Function to generate the main menu keyboard

def main_menu_keyboard():

keyboard = telebot.types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True)

keyboard.add(telebot.types.KeyboardButton("Send Message"))

return keyboard

# Handler for the /start command

@bot.message_handler(commands=['start'])

def start(message):

bot.send_message(message.chat.id, "Welcome to the bot! Click 'Send Message' to send a message to


the admin.", reply_markup=main_menu_keyboard())

# Handler for the "Send Message" button

@bot.message_handler(func=lambda message: message.text == "Send Message")

def send_message(message):

bot.send_message(message.chat.id, "Please type your message:")

bot.register_next_step_handler(message, forward_message_to_admin)
# Handler to forward the message to the admin

def forward_message_to_admin(message):

forwarded_message = f"New message from user {message.from_user.first_name} (ID:


{message.from_user.id}):\n{message.text}"

inline_button = telebot.types.InlineKeyboardMarkup()

inline_button.add(telebot.types.InlineKeyboardButton("Reply", callback_data=f"reply:
{message.from_user.id}"))

bot.send_message(admin_chat_id, forwarded_message, reply_markup=inline_button)

bot.send_message(message.chat.id, "Your message has been sent to the admin.")

# Handler for admin replies

@bot.callback_query_handler(func=lambda call: call.data.startswith('reply:'))

def reply_to_user(call):

user_id = call.data.split(':')[1]

bot.send_message(call.message.chat.id, "Please type your reply:")

bot.register_next_step_handler(call.message, lambda message: forward_reply_to_user(message,


user_id))

# Handler to forward the reply to the user

def forward_reply_to_user(message, user_id):

bot.send_message(user_id, f"Reply from admin: {message.text}")

bot.send_message(admin_chat_id, "Your reply has been sent to the user.")

# Start polling

bot.polling()

You might also like