mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
parent
4aad83d60b
commit
a4b8c3cab0
@ -21,6 +21,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
REQUIREMENTS = ['python-telegram-bot==5.0.0']
|
REQUIREMENTS = ['python-telegram-bot==5.0.0']
|
||||||
|
|
||||||
ATTR_PHOTO = "photo"
|
ATTR_PHOTO = "photo"
|
||||||
|
ATTR_DOCUMENT = "document"
|
||||||
ATTR_CAPTION = "caption"
|
ATTR_CAPTION = "caption"
|
||||||
|
|
||||||
CONF_CHAT_ID = 'chat_id'
|
CONF_CHAT_ID = 'chat_id'
|
||||||
@ -102,6 +103,8 @@ class TelegramNotificationService(BaseNotificationService):
|
|||||||
return
|
return
|
||||||
elif data is not None and ATTR_LOCATION in data:
|
elif data is not None and ATTR_LOCATION in data:
|
||||||
return self.send_location(data.get(ATTR_LOCATION))
|
return self.send_location(data.get(ATTR_LOCATION))
|
||||||
|
elif data is not None and ATTR_DOCUMENT in data:
|
||||||
|
return self.send_document(data.get(ATTR_DOCUMENT))
|
||||||
|
|
||||||
# send message
|
# send message
|
||||||
try:
|
try:
|
||||||
@ -125,6 +128,20 @@ class TelegramNotificationService(BaseNotificationService):
|
|||||||
_LOGGER.exception("Error sending photo.")
|
_LOGGER.exception("Error sending photo.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def send_document(self, data):
|
||||||
|
"""Send a document."""
|
||||||
|
import telegram
|
||||||
|
caption = data.pop(ATTR_CAPTION, None)
|
||||||
|
|
||||||
|
# send photo
|
||||||
|
try:
|
||||||
|
document = load_data(**data)
|
||||||
|
self.bot.sendDocument(chat_id=self._chat_id,
|
||||||
|
document=document, caption=caption)
|
||||||
|
except telegram.error.TelegramError:
|
||||||
|
_LOGGER.exception("Error sending document.")
|
||||||
|
return
|
||||||
|
|
||||||
def send_location(self, gps):
|
def send_location(self, gps):
|
||||||
"""Send a location."""
|
"""Send a location."""
|
||||||
import telegram
|
import telegram
|
||||||
|
Loading…
x
Reference in New Issue
Block a user