Changeset View
Changeset View
Standalone View
Standalone View
python_modules/libraries/dagster-slack/dagster_slack/resources.py
from slackclient import SlackClient | from slack import WebClient | ||||
from dagster import Field, StringSource, resource, seven | from dagster import Field, StringSource, resource | ||||
class SlackConnection: | class SlackConnection: | ||||
def __init__(self, token): | def __init__(self, token: str): | ||||
self.token = token | self._token = token | ||||
sashank: Does this actually work generically? Or does it only work in our workspace? I have a feeling… | |||||
Done Inline ActionsAh, I just kept it since it was in the previous message arguments. But looks like icon_url can't be specified anyways with the newer tokens so I'll just remove it. rexledesma: Ah, I just kept it since it was in the previous message arguments. But looks like `icon_url`… | |||||
self.sc = SlackClient(self.token) | self.sc = WebClient(self._token) | ||||
class _Chat: | class _Chat: | ||||
@classmethod | @classmethod | ||||
def post_message( | def post_message(cls, channel: str, text: str, **kwargs): | ||||
Not Done Inline Actionswe should drop this whole wrapper class and just expose the client max: we should drop this whole wrapper class and just expose the client | |||||
Done Inline Actionsrexledesma: whynot | |||||
cls, | |||||
channel="#noise", | |||||
username="dagsterbot", | |||||
text="Hello from Dagster!", | |||||
# pylint: disable=line-too-long | |||||
icon_url="https://user-images.githubusercontent.com/609349/57993619-9ff2ee00-7a6e-11e9-9184-b3414e3eeb30.png", | |||||
attachments=None, | |||||
): | |||||
"""slack_resource.chat.post_message() : chat.postMessage | """slack_resource.chat.post_message() : chat.postMessage | ||||
See https://api.slack.com/methods/chat.postMessage | See https://api.slack.com/methods/chat.postMessage | ||||
""" | """ | ||||
api_params = { | return self.sc.chat_postMessage(channel=channel, text=text, **kwargs) | ||||
"channel": channel, | |||||
"username": username, | |||||
"text": text, | |||||
"icon_url": icon_url, | |||||
"attachments": seven.json.dumps(attachments), | |||||
} | |||||
return self.sc.api_call("chat.postMessage", **api_params) | |||||
self.chat = _Chat | self.chat = _Chat | ||||
def api_call(self, method, timeout=None, **kwargs): | def api_call(self, api_method: str, **kwargs): | ||||
return self.sc.api_call(method, timeout, **kwargs) | """ slack_resource.api_call() | ||||
See https://slack.dev/python-slackclient/basic_usage.html#calling-any-api-methods | |||||
""" | |||||
return self.sc.api_call(api_method, **kwargs) | |||||
@resource( | @resource( | ||||
{ | { | ||||
"token": Field( | "token": Field( | ||||
StringSource, | StringSource, | ||||
description="""To configure access to the Slack API, you'll need an access | description="""To configure access to the Slack API, you'll need an access | ||||
token provisioned with access to your Slack workspace. | token provisioned with access to your Slack workspace. | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |
Does this actually work generically? Or does it only work in our workspace? I have a feeling that you can't arbitrarily specify usernames and icons like this, and it only works in our workspace because we actually have a dagsterbot installed.