1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

25 lines
726 B
Python
Raw Normal View History

2020-04-18 23:18:50 -07:00
"""Session handler for Slack API."""
# Project
from hyperglass.log import log
from hyperglass.external._base import BaseExternal
from hyperglass.models.webhook import Webhook
2020-04-18 23:18:50 -07:00
class SlackHook(BaseExternal, name="Slack"):
"""Slack session handler."""
2020-04-21 03:29:42 -07:00
def __init__(self, config):
2020-04-18 23:18:50 -07:00
"""Initialize external base class with Slack connection details."""
super().__init__(base_url="https://hooks.slack.com", config=config, parse=False)
2020-04-18 23:18:50 -07:00
2020-04-21 03:29:42 -07:00
async def send(self, query):
2020-04-18 23:18:50 -07:00
"""Send an incoming webhook to Slack."""
payload = Webhook(**query)
log.debug("Sending query data to Slack:\n{}", payload)
2020-04-21 03:29:42 -07:00
return await self._apost(endpoint=self.config.host.path, data=payload.slack())