1

I want to say to clients to start my chat bot and send me username and password, then I store chat_id of them, and use it whenever I want to send a message to one of them.

Is it possible? or chat_id will be expire?

Daniyal
  • 99
  • 2
  • 12

3 Answers3

1

If the chat_id is the same as the Telegram user_id for that client, then yes you can.

SendMessage:

chat_id  [Required]  [Integer]  Unique identifier for the target chat   
text     [Required]  [String]  Text of the message to be sent
Charles Okwuagwu
  • 10,538
  • 16
  • 87
  • 157
  • No, it's not same, any other idea? – Daniyal Nov 19 '16 at 07:16
  • "I want to say to clients to start my chat bot and send me username and password" ... Once the clients starts your bot, your will receive an Update, that update contains a message field. The message has a **from** --> User object and a **chat** --> Chat object. If your clients are starting your bot in private mode (not from groups) then the chat_id == user_id – Charles Okwuagwu Nov 19 '16 at 07:41
1

If you want to identify each user with a unique constant you can use user_id.

user_id: User identifier in Telegram.
chat_id: Unique identifier for the target chat.

user_id and chat_id wil never expire or change on Telegram. But a user may use your bot from a private chat or from a group. You may get two different values from the same user. So i suggest you to use user_id to do that.

aleix
  • 277
  • 5
  • 13
1

When a user register on telegram, server choose a unique chat_id for that user! it means the server do this automatically. thus if the user send /start message to your bot for the first time, this chat_id will store on bot database (if you code webhook which demonstrates users statastics)

The answer is if the user doesnt blocked your bot you can successfully send him/her a message. on the other hand if the user had delete accounted no ways suggest for send message to new chat id!

i hope you got it

Cruwl
  • 33
  • 1
  • 4