I want to create a bot that posts messages on channels / groups, the user sends the group address for example: @group_name, and I need to get the ID, title I work with telebot library
@bot.message_handler(commands=['addgroup'])
def add_group(message):
msg = bot.send_message(message.chat.id, 'Send group link without @')
bot.register_next_step_handler(msg, add)
def add(message):
url = "telegram.me/" + message.text
keyboard = types.InlineKeyboardMarkup()
keyboard.add(types.InlineKeyboardButton("##HERE I NEED GROUP NAME##", url=url))
msg = bot.send_message(message.chat.id, "Add this group?", reply_markup=keyboard)
bot.register_next_step_handler(msg, check_group)
....
How can I get this information?
Let's read telegram docs...
getChat
Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). Returns a Chat object on success.
Parameters:
chat_id
- unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername).So,
P.S.:
register_next_step_handler
is antipattern, useaiogram
's FSM instead.