Telegram duplicating messages

Asked

Viewed 276 times

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?

  • 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.

  • 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, 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 :(

  • @Italyloalgado can post your query? If you put inside the while and gives problem and the while is data coming from query, can be a duplicity problem with the data you take.

  • 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.

  • I did a test on Workbench and sql brings 2 results... will q is why?

  • @Itallosalgate (;

  • where does the $chatId used in the function? Is it always the same? If it is always the same, you will receive n messages on Telegram where n is equivalent to the total number of lines in Quey.

  • @Gabrielsantos $chatId is inside while, along with the $token and function call. I will test to change the function and delete that variable.

Show 5 more comments

1 answer

0

In your query, if you don’t group the die, you can have duplicate lines.

SELECT alerta.nr_celular nr_celular,
    setor.nm_setor    nm_setor,
    alerta.ds_email ds_email,
    cliente.nm_cliente nm_cliente
    FROM
    tbl_setor setor,
    tbl_setor_usuario set_usuario,
    tbl_alerta_contato alerta,
    tb_usuarios usuario,
    tbl_cliente cliente
    WHERE
    set_usuario.cd_setor = setor.cd_setor
    and cliente.cd_cliente = setor.cd_cliente
    and set_usuario.cd_usuario = alerta.cd_usuario
    and set_usuario.cd_cliente = alerta.cd_cliente
    and set_usuario.cd_setor = alerta.cd_setor
    and usuario.cd_usuario = set_usuario.cd_usuario    
    and setor.sn_alerta = 'S'
    and usuario.usr_ativo = 'S'
    AND setor.cd_cliente = $cliente (variável do login do usuário por post)
    AND setor.cd_setor = $setor (variável do login do usuário por post)
GROUP BY alerta.cd_usuario # coluna para agrupar!
  • Thank you for your reply Gabriel, but unfortunately I did not obtain satisfactory results. Keep sending duplicate messages to Telegram, the email is normal. I forgot to mention it to you. The lines that query results are distinct.

  • @Itallosalgado you can put the result of queries in your question?

  • Of course, here is the link with the image. https://prnt.sc/injh4j I censored some parts because they are private information.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.