tdlib / telegram-bot-api

Telegram Bot API server
https://core.telegram.org/bots
Boost Software License 1.0
3.15k stars 597 forks source link

Treat chat_join_requests like chat-initiating messages #198

Closed nmlorg closed 2 years ago

nmlorg commented 2 years ago
  1. I created a new group using the Telegram client, making a bot account I use for testing an admin.
  2. I created an invite link, toggling on "Approve New Members".
  3. I had a friend who did not have a chat open with my test bot click the link.
  4. The update came through:
    {'chat_join_request': {'chat': {'all_members_are_administrators': True,
                                    'id': -987654321,
                                    'title': 'invite link test group',
                                    'type': 'group'},
                           'date': 1636414880,
                           'from': {'first_name': 'FiRsT',
                                    'id': 123456789,
                                    'is_bot': False,
                                    'last_name': 'LaSt',
                                    'username': 'UsErNaMe'},
                           'invite_link': {'creates_join_request': True,
                                           'creator': {...
  5. I tried to send a message from the bot to the user, but it failed:
    >>> bot.sendmessage(chat_id=123456789, text='test')
    ntelebot.errors.Forbidden: {'ok': False, 'error_code': 403, 'description': "Forbidden: bot can't initiate conversation with a user"}

    Despite the one-character case mismatch, I assume this is coming from td/telegram/MessagesManager.cpp:

    void MessagesManager::on_send_message_fail(int64 random_id, Status error) {
     ⋮
          } else if (error.message() == "PEER_ID_INVALID") {
            error_code = 403;
            if (td_->auth_manager_->is_bot() &&
                (dialog_id.get_type() == DialogType::User || dialog_id.get_type() == DialogType::SecretChat)) {
              error_message = "Bot can't initiate conversation with a user";
            }

    and I don't see PEER_ID_INVALID anywhere else, so I assume this is a server restriction.


I'm working on a bot to replace the "lobby/foyer" pattern, where:

  1. public-in-spirit group RealGroup becomes private,
  2. creates a separate public group RealGroupFoyer,
  3. potential participants join RealGroupFoyer,
  4. a bot sends a CAPTCHA, and
  5. an admin [optionally interacts with them to further determine they're a real human, then] manually adds them to RealGroup.

  My original idea was:

  1. an admin adds my foyer bot to RealGroup as an admin,
  2. admin has the bot generate a deeplink that encodes the group's id,
  3. admins give out the deeplink in place of an invite link.
  4. Potential participant clicks the link, opening a placeholder chat with the bot and displaying a "START" button, then
  5. potential participant clicks the START button, opening an actual chat and sending the /start command.
  6. Bot responds with a CAPTCHA, etc.
  7. Bot generates a single-use invite link and sends it in the chat.
  8. Potential participant clicks the bot-generated invite link.

  I would like to switch to:

  1. an admin adds my foyer bot to RealGroup as an admin,
  2. admin creates an invite link with "Approve New Members" set,
  3. admins give out the invite link as usual.
  4. Potential participant clicks the link, causing a chat_join_request update to be sent to the bot.
  5. no extra verification step
  6. Bot creates a chat with the user and responds with a CAPTCHA, etc.
  7. Bot approves the join request.
  8. no extra join step
levlam commented 2 years ago

This was planned as a part of Bot API 5.5 update and the feature is live now.

yuli12gri commented 2 years ago

# Дубликат #