1 """Support for Twilio."""
3 from aiohttp
import web
4 from twilio.rest
import Client
5 import voluptuous
as vol
15 from .const
import DOMAIN
17 CONF_ACCOUNT_SID =
"account_sid"
18 CONF_AUTH_TOKEN =
"auth_token"
22 RECEIVED_DATA = f
"{DOMAIN}_data_received"
24 CONFIG_SCHEMA = vol.Schema(
26 vol.Optional(DOMAIN): vol.Schema(
28 vol.Required(CONF_ACCOUNT_SID): cv.string,
29 vol.Required(CONF_AUTH_TOKEN): cv.string,
33 extra=vol.ALLOW_EXTRA,
37 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
38 """Set up the Twilio component."""
39 if DOMAIN
not in config:
43 hass.data[DATA_TWILIO] = Client(
44 conf.get(CONF_ACCOUNT_SID), conf.get(CONF_AUTH_TOKEN)
50 hass: HomeAssistant, webhook_id: str, request: web.Request
52 """Handle incoming webhook from Twilio for inbound messages and calls."""
53 data =
dict(await request.post())
54 data[
"webhook_id"] = webhook_id
55 hass.bus.async_fire(RECEIVED_DATA,
dict(data))
57 return web.Response(text=
"")
61 """Configure based on config entry."""
62 webhook.async_register(
63 hass, DOMAIN,
"Twilio", entry.data[CONF_WEBHOOK_ID], handle_webhook
69 """Unload a config entry."""
70 webhook.async_unregister(hass, entry.data[CONF_WEBHOOK_ID])
74 async_remove_entry = config_entry_flow.webhook_async_remove_entry
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
web.Response handle_webhook(HomeAssistant hass, str webhook_id, web.Request request)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup(HomeAssistant hass, ConfigType config)