Skip to content

Instantly share code, notes, and snippets.

@checco
Last active January 22, 2017 23:36
Show Gist options
  • Save checco/c0b4ddc1508a60f5452d to your computer and use it in GitHub Desktop.
Save checco/c0b4ddc1508a60f5452d to your computer and use it in GitHub Desktop.
Python 3 script which permit to your bot to send messages in a group chat or a single person
#!/usr/bin/env python3
import urllib3
import certifi
import sys
# Generate a bot ID here: https://core.telegram.org/bots#botfather
bot_id = ''
chat_id = ''
if len(sys.argv) > 1:
message = ''
for word in sys.argv[1:]:
message = message + ' ' + word
else:
print('Sir, Where is the message?')
print('./send-telegram-py write something')
sys.exit()
try:
https = urllib3.PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=certifi.where())
r = https.request('GET', 'https://api.telegram.org/bot'
+ bot_id + '/sendMessage?chat_id='
+ chat_id + '&text=' + message)
except urllib3.exceptions.SSLError as err:
print('[ERROR] Telegram SSL error', err)
sys.exit()
@checco
Copy link
Author

checco commented Mar 10, 2016

Telegram Bot
First of all, you have to create a Bot and it's really simple: click here for the BotFather

Get a chat ID
Add your bot to a chat group and get updates of the bot for seeing the chatID, witht: 'https://api.telegram.org/bot' + bot_id + '/getUpdates'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment