Commit 0ce22464 authored by Zeitpunk's avatar Zeitpunk 💬

[F] Added sendPicture functionality

parent 88aa6241
# »» «« »» «« »» «« »» «« »» «« »» «« »» «« »» «« »» «« »» «« »» «« »» ««
# ||
# || Inspired by this:
# || https://www.codementor.io/garethdwyer/building-a-telegram-bot-using-python-part-1-goi5fncay
# ||
# «« »» «« »» «« »» «« »» «« »» «« »» «« »» «« »» «« »» «« »» «« »» «« »»
import requests
import json
import urllib
......@@ -20,6 +13,11 @@ class telefly:
response = requests.get(url)
content = response.content.decode("utf8") # .decode("utf8") for extra compatibility
return content
def postUrl(self, url, files):
response = requests.post(url, files=files)
content = response.content.decode("utf8")
return content
""" parses the JSON response (content) into a Python dictionary """
......@@ -81,28 +79,14 @@ class telefly:
reply_markup = {"keyboard":keyboard, "one_time_keyboard": True}
return json.dumps(reply_markup)
""" not implemented yet
def sendPicture(self, chat_id):
url = API + "sendPhoto?chat_id={}".format(chat_id)
filename = getPicture()
""" sends a picture to chat_id """
def sendPicture(self, chat_id, filename):
url = self.URL + "sendPhoto?chat_id={}".format(chat_id)
files = {'photo': open(filename, 'rb')}
response = requests.post(url, files=files)
content = response.content.decode("utf8")
return content
"""
self.postUrl(url, files)
# TODO: All the other methods of Telegram bots https://core.telegram.org/bots/api
# Important: forceReply, sendVideos, parseMode, (inline)Keyboards,
# reply_to_message_id, edit message ...
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