From 4cc711357ab3419f054cf44d60d9fbb8db86290c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20L=C3=B3pez?= Date: Mon, 6 Feb 2017 14:01:41 +0100 Subject: [PATCH] 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 --- homeassistant/components/notify/facebook.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/notify/facebook.py b/homeassistant/components/notify/facebook.py index e598b0e818b..8f8bb98bbe1 100644 --- a/homeassistant/components/notify/facebook.py +++ b/homeassistant/components/notify/facebook.py @@ -12,7 +12,7 @@ import voluptuous as vol import homeassistant.helpers.config_validation as cv from homeassistant.components.notify import ( - ATTR_TARGET, PLATFORM_SCHEMA, BaseNotificationService) + ATTR_TARGET, ATTR_DATA, PLATFORM_SCHEMA, BaseNotificationService) from homeassistant.const import CONTENT_TYPE_JSON _LOGGER = logging.getLogger(__name__) @@ -41,6 +41,15 @@ class FacebookNotificationService(BaseNotificationService): """Send some message.""" payload = {'access_token': self.page_access_token} 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: _LOGGER.error("At least 1 target is required") @@ -49,7 +58,7 @@ class FacebookNotificationService(BaseNotificationService): for target in targets: body = { "recipient": {"phone_number": target}, - "message": {"text": message} + "message": body_message } import json resp = requests.post(BASE_URL, data=json.dumps(body),