Created
March 19, 2019 05:07
-
-
Save atareao/4459e870129319b0b3e4191e6b5de0d8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 requests | |
import sys | |
import os | |
TOKEN = '123456789:Ab1Cd2Ef3Gh4Ij5Kl6Mn7Op8Qr9sTuVwXyZ' | |
def sendMessage(chat_id, text): | |
requests.post( | |
'https://api.telegram.org/bot{0}/{1}'.format(TOKEN, 'sendMessage'), | |
data={'chat_id': chat_id, 'text': text}) | |
def sendPhoto(chat_id, url, caption=''): | |
requests.post( | |
'https://api.telegram.org/bot{0}/{1}'.format(TOKEN, 'sendPhoto'), | |
data={'chat_id': chat_id, 'photo': url, 'caption': caption}) | |
def sendPhoto2(chat_id, afile, caption=''): | |
requests.post( | |
'https://api.telegram.org/bot{0}/{1}'.format(TOKEN, 'sendPhoto'), | |
files={'photo': (afile, open(afile, 'rb'))}, | |
data={'chat_id': chat_id, 'caption': caption}) | |
def sendPhoto3(chat_id, photo): | |
if(os.path.exists(photo)): | |
sendPhoto2(chat_id, photo) | |
else: | |
sendPhoto(chat_id, photo) | |
def sendAudio(chat_id, afile, caption=''): | |
requests.post( | |
'https://api.telegram.org/bot{0}/{1}'.format(TOKEN, 'sendAudio'), | |
files={'audio': (afile, open(afile, 'rb'))}, | |
data={'chat_id': chat_id, 'caption': caption}) | |
def sendVoice(chat_id, afile, caption=''): | |
requests.post( | |
'https://api.telegram.org/bot{0}/{1}'.format(TOKEN, 'sendVoice'), | |
files={'voice': (afile, open(afile, 'rb'))}, | |
data={'chat_id': chat_id, 'caption': caption}) | |
def sendLocation(chat_id, latitude, longitude): | |
requests.post( | |
'https://api.telegram.org/bot{0}/{1}'.format(TOKEN, 'sendLocation'), | |
data={'chat_id': chat_id, 'latitude': latitude, 'longitude': longitude}) | |
def sendContact(chat_id, phone_number, first_name, last_name=''): | |
requests.post( | |
'https://api.telegram.org/bot{0}/{1}'.format(TOKEN, 'sendContact'), | |
data={'chat_id': chat_id, 'phone_number': phone_number, | |
'first_name': first_name, 'last_name': last_name}) | |
def kickChatMember(chat_id, user_id): | |
requests.post( | |
'https://api.telegram.org/bot{0}/{1}'.format(TOKEN, 'kickChatMember'), | |
data={'chat_id': chat_id, 'user_id': user_id}) | |
if __name__ == '__main__': | |
if len(sys.argv) > 2: | |
sendMessage(sys.argv[1], sys.argv[2]) | |
# sendLocation(sys.argv[1], 39.4697495, -0.37739) | |
sendContact(sys.argv[1], '+34123456789', 'Perico', 'Palotes') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cuidado con el tocken.