1 """Microsoft Teams platform for notify component."""
3 from __future__
import annotations
8 import voluptuous
as vol
14 PLATFORM_SCHEMA
as NOTIFY_PLATFORM_SCHEMA,
15 BaseNotificationService,
22 _LOGGER = logging.getLogger(__name__)
24 ATTR_FILE_URL =
"image_url"
26 PLATFORM_SCHEMA = NOTIFY_PLATFORM_SCHEMA.extend({vol.Required(CONF_URL): cv.url})
32 discovery_info: DiscoveryInfoType |
None =
None,
33 ) -> MSTeamsNotificationService |
None:
34 """Get the Microsoft Teams notification service."""
35 webhook_url = config.get(CONF_URL)
41 _LOGGER.exception(
"Error in creating a new Microsoft Teams message")
46 """Implement the notification service for Microsoft Teams."""
49 """Initialize the service."""
53 """Send a message to the webhook."""
55 teams_message = pymsteams.connectorcard(self.
_webhook_url_webhook_url)
57 title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
58 data = kwargs.get(ATTR_DATA)
60 teams_message.title(title)
62 teams_message.text(message)
64 if data
is not None and (file_url := data.get(ATTR_FILE_URL))
is not None:
65 if not file_url.startswith(
"http"):
66 _LOGGER.error(
"URL should start with http or https")
69 message_section = pymsteams.cardsection()
70 message_section.addImage(file_url)
71 teams_message.addSection(message_section)
74 except RuntimeError
as err:
75 _LOGGER.error(
"Could not send notification. Error: %s", err)
def __init__(self, webhook_url)
def send_message(self, message=None, **kwargs)
MSTeamsNotificationService|None get_service(HomeAssistant hass, ConfigType config, DiscoveryInfoType|None discovery_info=None)