0
I’m facing a problem with a Telegram API encryption. It is working normally sending messages, but all are coming duplicated, which can be?
Follows function:
function sendMessage($chatID, $messaggio, $token) {
$url = "https://api.telegram.org/" . $token . "/sendMessage?chat_id=" . $chatID;
$url = $url . "&text=" . urlencode($messaggio);
$ch = curl_init();
$optArray = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($ch, $optArray);
$result = curl_exec($ch);
curl_close($ch);
Still call:
$token = "bot******************";
$chatid = "***********";
sendMessage($chatid,"mensagem aqui!", $token);
I read something about offset, but I don’t know how to start implementing it in the code... If anyone can help me, I’m grateful!
----update--- Follow while from fatch_assoc where there is the mailing + sendMessage function
$result_alerta = mysql_query( $query_alerta );
while ( $row_alerta = mysql_fetch_assoc( $result_alerta ) )
{ funções aqui }
----update--- follows query result https://prnt.sc/injh4j
where the call is made from
sendMessage
? The problem could be out of function, in the place that is calling her?– Gabriel Santos
Hello Gabriel, it is done inside a fetch_assoc While, just below the creation of the loop. Below has the function of sending email q works right, sends 1 single.
– Ítalo Salgado
See if you have anything related to this problem: https://answall.com/questions/198459/meu-bot-no-telegram-est%C3%a1-loop-in-messages
– RpgBoss
Rpgboss, thanks for the link, but I’ve already taken a look, the user’s problem is different, his bot loop if the user responds, unlike mine, which has no interaction at all, from the impression that the function is called 2x... I did a test here and when I put the function inside the while it sends the 2 messages in a row, but when it’s fucked, only inside the if, it sends the message correctly. Gives the impression that the loop is doing this with the function... I don’t know what can be :(
– Ítalo Salgado
@Italyloalgado can post your query? If you put inside the
while
and gives problem and thewhile
is data coming from query, can be a duplicity problem with the data you take.– Gabriel Santos
Hi @Gabrielsantos sorry for the delay. Unfortunately my query is a bit large, so I put it in a folder... Follow link https://pastebin.com/g48MHtrn If not, please advise.
– Ítalo Salgado
I did a test on Workbench and sql brings 2 results... will q is why?
– Ítalo Salgado
@Itallosalgate (;
– Gabriel Santos
where does the
$chatId
used in the function? Is it always the same? If it is always the same, you will receiven
messages on Telegram wheren
is equivalent to the total number of lines in Quey.– Gabriel Santos
@Gabrielsantos $chatId is inside while, along with the $token and function call. I will test to change the function and delete that variable.
– Ítalo Salgado