M
M
mr_good_cat2021-05-04 16:10:19
Web development
mr_good_cat, 2021-05-04 16:10:19

How to send a message to a bot in telegram via url?

Everywhere they write about how to send a message through the bot. I need, knowing the token, to send a request with the text to the bot,

upd: I understand what my problem is. I don't know what to enter in the chat_id= field. When you enter a bot id, it says 'bot can't send messages to bots'. When requesting from the bot, it returns my id to me and then, when I enter the url, I send messages through the bot to myself.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
etozhesano, 2021-05-04
@etozhesano

https://api.telegram.org/bot " + $token + "/sendMessage?chat_id=" + $chat_id + "&text=" + $text
Instead of highlighted bold ones, insert the appropriate value.
Well, pluses and spaces are not necessary, respectively , I just pulled out a line from the script.

E
Eduard Shkuta, 2021-05-04
@dyus1

You need to send a request to the address https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/se... and specify the following data in the parameters: chat_id=direct chat id, text=message itself
Example

S
shurshur, 2021-05-04
@shurshur

Yes, everything is written correctly in upd, you must first get the chat_id. This can be done by sending any message to the bot, and then using the .../getUpdates call to get it. The message will contain the desired chat_id. Then you can send messages to this chat_id. If this is all in order to simply send notifications to yourself in telegrams, then you don’t need to keep a constantly running bot, just pull sendMessage if necessary.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question