Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Esp8266 with the same Token #89

Open
garudaonekh opened this issue Sep 22, 2021 · 7 comments
Open

Multiple Esp8266 with the same Token #89

garudaonekh opened this issue Sep 22, 2021 · 7 comments

Comments

@garudaonekh
Copy link

Hi,
My purpose is to have multiple users using the same Bot(same token) and devices are assigned to different chat_id(users) rather than 1 device one Bot. This is too tedious.

I want to use the same token to manage 20+ esp8266 relay.
But it shows conflict error in getUpdates().
"error_code": 409, "description": "Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"

Is there any way to filter update based on chat_id(user_id)?

Thanks;

@shurillu
Copy link
Owner

Hi garudaonekh,
sadly you can not have the same token on multiple online bot, it is a Telegram rule: the error that you pointed out says exactly what I have just wrote.
To be more detailed, multiple bots can share the same token, BUT they MUST be online one at time (and i'm not sure if there is a timeout between).
I don't know what is your design/implementation, but you can create several bots with unique tokens and add it in a single group chat.
Every user that post a message in that group chat can reach all bots and every bot can parse the message/filter by sender's user ID the incoming messages.
Could this solve your issue?

Cheers,

Stefano

@garudaonekh
Copy link
Author

garudaonekh commented Sep 22, 2021

Ok, if I use group chat, will everyone see each other's messages? If like that, it'll be messy. Another drawback is, I heard that a user can only create 20 bots.

I just go thru Telegram API, its doc say Webhook can accept 100 concurrent connections. I don't know if this could help.

Another scenario is to use Middleware(the middle ware can communicate with device thru MQTT or socket...):

Telegram<->MiddleWare<->device A
                     <->device B
                      <->device C

But this scenario, looks complicated and I don't see any good library for me to do so.

Thanks;

@garudaonekh
Copy link
Author

garudaonekh commented Sep 22, 2021

My idea is to have 100 devices and give them to 100 users and I don't want to tell all of them that user A to use BotA, user C please use BotC and so on. I want to tell them to use the same bot.

I also have another use cases where a single user may have multiple devices. In that case, I don't want the user to manage multple different bots.

@shurillu
Copy link
Owner

mmm it's a bit complicated.

just go thru Telegram API, its doc say Webhook can accept 100 concurrent connections. I don't know if this could help.

This mean that the infrastructure (Telegram server and a single bot) can handle up to 100 concurrent connection. In other words, a single bot can virtually handle 100 unique user that are asking someting to the bot in the same time (100 connections open at time).
Take in mind that the ESP8266 library that handle the https connections can handle up to 5 different concurrent connections (if i remember well).

Anyway, if you're planning to give a device powered by an ESP8266 with a telegram bot, the user can create his own bot (token) and with WiFiManager (https://github.com/tzapu/WiFiManager) you can give the opportunity to configure the device to the user.

My idea is to have 100 devices and give them to 100 users and I don't want to tell all of them that user A to use BotA, user C please use BotC and so on. I want to tell them to use the same bot.

As I said, it is impossible to share the same token with multiple simultaneusly online bot, sorry. And this limitation cames from Telegram.
You have to rethink the architecture.
And another limitation is: two bots can't talk each other, only a "no bot account" can talk with a bot. In other words, you cant use a master bot to filter the incoming messages to others slave bots.

Hoping this can help, cheers

Stefano

@garudaonekh
Copy link
Author

garudaonekh commented Sep 28, 2021

The customer journey I want is:

a. A user will scan QR on the devices and it'll go to the Telegram bot which already created by me
b. The device is connected to the Internet thru 2g SIM GPRS. I used T-Call Sim 800L.
c. The device then will wait for its owner to register.
d. The user will then key in the unique id number written on the device in the bot chat. The new unregistered device will pick the message and see that the ID number belong to it, will register that user id as its owner.

Thus based on the this scenario, I think it's important to have a middleware software that will stand between telegram and the device. The missing part for me is the communication between the device and the middleware which I don't know what kind of technology stack to use.

What do you think?

PS: For complicated project, I will use Blynk. But for simple 4 to 8 relay projects with a few sensors, I think Telegram bot is very convenient and users are very familiar with Telegram(at least in my country)

@FarhanSakti
Copy link

Hi garudaonekh, sadly you can not have the same token on multiple online bot, it is a Telegram rule: the error that you pointed out says exactly what I have just wrote. To be more detailed, multiple bots can share the same token, BUT they MUST be online one at time (and i'm not sure if there is a timeout between). I don't know what is your design/implementation, but you can create several bots with unique tokens and add it in a single group chat. Every user that post a message in that group chat can reach all bots and every bot can parse the message/filter by sender's user ID the incoming messages. Could this solve your issue?

Cheers,

Stefano

So, is it possible that two esp32 in one group chat send data from different sensor?
I want to make system like this
System A: Sensor A > ESP32 A> telegram bot 1 > Telegram group
System B: Sensor B > ESP32 B> telegram bot 2 > Telegram group
I already try this, but there is no response from system B, only system A that can start and receive sensor data

@shurillu
Copy link
Owner

Hello FarhanSakti,

as you can se here, you can have up to 20 bots in a group chat.
Moreover, all bots can read the group chat and post masseges in the group chat.
To do that, you have to:

  1. add the bot to the chat (the "Allow groups" property of the bot must be set to enable - use Botfather);
  2. the "Group Privacy" property of the bot must be set to disable - use Botfather.

Doing these settings, all the bots added can use the chat group (read messages, post messages).

Take in mind that: bots can't chat each others! In other word, even in a chat group, bots can't read bot's messages.
Example:

  • bot1 post "message1" on a groupchat1
  • bot2 post "message2" on a groupchat1
  • user1 post "message3" on a groupchat1
    so
  • user1 see the message1 (bot1) and message2 (bot2)
  • bot1 and bot2 see only message3 from user1

I hope this explain well how bots works each others and more specific in a chat group.

Cheers,

Stefano

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants