0

I have prepared one api in php for send message to bot. Every time, I need to pass chat_id in api call. Anyone know how can i create unique chat id for send message to bot.

Thanks in advance.

Danil Pyatnitsev
  • 2,172
  • 2
  • 26
  • 39
coderexpert
  • 11
  • 1
  • 1

2 Answers2

0

According the documentation:

Bots can't initiate conversations with users. A user must either add them to a group or send them a message first. People can use telegram.me/ links or username search to find your bot.

You need to write (or user need to write) first to bot. After it, in response (that getting via webhook or getUpdates method) you can get chat_id that uses to write messages to user.

Update: If I understand your comment right, you can do that:

  1. Create somepage or modal window, that can be used to send message to support.
  2. Catch this message and send it via sendMessage method to support team.

Whom? You can manage this. I see two options:

  1. You can create a group for support team in telegram and add your bot to this group.
  2. You can store chat id's for all support's team members on your side and choice how recive message for every support request form website.
  3. When bot receive a message it goes to backend (webhook or getUpdates), and from the backend it's can be shown to enduser.
Danil Pyatnitsev
  • 2,172
  • 2
  • 26
  • 39
  • I want to use it from support in chat in my website. If any one user need to contact to support then they can send message to bot. It's not necessary that visitor will use Telegrame. – coderexpert Mar 04 '17 at 08:11
  • If support person will give to reply them How can i defer chat between two visitors? We can defer message thread using chat_id. – coderexpert Mar 06 '17 at 21:30
0

Each user's chatID is unique and therefore you can send a message from your own Telegram account to your bot and save the chatID. After that when the website user sends a message in your site you can pass that message to your bot via php and force the bot to send it to yourself using your chatID .

You don't need to communicate with the user with telegram you should just use PHP to get the message and give it to the bot for sending to yourself.

Note that bots can only send messages to people who have sent at least one message to them before.

Naser.Sadeghi
  • 1,341
  • 1
  • 12
  • 35
  • How can i get my chatID? – coderexpert Mar 06 '17 at 21:29
  • I'm not familiar with telegram-bot in PHP, but in C# all you need to do is: tap start in your bot and then using the `long chatID = update.Message.Chat.Id;` you can find the chatID of the user who has sent the current update(/start) to the bot. In this case the user is yourself and you'll get your own chatID. – Naser.Sadeghi Mar 07 '17 at 11:19
  • @coderexpert I searched for its PHP command and I think this will fix your issue: `$update->message->chat->id` – Naser.Sadeghi Mar 07 '17 at 11:22