2 years ago
#19781
Diyorbek Turgunboyev
My telegram bot sends message again and again while I will start sending message to members
My telegram bot sends message again and again while I will start sending message to members, if members' count more than 500.
I am using this code for sending message:
<?php
define('API_KEY',"[*API_TOKEN*]");
function bot($method,$datas=[]){
$url = "https://api.telegram.org/bot".API_KEY."/".$method;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$datas);
$res = curl_exec($ch);
if(curl_error($ch)){
var_dump(curl_error($ch));
}else{
return json_decode($res);
}
}
}
$member = file_get_contents("members.json");
$js = json_decode($member);
if(is_object($js)){
$js = get_object_vars($js);
}
foreach($js as $mem){
bot('sendMessage',[
'chat_id'=>$mem,
'text'=>"Message text to send"
]);
}
?>
How I can fix this bug?
php
telegram-bot
sendmessage
codebug
0 Answers
Your Answer