Send a welcome message to newcomers to the Telegram group | Telegram bot

15 April 2023 1003 Reading time: 1 minute

You have a telegram group where you gather your audience and you want to welcome message new members to the group, how can you do that?

To do this you need to follow a few steps

1. Need to create a Telegram bot( We talked about this in our article: How to create a Telegram bot with PHP? )

2. Adds our bot to the group we will use

3. PHP Telegram We create our bot with the following codes using the library

<?php
include 'Telegram.php';
$token = "YOUR_BOT_TOKEN";
$telegram = new Telegram($token);
$data = $telegram->getData();
if(isset($data['message']['new_chat_member']['first_name'])){
   $chat_id = $telegram->ChatID();
   $newUser = $data['message']['new_chat_member']['first_name'];
   $content = array('chat_id' => $chat_id, 'text' => $newUser.' welcome!');
   $telegram->sendMessage($content);
}

You can add the above codes by creating a bot.php file on your server and https://api.telegram.org/botYOUR_BOT_TOKEN/setWebhook?url=https://www.example.com/bot.php this way you can identify your Webhook by opening it in a browser. Your bot will now automatically send a "Welcome" message to new users who will join your Telegram group.

Similar articles