Get all chat IDs using the Telegram bot

The main question: how to get chat IDs for all conversations ever held with a bot?

Imagine that a bot is talking to user A.

Now I stop the bot process and start it again.

How do I get the chat id of this chat with user A?

I understand that you get the chat id when the user sends you a message and you use this id to reply, but what if user A no longer sends messages to the bot during the current execution? How to get past conversation id?

Is the only option for storing identifiers and retrieving them when starting a second run?

UPDATE:

It seems like the current solution is to keep the chat id in a safe place, as @Tick Tock replied.

+4
source share
1 answer

Your question is not clear to me, but, as I understand from your question, I wrote something to you, I hope it will be useful. You can get chat_idand use it to send something to this chat. I would give an example code, but before giving me something to explain.

There are two definitions in the Telegram Bot API: chat_idand from_id.

1 - When we are in a privatechat with some chat_idand from_idare equal.

2. group, chat_id id (from_id), - (, , - privacy_mode )

, : - , Telegram BOT ( script), "Hello chat_id" . ( PHP)

define('BOT_TOKEN','12345:abcde');//replace with your bot token
$command_prefix_url='https://api.telegram.org/bot' . BOT_TOKEN ;

$update = json_decode(file_get_contents('php://input')); //retrieves data sent by telegram

$chat_id=$update->message->chat->id; //retrives `chat_id`

$rep = json_decode(file_get_contents($command_prefix_url . '/SendMessage?chat_id=' .
    $chat_id    . '&text=' . urldecode('Hello '.(string)$chat_id))); //send something to that `chat_id` (sender)

: (- , )

-, chat_id ( ) - . , Telegram , bot WHOLE chat_id, - chat_id ( reciceve from) .

chat_id , , . chat_id , , , .

, , , - , , , , / - , /him chat_id . , / -.

+5

Source: https://habr.com/ru/post/1649704/


All Articles