mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Allow to use data for enhanced messages (#5763)
Add notification data field to the message send to Facebook. Allows to construct richer messages like cards, quick replies, attach images, videos, etc
This commit is contained in:
parent
26a3ecc9d0
commit
4cc711357a
@ -12,7 +12,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.components.notify import (
|
from homeassistant.components.notify import (
|
||||||
ATTR_TARGET, PLATFORM_SCHEMA, BaseNotificationService)
|
ATTR_TARGET, ATTR_DATA, PLATFORM_SCHEMA, BaseNotificationService)
|
||||||
from homeassistant.const import CONTENT_TYPE_JSON
|
from homeassistant.const import CONTENT_TYPE_JSON
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -41,6 +41,15 @@ class FacebookNotificationService(BaseNotificationService):
|
|||||||
"""Send some message."""
|
"""Send some message."""
|
||||||
payload = {'access_token': self.page_access_token}
|
payload = {'access_token': self.page_access_token}
|
||||||
targets = kwargs.get(ATTR_TARGET)
|
targets = kwargs.get(ATTR_TARGET)
|
||||||
|
data = kwargs.get(ATTR_DATA)
|
||||||
|
|
||||||
|
body_message = {"text": message}
|
||||||
|
|
||||||
|
if data is not None:
|
||||||
|
body_message.update(data)
|
||||||
|
# Only one of text or attachment can be specified
|
||||||
|
if 'attachment' in body_message:
|
||||||
|
body_message.pop('text')
|
||||||
|
|
||||||
if not targets:
|
if not targets:
|
||||||
_LOGGER.error("At least 1 target is required")
|
_LOGGER.error("At least 1 target is required")
|
||||||
@ -49,7 +58,7 @@ class FacebookNotificationService(BaseNotificationService):
|
|||||||
for target in targets:
|
for target in targets:
|
||||||
body = {
|
body = {
|
||||||
"recipient": {"phone_number": target},
|
"recipient": {"phone_number": target},
|
||||||
"message": {"text": message}
|
"message": body_message
|
||||||
}
|
}
|
||||||
import json
|
import json
|
||||||
resp = requests.post(BASE_URL, data=json.dumps(body),
|
resp = requests.post(BASE_URL, data=json.dumps(body),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user