php 如何通过php向公共电报频道发送消息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34588463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to send a message to a public Telegram channel by php?
提问by user3416269
Is it possible to send a message to a public Telegram channel by API as admin? I mean is it possible to send e.g. a video to a public Telegram channel by using e.g. php?
是否可以以管理员身份通过 API 向公共 Telegram 频道发送消息?我的意思是可以使用例如 php 将视频发送到公共电报频道吗?
回答by Saeid Tahmuresi
You can create a telegram bot and add it to your channel as admin. Then use @yourchannel as chat_id in your telegram bot for sending messages to your channel. As an example in php:
您可以创建一个电报机器人并将其以管理员身份添加到您的频道。然后在您的电报机器人中使用 @yourchannel 作为 chat_id 向您的频道发送消息。以php为例:
<?php
$botToken = "yourbottoken";
$chat_id = "@yourchannel";
$message = "your message";
$bot_url = "https://api.telegram.org/bot$botToken/";
$url = $bot_url."sendMessage?chat_id=".$chat_id."&text=".urlencode($message);
file_get_contents($url);
?>