Greetings, dear ones. First, I will introduce you to the essence of the bot’s work.
There is an administrator (one telegram id), and he should receive notifications about ordinary users who write /start in the bot.
There is a table with user data (his nickname, identification number (issued to the user as soon as he writes / start) and a column for data from the admin).
As soon as the administrator is notified about the activation of the bot by an ordinary user, he is asked to write certain information about this user (the administrator enters this data in his chat with the bot), it must be processed and added to the last column of the user.
The problem is as follows: it is impossible to make the bot process the administrator’s message after it receives a notification about the user. The admin’s messages simply do not go anywhere and the bot stops working, the user is also not logged into the database because of this.
Please help me figure it out. Maybe someone has encountered this and solved such a problem (in telebot, this is done very simply: the administrator’s message is registered in a variable and then it is added to the database, in aiogram, unfortunately, this is not possible as far as I understand, but I cannot use telebot: the bot must be asynchronous)
@router.message(CommandStart())
async def cmd_start(message: Message, state: FSMContext, bot: Bot):
user_id = message.from_user.id
user_name = message.from_user.first_name
if not await rq.user_exists(user_id):
await state.update_data(user_id=user_id, user_name=user_name)
# We send a welcome message to the user
await message.reply("Welcome! The administrator will assign you a tag soon")
# We notify the administrator about the new user and suggest choosing a tag
tags = await rq.get_all_tags()
if tags:
buttons = [[KeyboardButton(text=tag)] for tag in tags]
keyboard = ReplyKeyboardMarkup(keyboard=buttons, resize_keyboard=True)
await bot.send_message(
ADMIN_ID,
f"New user: {user_name} (ID: {user_id}) logged in. Provide information about him:",
reply_markup=keyboard
)
await state.set_state(Form.waiting_for_admin_tag_choice)
# else:
# await bot.send_message(ADMIN_ID, "There are no tags available. Please add tags.")
else:
await message.answer("You are already registered!")
# Notifying the administrator about an existing user
await bot.send_message(ADMIN_ID, f"User: {user_name} (ID: {user_id}) logged in.")
This is the handler code for the /start message from the user. It allows you to notify the administrator about the launch of his bot by a certain user. I can’t figure out what to add to this function in order for my functionality to work or which handler to add besides CommandStart
TAPAC is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.