Skip to content

Instantly share code, notes, and snippets.

@kavehbc
Created May 27, 2020 20:58
Show Gist options
  • Save kavehbc/67ff669ff0dec5fced4a88d1c8c5e38b to your computer and use it in GitHub Desktop.
Save kavehbc/67ff669ff0dec5fced4a88d1c8c5e38b to your computer and use it in GitHub Desktop.
Python - Send a message via Telegram
import time
import requests
import urllib.parse
def sendTelegramMessage(message):
bot_token = 'API Token here'
bot_chatID = 'Chat ID here'
message = urllib.parse.query(message)
send_text = f'https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={bot_chatID}&parse_mode=Markdown&text={message}'
response = requests.get(send_text)
return response.json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment