Reputation: 23
I need a simple bot to send message via telegram. I use this php code for the reason:
header('Content-Type: text/html; charset=utf-8');
$message= file_get_contents("php://input");
$arrayMessage= json_decode($message, true);
$token= "*********";
$chat_id= $arrayMessage['message']['from']['id'];
$command= $arrayMessage['message']['text'];
if($command == '/start'){
$text= "Hello";
$url= "https://api.telegram.org/bot".$token."/sendMessage?chat_id=".$chat_id."&text=".$text;
file_put_contents("message.txt", $url);
//file_get_contents ($url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
}
any suggestion?
i use cloudflare for ssl certificate and the webhook method is initiated.
Upvotes: 0
Views: 1462
Reputation: 2213
Maybe you need to add
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
and other debugging code to find the error as follows:
var_dump ( curl_getinfo ( $ch ) );
if (curl_errno ( $ch )) {
print curl_error ( $ch );
} else {
curl_close ( $ch );
}
Upvotes: 1