PHP - Bot Telegram 向频道发送消息并在聊天中回复
PHP - Bot Telegram sends message to Channel and Reply in the Chat
我的 PHP 脚本 - 它有一个 Github 库(最后是 link),正在与 Telegram Bot 通信,但是这个 Bot 向 Channel 和频道聊天。
$canalID= "@xxx";
$botKey = "xx:xxxx-yyy";
$requestFactory = new Http\Factory\Guzzle\RequestFactory();
$streamFactory = new Http\Factory\Guzzle\StreamFactory();
$client = new Http\Adapter\Guzzle6\Client();
$apiClient = new \TgBotApi\BotApiBase\ApiClient($requestFactory, $streamFactory, $client);
$bot = new \TgBotApi\BotApiBase\BotApi($botKey, $apiClient, new \TgBotApi\BotApiBase\BotApiNormalizer());
$text = "Olá";
$arr = ["parseMode" => "HTML"];
$bot->send(\TgBotApi\BotApiBase\Method\SendMessageMethod::create($canalID, $text, $arr));
我希望机器人只向频道发送消息,并停止在该频道的聊天中复制自己。
他不属于聊天,只属于频道。
我不明白他为什么回信息..
您可以使用以下函数(不需要库):
<?php
tg("Olá");
function tg($text) {
$data = ['chat_id' => '@xxx', 'disable_web_page_preview' => true, 'parse_mode' => 'HTML', 'text' => $text];
file_get_contents('https://api.telegram.org/xx:xxxx-yyy/sendMessage?'.http_build_query($data));
}
替换:
- @xxx (chat_id);
- xx:xxxx-yyy (botKey).
我的 PHP 脚本 - 它有一个 Github 库(最后是 link),正在与 Telegram Bot 通信,但是这个 Bot 向 Channel 和频道聊天。
$canalID= "@xxx";
$botKey = "xx:xxxx-yyy";
$requestFactory = new Http\Factory\Guzzle\RequestFactory();
$streamFactory = new Http\Factory\Guzzle\StreamFactory();
$client = new Http\Adapter\Guzzle6\Client();
$apiClient = new \TgBotApi\BotApiBase\ApiClient($requestFactory, $streamFactory, $client);
$bot = new \TgBotApi\BotApiBase\BotApi($botKey, $apiClient, new \TgBotApi\BotApiBase\BotApiNormalizer());
$text = "Olá";
$arr = ["parseMode" => "HTML"];
$bot->send(\TgBotApi\BotApiBase\Method\SendMessageMethod::create($canalID, $text, $arr));
我希望机器人只向频道发送消息,并停止在该频道的聊天中复制自己。
他不属于聊天,只属于频道。
我不明白他为什么回信息..
您可以使用以下函数(不需要库):
<?php
tg("Olá");
function tg($text) {
$data = ['chat_id' => '@xxx', 'disable_web_page_preview' => true, 'parse_mode' => 'HTML', 'text' => $text];
file_get_contents('https://api.telegram.org/xx:xxxx-yyy/sendMessage?'.http_build_query($data));
}
替换:
- @xxx (chat_id);
- xx:xxxx-yyy (botKey).