mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Remove facebook broadcast api (#32517)
* Remove facebook broadcast api * Update notify.py * Revert API Version change
This commit is contained in:
parent
aed15761de
commit
11eee43fc7
@ -19,8 +19,6 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
CONF_PAGE_ACCESS_TOKEN = "page_access_token"
|
CONF_PAGE_ACCESS_TOKEN = "page_access_token"
|
||||||
BASE_URL = "https://graph.facebook.com/v2.6/me/messages"
|
BASE_URL = "https://graph.facebook.com/v2.6/me/messages"
|
||||||
CREATE_BROADCAST_URL = "https://graph.facebook.com/v2.11/me/message_creatives"
|
|
||||||
SEND_BROADCAST_URL = "https://graph.facebook.com/v2.11/me/broadcast_messages"
|
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||||
{vol.Required(CONF_PAGE_ACCESS_TOKEN): cv.string}
|
{vol.Required(CONF_PAGE_ACCESS_TOKEN): cv.string}
|
||||||
@ -57,29 +55,23 @@ class FacebookNotificationService(BaseNotificationService):
|
|||||||
_LOGGER.error("At least 1 target is required")
|
_LOGGER.error("At least 1 target is required")
|
||||||
return
|
return
|
||||||
|
|
||||||
# broadcast message
|
for target in targets:
|
||||||
if targets[0].lower() == "broadcast":
|
# If the target starts with a "+", it's a phone number,
|
||||||
broadcast_create_body = {"messages": [body_message]}
|
# otherwise it's a user id.
|
||||||
_LOGGER.debug("Broadcast body %s : ", broadcast_create_body)
|
if target.startswith("+"):
|
||||||
|
recipient = {"phone_number": target}
|
||||||
|
else:
|
||||||
|
recipient = {"id": target}
|
||||||
|
|
||||||
resp = requests.post(
|
body = {
|
||||||
CREATE_BROADCAST_URL,
|
"recipient": recipient,
|
||||||
data=json.dumps(broadcast_create_body),
|
"message": body_message,
|
||||||
params=payload,
|
"messaging_type": "MESSAGE_TAG",
|
||||||
headers={CONTENT_TYPE: CONTENT_TYPE_JSON},
|
"tag": "ACCOUNT_UPDATE",
|
||||||
timeout=10,
|
|
||||||
)
|
|
||||||
_LOGGER.debug("FB Messager broadcast id %s : ", resp.json())
|
|
||||||
|
|
||||||
# at this point we get broadcast id
|
|
||||||
broadcast_body = {
|
|
||||||
"message_creative_id": resp.json().get("message_creative_id"),
|
|
||||||
"notification_type": "REGULAR",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = requests.post(
|
resp = requests.post(
|
||||||
SEND_BROADCAST_URL,
|
BASE_URL,
|
||||||
data=json.dumps(broadcast_body),
|
data=json.dumps(body),
|
||||||
params=payload,
|
params=payload,
|
||||||
headers={CONTENT_TYPE: CONTENT_TYPE_JSON},
|
headers={CONTENT_TYPE: CONTENT_TYPE_JSON},
|
||||||
timeout=10,
|
timeout=10,
|
||||||
@ -87,32 +79,6 @@ class FacebookNotificationService(BaseNotificationService):
|
|||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
log_error(resp)
|
log_error(resp)
|
||||||
|
|
||||||
# non-broadcast message
|
|
||||||
else:
|
|
||||||
for target in targets:
|
|
||||||
# If the target starts with a "+", it's a phone number,
|
|
||||||
# otherwise it's a user id.
|
|
||||||
if target.startswith("+"):
|
|
||||||
recipient = {"phone_number": target}
|
|
||||||
else:
|
|
||||||
recipient = {"id": target}
|
|
||||||
|
|
||||||
body = {
|
|
||||||
"recipient": recipient,
|
|
||||||
"message": body_message,
|
|
||||||
"messaging_type": "MESSAGE_TAG",
|
|
||||||
"tag": "ACCOUNT_UPDATE",
|
|
||||||
}
|
|
||||||
resp = requests.post(
|
|
||||||
BASE_URL,
|
|
||||||
data=json.dumps(body),
|
|
||||||
params=payload,
|
|
||||||
headers={CONTENT_TYPE: CONTENT_TYPE_JSON},
|
|
||||||
timeout=10,
|
|
||||||
)
|
|
||||||
if resp.status_code != 200:
|
|
||||||
log_error(resp)
|
|
||||||
|
|
||||||
|
|
||||||
def log_error(response):
|
def log_error(response):
|
||||||
"""Log error message."""
|
"""Log error message."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user