Your question is unclear to me but as I understand from your question I wrote something to you hope be helpful. You can retrieve chat_id
s and use it to send something to that chat
. I would give a sample code but before let me explain something.
In Telegram Bot API there is two definitions: chat_id
and from_id
.
1-When we are in private
chat with some one chat_id
and from_id
are equal.
2-When our bot is a group
member, then chat_id
is id of that group and is different from that person id(from_id
) may be send something to group(and maybe our bot receive it too-when privacy_mode
is off)
I assume your bot is in private chat:
when user sends anything to your bot, then Telegram gives that message to your BOT( calls your script), this sample code sends "Hello chat_id" to that user.(in 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)
UPDATED: (due to edition in question)
First, chat_id
is unique and always permanent for that user(in private chats)
even if your bot's user leaves your bot and rejoin again.
I don't hear or read anything up to now that Telegram have been provided a method to tell your bot
WHOLE its users chat_id
, so the best way to know about your users is to save their chat_id
and other info (that you gather along the time from user from messages reciceve from) in a database.
If you save at least their chat_id
in a simple database then you have a list of your bot's subscribed users. And since chat_id
is permanent you can send anything you want to your users.
AND, as I understand from your question, IF you do not have a database but user A is your bot's subscribed user, AS I KNOW, you should wait until she/he send a single message to you, then you grab her/him chat_id
and add it to your database. NOW you can send her/him every time anything.