Created
June 13, 2017 19:52
-
-
Save mariocesar/477f19f633973d4f4134087ce1776518 to your computer and use it in GitHub Desktop.
Send a telegram message with python requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
api_url = 'https://api.telegram.org/bot{token}/{method}'.format | |
TELEGRAM_ACCESS_TOKEN = os.environ.get('TELEGRAM_ACCESS_TOKEN', None) | |
def telegram_command(name, data): | |
url = api_url(token=TELEGRAM_ACCESS_TOKEN, method=name) | |
return requests.post(url=url, json=data) | |
def telegram_sendMessage(text: str, chat_id: str, notify=True): | |
return telegram_command('sendMessage', { | |
'text': text, | |
'chat_id': chat_id, | |
'parse_mode': 'markdown', | |
'disable_notification': not notify}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment