I am using laravel-notification-channels/telegram I’ve implemented welcome notification for my users and my bot sending that message with no issue, the second part of my implementation is to add those users (who I’ve sent welcome message) into my channel.
PS:
My bot is admin of my channel and has access to add users.
Logic
- Telegram users can register (done)
- Get telegram users data and send welcome message (done)
- Add telegram users to my channel by bot. (need help)
Code
Note:
my code currently is just enough to send welcome message, nothing about adding users to channel…
public $user;
public $telegram_id;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($user, $telegram_id)
{
$this->user = $user;
$this->telegram_id = $telegram_id;
}
public function toTelegram($notifiable)
{
// first message to bot (to recognize the user)
TelegramMessage::create()
->to('MY_BOT_ID');
// then message the user from bot
return TelegramFile::create()
->to($this->telegram_id) // registered user ID on telegram
->content("Hello");
}
// (NEXT) add user to channel
//.....
Any idea?
2
Answers
I’m afraid that won’t be possible with the bot API since there’s no API method for that (see Telegram Bot API).
However, you could give the users an invitation link to the chat so they can join. You can generate the invite link using exportChatInviteLink method, but this can’t be done through
laravel-notification-channels/telegram
. Perhaps you could generate the link manually through the API, add it to your application, and then send the link to the users.If you really wish to add the users to the chat, you can use the channels.inviteToChannel method on the client API. MadelineProto is a PHP Telegram client library which can do that.
Added the corresponding method to the documentation
TELEGRAM DOCS