Commit 2d9c8100 authored by Zeitpunk's avatar Zeitpunk 💬

[F] Added File and Document features

parent 73358e0c
......@@ -11,7 +11,7 @@ requires = [
setuptools.setup(
name="telefly",
version="0.1.1",
version="0.1.3",
author="Zeitpunk",
author_email="ztpnk@mailbox.org",
description="Create Telegram bots in Python.",
......
......@@ -6,6 +6,7 @@ import urllib
class telefly:
def __init__(self, token):
self.URL = "https://api.telegram.org/bot{}/".format(token)
self.fileURL = "https://api.telegram.org/file/bot{}/".format(token)
""" downloads the content from a URL and gives us a string """
......@@ -84,6 +85,20 @@ class telefly:
url = self.URL + "sendPhoto?chat_id={}".format(chat_id)
files = {'photo': open(filename, 'rb')}
self.postUrl(url, files)
def sendDocument(self, chat_id, filename):
url = self.URL + "sendDocument?chat_id={}".format(chat_id)
files = {'document': open(filename, 'rb')}
self.postUrl(url, files)
def getFile(self, fileID):
url = self.URL + "getFile?file_id={}".format(fileID)
js = self.getJson(url)
return js["result"]["file_path"]
def getFileUrl(self, fileID):
filePath = self.getFile(fileID)
return self.fileURL + "{}".format(filePath)
# TODO: All the other methods of Telegram bots https://core.telegram.org/bots/api
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment