1 """Twilio Call platform for notify component."""
3 from __future__
import annotations
8 from twilio.base.exceptions
import TwilioRestException
9 import voluptuous
as vol
13 PLATFORM_SCHEMA
as NOTIFY_PLATFORM_SCHEMA,
14 BaseNotificationService,
21 _LOGGER = logging.getLogger(__name__)
23 CONF_FROM_NUMBER =
"from_number"
25 PLATFORM_SCHEMA = NOTIFY_PLATFORM_SCHEMA.extend(
27 vol.Required(CONF_FROM_NUMBER): vol.All(
28 cv.string, vol.Match(
r"^\+?[1-9]\d{1,14}$")
37 discovery_info: DiscoveryInfoType |
None =
None,
38 ) -> TwilioCallNotificationService:
39 """Get the Twilio Call notification service."""
41 hass.data[DATA_TWILIO], config[CONF_FROM_NUMBER]
46 """Implement the notification service for the Twilio Call service."""
48 def __init__(self, twilio_client, from_number):
49 """Initialize the service."""
54 """Call to specified target users."""
55 if not (targets := kwargs.get(ATTR_TARGET)):
56 _LOGGER.warning(
"At least 1 target is required")
59 if message.startswith((
"http://",
"https://")):
62 twimlet_url =
"http://twimlets.com/message?Message="
63 twimlet_url += urllib.parse.quote(message, safe=
"")
65 for target
in targets:
67 self.
clientclient.calls.create(
68 to=target, url=twimlet_url, from_=self.
from_numberfrom_number
70 except TwilioRestException
as exc:
def send_message(self, message="", **kwargs)
def __init__(self, twilio_client, from_number)
TwilioCallNotificationService get_service(HomeAssistant hass, ConfigType config, DiscoveryInfoType|None discovery_info=None)