Skip to content

Instantly share code, notes, and snippets.

@mariocesar
Created June 13, 2017 19:52
Show Gist options
  • Save mariocesar/477f19f633973d4f4134087ce1776518 to your computer and use it in GitHub Desktop.
Save mariocesar/477f19f633973d4f4134087ce1776518 to your computer and use it in GitHub Desktop.
Send a telegram message with python requests
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