S
S
Sergey Zhuzhgov2022-02-20 20:09:51
PHP
Sergey Zhuzhgov, 2022-02-20 20:09:51

Why doesn't sending a message to telegram work?

Hello. Tell me, please, what could be the reason?

There is a function for sending a message to telegram:

function bs_tg($tgam) {
  
  $ch = curl_init();
    curl_setopt_array(
        $ch,
        array(
            CURLOPT_URL => 'https://api.telegram.org/bot' . TELEGRAM_TOKEN . '/sendMessage',
            CURLOPT_POST => TRUE,
            CURLOPT_RETURNTRANSFER => TRUE,
            CURLOPT_TIMEOUT => 10,
            CURLOPT_POSTFIELDS => array(
                'chat_id' => TELEGRAM_CHATID,
                'text' => $tgam,
            ),
        )
    );
    curl_exec($ch);
  
}


I call it with a function
$tempbody = implode(",
",array_values($massiv));

bs_tg($tempbody);


If I put "array_values" - nothing works.
If I put "array_keys" - it works, but sends the keys.

What could be the reason?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rst0, 2022-02-21
@Rst0

function bs_tg($tgam) {
  
  $ch = curl_init();
   $opt = array(
            CURLOPT_URL => 'https://api.telegram.org/bot' . TELEGRAM_TOKEN . '/sendMessage',
            CURLOPT_POST => TRUE,
            CURLOPT_RETURNTRANSFER => TRUE,
            CURLOPT_TIMEOUT => 10,
            CURLOPT_POSTFIELDS => array(
                'chat_id' => TELEGRAM_CHATID,
                'text' => $tgam,
            );
    
curl_setopt_array($ch, $opt);
    curl_exec($ch);
   curl_close($ch);
  
}
$tempbody = is_array($massiv)  ?  implode(',' , $massiv)  :  $massiv ;

bs_tg($tempbody);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question