Send and Receive Messages with the Telegram API

curl https://api.telegram.org/bot{YOUR_API_KEY_HERE}/getUpdates
>>> import requests
>>> token = {YOUR_API_KEY_HERE}
>>> url = f'https://api.telegram.org/bot{token}/getUpdates'
>>> requests.post(url).json()
{"ok":true,"result":[{"update_id":12671344,
"message":{"message_id":30,"from":{"id":{YOUR_ID},"is_bot":false,"first_name": "{YOUR_NAME}"
,"username":"{YOUR_USERNAME}","language_code":"en"},"chat":{"id":{YOUR_CHAT_ID},"first_name":"{YOUR_FIRST_NAME}","username":"{YOUR_USERNAME}","type":"private"},"date":1560719493,"text":"{YOUR_SENT_MESSAGE}"}}]}
{“ok”:true,”result”:[]}
curl -d chat_id={YOUR_CHAT_ID} -d text="test msg from curl"  https://api.telegram.org/bot{YOUR_API_KEY_HERE}/sendMessage
>>> import requests
>>> token = {YOUR_API_KEY_HERE}
>>> url = f'https://api.telegram.org/bot{token}/sendMessage'
>>> data = {'chat_id': {YOUR_CHAT_ID}, 'text': 'python msg'}
>>> requests.post(url, data).json()

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store