Sending a message to the telegram channel
The last notes
Website hosting
If you are choosing hosting for your project, I recommend Timeweb. Modern infrastructure, a wide range of plans from starter options to high-load VPS, and responsive tech support that actually helps instead of sending template replies. I host some of my own projects there and recommend it to my clients.
Go to site Affiliate link. The price remains the same for you.All English-language materials have been translated fully automatically using the Google service
Get the bot token
Find a special contact in the telegram @botfarther
Sending a command to create a bot /newbot
Enter a unique name for the bot, get and save the bot token
Getting the channel id in telegrams
1. Create a channel
2. We write any message to the channel
3. Find contact @getmyid_bot
4. We forward him any message from our channel
5. Get and save the id of the user, the current chat and the desired chat. Save the value from "Forwarded from chat". Using
Sending a message to the telegram channel
function send(text){
// Токен бота и идентификатор чата
$token='';
$chat_id='';
// Отправить сообщение
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL,'https://api.telegram.org/bot'.$token.'/sendMessage');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,'chat_id='.$chat_id.'&text='.urlencode($text));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
// Настройки прокси, если это необходимо
/*
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $auth);
*/
// Отправить сообщение
$result=curl_exec($ch);
curl_close($ch);
}
Comments