【问题标题】:PHP - Bot Telegram sends message to Channel and Reply in the ChatPHP - Bot Telegram 向频道发送消息并在聊天中回复
【发布时间】:2021-04-06 15:22:07
【问题描述】:

我的 PHP 脚本 - 有一个 Github 库(链接在最后),正在与 Telegram Bot 通信,但这个 Bot 向频道和频道聊天发送消息。

$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));

我希望机器人只向频道发送消息,并停止在该频道的聊天中复制自己。

他不属于聊天,只属于频道。

我不明白他为什么回复这个消息..

https://github.com/tg-bot-api/bot-api-base

【问题讨论】:

  • 所以您不希望频道的任何回复?
  • @AbsoluteBeginner 我希望他将消息发送到频道,就像他正在做的那样.. 问题是他也将消息发送到频道聊天,也就是说,他发送了一个副本并在那里总是两个通知(一个在频道上,一个在频道的聊天中)。

标签: php telegram telegram-bot


【解决方案1】:

您可以使用以下函数(无需库):

<?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)。

【讨论】:

猜你喜欢
  • 2022-12-21
  • 2017-10-03
  • 2015-12-01
  • 2013-02-27
  • 2021-06-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-10
相关资源
最近更新 更多