How to identify from which telegram bot request came?
Question:
I want to create two telegram bots
on one
adress https://example.com
this is working with webhooks, but i can’t identify from which bot request came.
This is what i recieve from bot 1
:
{
"update_id": 610779399,
"message": {
"message_id": 58,
"from": {
"id": 299470913,
"is_bot": false,
"first_name": "my_first_name",
"last_name": "my_last_name",
"username": "my_user_name",
"language_code": "en"
},
"chat": {
"id": 299470913,
"first_name": "my_first_name",
"last_name": "my_last_name",
"username": "my_user_name",
"type": "private"
},
"date": 1664720338,
"text": "this message is from bot 1"
}
}
This is what i recieve from Bot 2
:
{
"update_id": 66917787,
"message": {
"message_id": 37910,
"from": {
"id": 299470913,
"is_bot": false,
"first_name": "my_first_name",
"last_name": "my_last_name",
"username": "my_user_name",
"language_code": "en"
},
"chat": {
"id": 299470913,
"first_name": "my_first_name",
"last_name": "my_last_name",
"username": "my_user_name",
"type": "private"
},
"date": 1664720333,
"text": "this is from bot 2"
}
}
Responses looks identical, is it even possible to identify from which bot request came
?
Answers:
When setting up the webhook using setWebhook API method, you can set secret_token
parameter, which will specify value of X-Telegram-Bot-Api-Secret-Token
header in every request sent to your webhook.
Secret token is usually used for security purposes, to make sure that the requests sent to your webhook are really coming from Telegram (and not from some malicious actor). If you use different secret tokens for two different bots, you can also use these tokens to specify from which bot the request was sent.
I want to create two telegram bots
on one
adress https://example.com
this is working with webhooks, but i can’t identify from which bot request came.
This is what i recieve from bot 1
:
{
"update_id": 610779399,
"message": {
"message_id": 58,
"from": {
"id": 299470913,
"is_bot": false,
"first_name": "my_first_name",
"last_name": "my_last_name",
"username": "my_user_name",
"language_code": "en"
},
"chat": {
"id": 299470913,
"first_name": "my_first_name",
"last_name": "my_last_name",
"username": "my_user_name",
"type": "private"
},
"date": 1664720338,
"text": "this message is from bot 1"
}
}
This is what i recieve from Bot 2
:
{
"update_id": 66917787,
"message": {
"message_id": 37910,
"from": {
"id": 299470913,
"is_bot": false,
"first_name": "my_first_name",
"last_name": "my_last_name",
"username": "my_user_name",
"language_code": "en"
},
"chat": {
"id": 299470913,
"first_name": "my_first_name",
"last_name": "my_last_name",
"username": "my_user_name",
"type": "private"
},
"date": 1664720333,
"text": "this is from bot 2"
}
}
Responses looks identical, is it even possible to identify from which bot request came
?
When setting up the webhook using setWebhook API method, you can set secret_token
parameter, which will specify value of X-Telegram-Bot-Api-Secret-Token
header in every request sent to your webhook.
Secret token is usually used for security purposes, to make sure that the requests sent to your webhook are really coming from Telegram (and not from some malicious actor). If you use different secret tokens for two different bots, you can also use these tokens to specify from which bot the request was sent.