PHP telegram bot:从id.txt

时间:2018-06-13 17:54:48

标签: php bots telegram sendmessage allusersprofile

我创建了一个php电报船。在这种情况下,我将用户ID存储在id.txt文件中。

$message = $update->message;
$text1 = $message->text;
$fadmin = $message->from->id;
$baza = file_get_contents("id.txt");

$saqla2 = "$baza\n$fadmin";
file_put_contents("id.txt", $saqla2);

然后如何向每个注册用户发送消息?所以你需要向所有少数民族发送信息。

$text2 = str_replace("/xabar","",$text1);
  $response = file_get_contents("https://api.telegram.org/bot".API_KEY."/sendMessage?chat_id= //there all user id from $baza // &text=$text2");

1 个答案:

答案 0 :(得分:0)

您可以将user_ids存储在文本文件中: 例如list.txt

108926499
108926497
108926496

现在向所有用户index.php发送消息:

<?php
$apiToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

$users=file_get_contents('list.txt');
$users=explode("\n",$users);
foreach ($users as $user)
{
    if (empty($user)) continue;
    $data = [
        'chat_id' => $user,
        'text' => 'Hello world!'
    ];

    $response = file_get_contents("https://api.telegram.org/bot$apiToken/sendMessage?" . http_build_query($data) );
}