Questions tagged [php-telegram-bot]

The telegram Bots are applications that can be used via telegram chat, the interaction is via Messages. The realization of these bots with PHP simplifies the work of a developer.

It is implemented by API and HTTP-based interface has all the methods of bot telegram (https://stackoverflow.com/tags/telegram-bot/info).

A simple way of use is:

define('BOT_TOKEN', '<YOUR-TOKEN>');
define('API_URL', 'https://api.telegram.org/bot'.BOT_TOKEN.'/');
define('FILE_URL', 'https://api.telegram.org/file/bot'.BOT_TOKEN.'/');

$content = file_get_contents("php://input");
$update = json_decode($content, true);

$message = isset($update['message']) ? $update['message'] : "";
$chatId = isset($message['chat']['id']) ? $message['chat']['id'] : "";
$text = isset($message['text']) ? $message['text'] : "";

header("Content-Type: application/json");
$parameters = array('chat_id' => $chatId, "text" => 'you wrote: '.$text);
$parameters["method"] = "sendMessage";
341 questions
20
votes
1 answer

Negative chat id in log file of telegram bot

I have a Telegram bot and I save all user activity in a log file. When I checked the log file, I found a user with a negative chat ID -107606558. Is this normal?
amin roshani
  • 389
  • 4
  • 11
13
votes
2 answers

Sending animated GIFs with sendPhoto (Telegram bot)

I'm trying to send an animated GIF with sendPhoto (Telegram's Bot API) with this request: https://api.telegram.org/bot/sendPhoto?chat_id=&photo=http://i.giphy.com/13IC4LVeP5NGNi.gif That method works, as in, I get ok:true back, but…
m52go
  • 343
  • 1
  • 3
  • 14
13
votes
1 answer

How do I get the user picture/avatar using the Telegram bot chat API?

The user object has no photo_id, so is there way to get the user's avatar?
Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204
10
votes
2 answers

Prevent a Telegram bot from being added to any group or channel (allow adding it to whitelisted groups/channels)

As far as I read the Telegram Bot API's docs, Telegram do not limit the calls to your webhook callback in any way. I am creating a Telegram Bot that will be available only for groups and channels that I will whitelist. I can filter out the messages…
9
votes
1 answer

telegram inline bot - InlineQueryResultCachedPhoto does not show title and description

I'm using telegram bot api for implementing an inline bot. For sending query result to the user, I'm using answerInlineQuery method in this way. This is just an example for showing a photo that exist on telegram server to user: $results = array( …
hamed
  • 7,939
  • 15
  • 60
  • 114
9
votes
1 answer

How to get Telegram channels updates (posts) with api?

I want to get Telegram channels updates (posts) with api by php! (I am not channels admin) I am not sure can I do this with bot or not? if it is not possible how can do that with telegram api ?
SoheilYou
  • 907
  • 5
  • 23
  • 43
9
votes
1 answer

how to create link in telegram bot

I am designing a telegram bot. I want to show some links e.g. 1- wkpviana 2- vianahosting that when user click it, open http://wkpviana.net http://vianahosting.ir in browser. How I can create it in php? part of my code is:
8
votes
3 answers

Regex match Telegram username and delete whole line in PHP

I wanna match Telegram username in message text and delete entire line, I've tried this pattern but the problem is that it matches emails too: .*(@(?=.{5,64}(?:\s|$))(?![_])(?!.*[_]{2})[a-zA-Z0-9_]+(?
Ali Raghebi
  • 205
  • 2
  • 6
8
votes
1 answer

How do I get the user profile picture of someone using the Telegram bot chat API?

I'm making a basic Control Panel for managing my Bot with PHP. Basically I want to display the Profile picture / avatar of the user who is sending message to the bot. However the user object has no photo_id, so is there way to get the user's avatar?
user8454964
8
votes
2 answers

How to create inline buttons in PHP Bot Telegram

I must program in php due to company needs... but I am working with php for first time... and it's the first time I am working with telegram bot :'( In some way, before, when i ran the command /start and doWork everything worked... but now I must…
Simone
  • 2,304
  • 6
  • 30
  • 79
8
votes
2 answers

Escaping underline in telegram api when parse_mode = Markdown

How can I send this text correctly: $parameters['text'] = 'you must see [example](example.com) or contact with @exmaple_com'; if I don't use "Markdown", telegram don't show the above link if I use "Markdown", telegram can't handle underline.
mitra razmara
  • 745
  • 6
  • 10
8
votes
2 answers

How can I mention Telegram users without a username?

I want mention users even those which do not have a username. If a user has set up a username I return Hi @username as an answer but if a user does not have one I can't do that. I tried using the unique User ID e.g. @5642166 but that did not…
john
  • 81
  • 1
  • 1
  • 2
7
votes
3 answers

How much length can be of a Telegram user_id?

I am making a database in which my algorithm only accepts queries from users with telegram id length of 9. user_id: 123456789; length = user_id.length; display(length); OUTPUT: 9 Are there telegram user ids of length lesser than 9?Can anybody…
7
votes
4 answers

How to get Telegram Bot statistics?

Does exists any way to get bot's statistics with API or with web interface or with BotFather? Or I must to collect statistics by processing updates from bot API? ps. Currently I store statistics in Redis by processing updates from bot API, but I…
Nick
  • 9,735
  • 7
  • 59
  • 89
6
votes
1 answer

How to get callback_data from Telegram in PHP

I want to get callback data from response but array is empty. I am trying to show in message callback_data array. Here is my code: $botToken = "token"; $botAPI = "https://api.telegram.org/bot" . $botToken; $update =…
Akram Baratov
  • 143
  • 1
  • 3
  • 13
1
2 3
22 23