1 """Facebook platform for notify component."""
3 from __future__
import annotations
5 from http
import HTTPStatus
10 import voluptuous
as vol
15 PLATFORM_SCHEMA
as NOTIFY_PLATFORM_SCHEMA,
16 BaseNotificationService,
23 _LOGGER = logging.getLogger(__name__)
25 CONF_PAGE_ACCESS_TOKEN =
"page_access_token"
26 BASE_URL =
"https://graph.facebook.com/v2.6/me/messages"
28 PLATFORM_SCHEMA = NOTIFY_PLATFORM_SCHEMA.extend(
29 {vol.Required(CONF_PAGE_ACCESS_TOKEN): cv.string}
36 discovery_info: DiscoveryInfoType |
None =
None,
37 ) -> FacebookNotificationService:
38 """Get the Facebook notification service."""
43 """Implementation of a notification service for the Facebook service."""
46 """Initialize the service."""
50 """Send some message."""
52 targets = kwargs.get(ATTR_TARGET)
53 data = kwargs.get(ATTR_DATA)
55 body_message = {
"text": message}
58 body_message.update(data)
60 if "attachment" in body_message:
61 body_message.pop(
"text")
64 _LOGGER.error(
"At least 1 target is required")
67 for target
in targets:
70 if target.startswith(
"+"):
71 recipient = {
"phone_number": target}
73 recipient = {
"id": target}
76 "recipient": recipient,
77 "message": body_message,
78 "messaging_type":
"MESSAGE_TAG",
79 "tag":
"ACCOUNT_UPDATE",
83 data=json.dumps(body),
85 headers={
"Content-Type": CONTENT_TYPE_JSON},
88 if resp.status_code != HTTPStatus.OK:
93 """Log error message."""
95 error_message = obj[
"error"][
"message"]
96 error_code = obj[
"error"][
"code"]
99 "Error %s : %s (Code %s)", response.status_code, error_message, error_code
def __init__(self, access_token)
def send_message(self, message="", **kwargs)
FacebookNotificationService get_service(HomeAssistant hass, ConfigType config, DiscoveryInfoType|None discovery_info=None)