Last active
January 22, 2017 23:36
-
-
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
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
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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'