Ale
Ale

Reputation: 113

PHP - Bot Telegram sends message to Channel and Reply in the Chat

My PHP Script - which has a Github library (link at the end), is communicating with a Telegram Bot, but this Bot sends messages to both the Channel and the Channel Chat.

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

I would like the robot to just send messages to the Channel, and stop replicating itself in the Chat of that Channel.

He does not belong to the Chat, only to the Channel.

I don't understand why he replies the message ..

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

Upvotes: 1

Views: 1452

Answers (1)

AbsoluteBeginner
AbsoluteBeginner

Reputation: 2255

You can use the following function (no library needed):

<?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));
}

Replace:

  • @xxx (chat_id);
  • xx:xxxx-yyy (botKey).

Upvotes: 2

Related Questions