'692779Et_e91Q97jP5gbjDhD0apKU30I';
                  
                  
                  
                  
                  
                  // Your webhook URL
                  
                  
                  $webhookUrl = 'https://ttrsop.live/Autokicker.php';
                  
                  
                  
                  
                  
                  // Set the webhook
                  
                  
                  $apiUrl = "https://api.telegram.org/bot$botToken/setWebhook";
                  
                  
                  $data = array('url' => $webhookUrl);
                  
                  
                  $options = array(
                  
                  
                      'http' => array(
                  
                  
                          'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
                  
                  
                          'method'  => 'POST',
                  
                  
                          'content' => http_build_query($data),
                  
                  
                      ),
                  
                  
                  );
                  
                  
                  $context  = stream_context_create($options);
                  
                  
                  $result = file_get_contents($apiUrl, false, $context);
                  
                  
                  
                  
                  
                  if ($result === false) {
                  
                  
                      die('Failed to set up the webhook.');
                  
                  
                  } else {
                  
                  
                      echo 'Webhook set up successfully.';
                  
                  
                  }
                  
                  
                  
                  
                  
                  // Handle incoming updates
                  
                  
                  $input = file_get_contents("php://input");
                  
                  
                  $update = json_decode($input, true);
                  
                  
                  
                  
                  
                  if (isset($update['message']) && isset($update['message']['chat']['id'])) {
                  
                  
                      $chatId = $update['message']['chat']['id'];
                  
                  
                  
                  
                  
                      if (isset($update['message']['new_chat_members'])) {
                  
                  
                          // Handle new member join
                  
                  
                          $newMember = $update['message']['new_chat_members'][0];
                  
                  
                          $newMemberId = $newMember['id'];
                  
                  
                  
                  
                  
                          // Send a welcome message to the new member
                  
                  
                          $welcomeMessage = "Welcome to the group! User ID: $newMemberId";
                  
                  
                          sendMessage($botToken, $chatId, $welcomeMessage);
                  
                  
                      } elseif (isset($update['message']['left_chat_member'])) {
                  
                  
                          // Handle member leave
                  
                  
                          $leftMember = $update['message']['left_chat_member'];
                  
                  
                          $leftMemberId = $leftMember['id'];
                  
                  
                  
                  
                  
                          // Send a farewell message to the leaving member
                  
                  
                          $farewellMessage = "Goodbye! User ID: $leftMemberId";
                  
                  
                          sendMessage($botToken, $chatId, $farewellMessage);
                  
                  
                      }
                  
                  
                  }
                  
                  
                  
                  
                  
                  function sendMessage($token, $chatId, $message) {
                  
                  
                      $apiUrl = "https://api.telegram.org/bot$token/sendMessage";
                  
                  
                      $data = array('chat_id' => $chatId, 'text' => $message);
                  
                  
                      $options = array(
                  
                  
                          'http' => array(
                  
                  
                              'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
                  
                  
                              'method'  => 'POST',
                  
                  
                              'content' => http_build_query($data),
                  
                  
                          ),
                  
                  
                      );
                  
                  
                      $context  = stream_context_create($options);
                  
                  
                      $result = file_get_contents($apiUrl, false, $context);
                  
                  
                  
                  
                  
                      if ($result === false) {
                  
                  
                          echo 'Failed to send message.';
                  
                  
                      }
                  
                  
                  }
                  
                  
                
s0m31 why this not work
add 'allowed_updates' => '["message", "chat_member"]' to data that goes to setWebhook
and better remove leftovers of your tokens
Now fine - <?php // Your bot token $botToken = 'YOUR_BOT_TOKEN'; // Your webhook URL $webhookUrl = 'https://your-webhook-url/your-webhook-endpoint'; // Set the webhook with 'allowed_updates' parameter $apiUrl = "https://api.telegram.org/bot$botToken/setWebhook"; $data = array( 'url' => $webhookUrl, 'allowed_updates' => '["message", "chat_member"]' ); $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data), ), ); $context = stream_context_create($options); $result = file_get_contents($apiUrl, false, $context); if ($result === false) { die('Failed to set up the webhook.'); } else { echo 'Webhook set up successfully.'; } // Handle incoming updates $input = file_get_contents("php://input"); $update = json_decode($input, true); if (isset($update['message']) && isset($update['message']['chat']['id'])) { $chatId = $update['message']['chat']['id']; if (isset($update['message']['new_chat_members'])) { // Handle new member join $newMember = $update['message']['new_chat_members'][0]; $newMemberId = $newMember['id']; // Send a welcome message to the new member $welcomeMessage = "Welcome to the group! User ID: $newMemberId"; sendMessage($botToken, $chatId, $welcomeMessage); } elseif (isset($update['message']['left_chat_member'])) { // Handle member leave $leftMember = $update['message']['left_chat_member']; $leftMemberId = $leftMember['id']; // Send a farewell message to the leaving member $farewellMessage = "Goodbye! User ID: $leftMemberId"; sendMessage($botToken, $chatId, $farewellMessage); } } function sendMessage($token, $chatId, $message) { $apiUrl = "https://api.telegram.org/bot$token/sendMessage"; $data = array('chat_id' => $chatId, 'text' => $message); $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data), ), ); $context = stream_context_create($options); $result = file_get_contents($apiUrl, false, $context); if ($result === false) { echo 'Failed to send message.'; } }
NOT WORK
new_chat_members and left_chat_member are only service messages. You should use chat_member update to catch them all
try to debug your code yourself. chat_member updates are known to be buggy. Maybe mine is just a service message
yea, probably attached a service message
What i add on offset
do not add this parameter. Its for getupdates only
Now - <?php // Your bot token $botToken = 'YOUR_BOT_TOKEN'; // Your webhook URL $webhookUrl = 'https://your-webhook-url/your-webhook-endpoint'; // Set the webhook with 'allowed_updates' parameter $apiUrl = "https://api.telegram.org/bot$botToken/setWebhook"; $data = array( 'url' => $webhookUrl, 'allowed_updates' => '["chat_member"]' ); $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data), ), ); $context = stream_context_create($options); $result = file_get_contents($apiUrl, false, $context); if ($result === false) { die('Failed to set up the webhook.'); } else { echo 'Webhook set up successfully.'; } // Handle incoming updates $input = file_get_contents("php://input"); $update = json_decode($input, true); if (isset($update['message']) && isset($update['message']['chat']['id'])) { $chatId = $update['message']['chat']['id']; if (isset($update['message']['chat_member'])) { // Handle chat_member update $chatMember = $update['message']['chat_member']; $chatMemberId = $chatMember['user']['id']; if ($chatMember['new_chat_member']) { // New member joined $welcomeMessage = "Welcome to the group! User ID: $chatMemberId"; sendMessage($botToken, $chatId, $welcomeMessage); } else { // Member left $farewellMessage = "Goodbye! User ID: $chatMemberId"; sendMessage($botToken, $chatId, $farewellMessage); } } } function sendMessage($token, $chatId, $message) { $apiUrl = "https://api.telegram.org/bot$token/sendMessage"; $data = array('chat_id' => $chatId, 'text' => $message); $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data), ), ); $context = stream_context_create($options); $result = file_get_contents($apiUrl, false, $context); if ($result === false) { echo 'Failed to send message.'; } }
I added see on $apiUrl
if (isset($update['chat_member'])) { // Handle chat_member update $chatMember = $update['chat_member']; $newChatMemberId = $chatMember['new_chat_member']['user']['id']; $newChatMemberStatus = $chatMember['new_chat_member']['status']; $oldChatMemberStatus = $chatMember['old_chat_member']['status']; if ( $newChatMemberStatus == 'member' && $oldChatMemberStatus == 'left') { // New member joined $welcomeMessage = "Welcome to the group! User ID: $newChatMemberId"; sendMessage($botToken, $chatId, $welcomeMessage); } else if ( $newChatMemberStatus == 'left' && $oldChatMemberStatus == 'member' ) { // Member left $farewellMessage = "Goodbye! User ID: $newChatMemberId"; sendMessage($botToken, $chatId, $farewellMessage); } }
Again ur code not work
😟 you should provide more debug info.
Why it's need to add old chat member status?
I just posted a solution. Debug it and fix other mistakes in your code
Because otherwise it will catch also promotion, restrictions etc.
There are multiple conditions. https://t.me/BotNews/57
Обсуждают сегодня