0
<?php
$parameters = array(
    "chat_id" => "******",
    "text" => "Hello",
    "disable_web_page_preview" => "true",
    "parse_mode" => "Markdown"
);
send($parameters);
function send($parameters)
{
    $bot_token = "*********";
    $url = "https://api.telegram.org/bot$bot_token/sendMessage";
    if (!$ch = curl_init())
    {
        exit();
    }
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $outpot = curl_exec($ch);
    return $outpot;
}
?>

This is my code but it is not working.

I want to send some messages to the telegram bot.

Jakye
  • 6,440
  • 3
  • 19
  • 38
avm
  • 25
  • 2
  • 8
  • 1
    We cannot help you with "not working". It not working because it not working. Provide error pls. – Maksim Jul 30 '21 at 18:40
  • Welcome to SO. You'll need to tell us more about what the problem is for anyone to be able to help. Are you getting error msgs? Does your curl call work, [have you debugged it](https://stackoverflow.com/questions/3757071/php-debugging-curl)? – Don't Panic Aug 01 '21 at 09:11

1 Answers1

0

Your code looks good, although, the chat ID you're using is not correct one. You need to manually get the channel ID via bot getMessages endpoint API.

GAMELASTER
  • 1,071
  • 1
  • 12
  • 23