-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae75f3b
commit 0737466
Showing
5 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import logging | ||
|
||
from senor_octopus.types import Stream | ||
from slack_sdk import WebClient | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
async def slack( | ||
stream: Stream, | ||
token: str, | ||
channel: str, | ||
) -> None: | ||
""" | ||
Send events as messages to a Slack channel. | ||
This sink can be used to send events to a Slack channel. | ||
The value of the event is sent as the message; its name | ||
is ignored. | ||
Parameters | ||
---------- | ||
stream | ||
The incoming stream of events | ||
token | ||
The authentication token for the bot | ||
channel | ||
The Slack channel ID | ||
""" | ||
client = WebClient(token=token) | ||
async for event in stream: # pragma: no cover | ||
client.chat_postMessage(channel=channel, text=str(event["value"])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import random | ||
|
||
import pytest | ||
from senor_octopus.sinks.slack import slack | ||
from senor_octopus.sources.rand import rand | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_slack(mocker) -> None: | ||
WebClient = mocker.patch("senor_octopus.sinks.slack.WebClient") | ||
client = WebClient.return_value | ||
|
||
random.seed(42) | ||
|
||
await slack(rand(1), "XXX", "C0123456789") | ||
|
||
client.chat_postMessage.assert_called_with( | ||
channel="C0123456789", | ||
text="0.6394267984578837", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters