mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Change PR to suggestion on gitter (#3243)
This commit is contained in:
parent
3668afe306
commit
91028cbc13
@ -24,6 +24,10 @@ REQUIREMENTS = ['python-telegram-bot==5.0.0']
|
|||||||
ATTR_PHOTO = "photo"
|
ATTR_PHOTO = "photo"
|
||||||
ATTR_DOCUMENT = "document"
|
ATTR_DOCUMENT = "document"
|
||||||
ATTR_CAPTION = "caption"
|
ATTR_CAPTION = "caption"
|
||||||
|
ATTR_URL = 'url'
|
||||||
|
ATTR_FILE = 'file'
|
||||||
|
ATTR_USERNAME = 'username'
|
||||||
|
ATTR_PASSWORD = 'password'
|
||||||
|
|
||||||
CONF_CHAT_ID = 'chat_id'
|
CONF_CHAT_ID = 'chat_id'
|
||||||
|
|
||||||
@ -105,8 +109,6 @@ class TelegramNotificationService(BaseNotificationService):
|
|||||||
elif data is not None and ATTR_DOCUMENT in data:
|
elif data is not None and ATTR_DOCUMENT in data:
|
||||||
return self.send_document(data.get(ATTR_DOCUMENT))
|
return self.send_document(data.get(ATTR_DOCUMENT))
|
||||||
|
|
||||||
text = ''
|
|
||||||
|
|
||||||
if title:
|
if title:
|
||||||
text = '{} {}'.format(title, message)
|
text = '{} {}'.format(title, message)
|
||||||
else:
|
else:
|
||||||
@ -126,11 +128,16 @@ class TelegramNotificationService(BaseNotificationService):
|
|||||||
def send_photo(self, data):
|
def send_photo(self, data):
|
||||||
"""Send a photo."""
|
"""Send a photo."""
|
||||||
import telegram
|
import telegram
|
||||||
caption = data.pop(ATTR_CAPTION, None)
|
caption = data.get(ATTR_CAPTION)
|
||||||
|
|
||||||
# send photo
|
# send photo
|
||||||
try:
|
try:
|
||||||
photo = load_data(**data)
|
photo = load_data(
|
||||||
|
url=data.get(ATTR_URL),
|
||||||
|
file=data.get(ATTR_FILE),
|
||||||
|
username=data.get(ATTR_USERNAME),
|
||||||
|
password=data.get(ATTR_PASSWORD),
|
||||||
|
)
|
||||||
self.bot.sendPhoto(chat_id=self._chat_id,
|
self.bot.sendPhoto(chat_id=self._chat_id,
|
||||||
photo=photo, caption=caption)
|
photo=photo, caption=caption)
|
||||||
except telegram.error.TelegramError:
|
except telegram.error.TelegramError:
|
||||||
@ -140,11 +147,16 @@ class TelegramNotificationService(BaseNotificationService):
|
|||||||
def send_document(self, data):
|
def send_document(self, data):
|
||||||
"""Send a document."""
|
"""Send a document."""
|
||||||
import telegram
|
import telegram
|
||||||
caption = data.pop(ATTR_CAPTION, None)
|
caption = data.get(ATTR_CAPTION)
|
||||||
|
|
||||||
# send photo
|
# send photo
|
||||||
try:
|
try:
|
||||||
document = load_data(**data)
|
document = load_data(
|
||||||
|
url=data.get(ATTR_URL),
|
||||||
|
file=data.get(ATTR_FILE),
|
||||||
|
username=data.get(ATTR_USERNAME),
|
||||||
|
password=data.get(ATTR_PASSWORD),
|
||||||
|
)
|
||||||
self.bot.sendDocument(chat_id=self._chat_id,
|
self.bot.sendDocument(chat_id=self._chat_id,
|
||||||
document=document, caption=caption)
|
document=document, caption=caption)
|
||||||
except telegram.error.TelegramError:
|
except telegram.error.TelegramError:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user