How we should send query to Telegram bot API?

馋奶兔 提交于 2019-12-02 19:25:39

You just send a POST request to:

https://api.telegram.org/bot{token}/{method}

For example:

https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/sendMessage

In the body of the request, you URL encode the parameters:

chat_id=12345&text=hello%20friend

For example, in Python using the requests module:

import requests

response = requests.post(
    url='https://api.telegram.org/bot{0}/{1}'.format(token, method),
    data={'chat_id': 12345, 'text': 'hello friend'}
).json()

When a user chats with your bot, you get a Message object that has a chat id (and a user id, which you can substitute for a chat id). There's no way to initiate a chat with a user unless you already know their user id, so you have to wait for a user to talk to you. You can simplify that by using deep linking and having the user click on a link that sends a pre-made message when they hit the Start button.

Kunwar Shekhar Singh

Try this

https://api.telegram.org/bot{token}/sendMessage?chat_id=<chat_id>&text=<Enter your text here>

Example

https://api.telegram.org/bot449123456:AAHSAnSGDm8PW2Z-1ZiwdVDmgv7sM3NMTxg/sendMessage?chat_id=311911234&text=Hi+Everyone
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!