当前位置: 首页>>代码示例>>Python>>正文


Python slack.WebClient方法代码示例

本文整理汇总了Python中slack.WebClient方法的典型用法代码示例。如果您正苦于以下问题:Python slack.WebClient方法的具体用法?Python slack.WebClient怎么用?Python slack.WebClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在slack的用法示例。


在下文中一共展示了slack.WebClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: start_onboarding

# 需要导入模块: import slack [as 别名]
# 或者: from slack import WebClient [as 别名]
def start_onboarding(web_client: slack.WebClient, user_id: str, channel: str):
    # Create a new onboarding tutorial.
    onboarding_tutorial = OnboardingTutorial(channel)

    # Get the onboarding message payload
    message = onboarding_tutorial.get_message_payload()

    # Post the onboarding message in Slack
    response = await web_client.chat_postMessage(**message)

    # Capture the timestamp of the message we've just posted so
    # we can use it to update the message after a user
    # has completed an onboarding task.
    onboarding_tutorial.timestamp = response["ts"]

    # Store the message sent in onboarding_tutorials_sent
    if channel not in onboarding_tutorials_sent:
        onboarding_tutorials_sent[channel] = {}
    onboarding_tutorials_sent[channel][user_id] = onboarding_tutorial


# ================ Team Join Event =============== #
# When the user first joins a team, the type of the event will be 'team_join'.
# Here we'll link the onboarding_message callback to the 'team_join' event. 
开发者ID:slackapi,项目名称:python-slackclient,代码行数:26,代码来源:async_app.py

示例2: onboarding_message

# 需要导入模块: import slack [as 别名]
# 或者: from slack import WebClient [as 别名]
def onboarding_message(**payload):
    """Create and send an onboarding welcome message to new users. Save the
    time stamp of this message so we can update this message in the future.
    """
    # Get WebClient so you can communicate back to Slack.
    web_client = payload["web_client"]

    # Get the id of the Slack user associated with the incoming event
    user_id = payload["data"]["user"]["id"]

    # Open a DM with the new user.
    response = web_client.im_open(user_id)
    channel = response["channel"]["id"]

    # Post the onboarding message.
    await start_onboarding(web_client, user_id, channel)


# ============= Reaction Added Events ============= #
# When a users adds an emoji reaction to the onboarding message,
# the type of the event will be 'reaction_added'.
# Here we'll link the update_emoji callback to the 'reaction_added' event. 
开发者ID:slackapi,项目名称:python-slackclient,代码行数:24,代码来源:async_app.py

示例3: test_issue_559

# 需要导入模块: import slack [as 别名]
# 或者: from slack import WebClient [as 别名]
def test_issue_559(self):
        response = SlackResponse(
            client=WebClient(token="xoxb-dummy"),
            http_verb="POST",
            api_url="http://localhost:3000/api.test",
            req_args={},
            data={
                "ok": True,
                "args": {
                    "hello": "world"
                }
            },
            headers={},
            status_code=200,
        )

        self.assertTrue("ok" in response.data)
        self.assertTrue("args" in response.data)
        self.assertFalse("error" in response.data) 
开发者ID:slackapi,项目名称:python-slackclient,代码行数:21,代码来源:test_slack_response.py

示例4: test_response_can_be_paginated_multiple_times_use_sync_aiohttp

# 需要导入模块: import slack [as 别名]
# 或者: from slack import WebClient [as 别名]
def test_response_can_be_paginated_multiple_times_use_sync_aiohttp(self):
        self.client = WebClient(
            token="xoxp-1234",
            base_url="http://localhost:8888",
            run_async=False,
            use_sync_aiohttp=True,
        )
        self.client.token = "xoxb-channels_list_pagination"
        # This test suite verifies the changes in #521 work as expected
        response = self.client.channels_list(limit=1)
        ids = []
        for page in response:
            ids.append(page["channels"][0]["id"])
        self.assertEqual(ids, ["C1", "C2", "C3"])

        # The second iteration starting with page 2
        # (page1 is already cached in `response`)
        self.client.token = "xoxb-channels_list_pagination2"
        ids = []
        for page in response:
            ids.append(page["channels"][0]["id"])
        self.assertEqual(ids, ["C1", "C2", "C3"]) 
开发者ID:slackapi,项目名称:python-slackclient,代码行数:24,代码来源:test_web_client.py

示例5: setUp

# 需要导入模块: import slack [as 别名]
# 或者: from slack import WebClient [as 别名]
def setUp(self):
        setup_mock_web_api_server(self)

        self.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(self.loop)
        task = asyncio.ensure_future(self.mock_server(), loop=self.loop)
        self.loop.run_until_complete(asyncio.wait_for(task, 0.1))

        self.client = slack.RTMClient(
            token="xoxb-valid",
            base_url="http://localhost:8765",
            auto_reconnect=False,
            run_async=False,
        )
        self.client._web_client = slack.WebClient(
            token="xoxb-valid",
            base_url="http://localhost:8888",
            run_async=False,
        ) 
开发者ID:slackapi,项目名称:python-slackclient,代码行数:21,代码来源:test_rtm_client_functional.py

示例6: test_run_async_valid

# 需要导入模块: import slack [as 别名]
# 或者: from slack import WebClient [as 别名]
def test_run_async_valid(self):
        client = slack.RTMClient(
            token="xoxb-valid",
            base_url="http://localhost:8765",
            run_async=True,
        )
        client._web_client = slack.WebClient(
            token="xoxb-valid",
            base_url="http://localhost:8888",
            run_async=True,
        )
        self.called = False

        @slack.RTMClient.run_on(event="open")
        async def handle_open_event(**payload):
            self.called = True

        client.start()  # intentionally no await here
        await asyncio.sleep(3)
        self.assertTrue(self.called) 
开发者ID:slackapi,项目名称:python-slackclient,代码行数:22,代码来源:test_rtm_client_functional.py

示例7: test_run_async_invalid

# 需要导入模块: import slack [as 别名]
# 或者: from slack import WebClient [as 别名]
def test_run_async_invalid(self):
        client = slack.RTMClient(
            token="xoxb-valid",
            base_url="http://localhost:8765",
            run_async=True,
        )
        client._web_client = slack.WebClient(
            token="xoxb-valid",
            base_url="http://localhost:8888",
            run_async=True,
        )
        self.called = False

        @slack.RTMClient.run_on(event="open")
        def handle_open_event(**payload):
            self.called = True

        client.start()  # intentionally no await here
        await asyncio.sleep(3)
        self.assertFalse(self.called) 
开发者ID:slackapi,项目名称:python-slackclient,代码行数:22,代码来源:test_rtm_client_functional.py

示例8: setUp

# 需要导入模块: import slack [as 别名]
# 或者: from slack import WebClient [as 别名]
def setUp(self):
        self.logger = logging.getLogger(__name__)
        self.org_admin_token = os.environ[SLACK_SDK_TEST_GRID_ORG_ADMIN_USER_TOKEN]
        self.sync_client: WebClient = WebClient(
            token=self.org_admin_token,
            run_async=False,
            loop=asyncio.new_event_loop()
        )
        self.async_client: WebClient = WebClient(token=self.org_admin_token, run_async=True)

        self.team_id = os.environ[SLACK_SDK_TEST_GRID_TEAM_ID]
        self.idp_usergroup_id = os.environ[SLACK_SDK_TEST_GRID_IDP_USERGROUP_ID]

        if not hasattr(self, "channel_ids"):
            team_admin_token = os.environ[SLACK_SDK_TEST_GRID_WORKSPACE_ADMIN_USER_TOKEN]
            client = WebClient(token=team_admin_token, run_async=False, loop=asyncio.new_event_loop())
            convs = client.conversations_list(exclude_archived=True, limit=100)
            self.channel_ids = [c["id"] for c in convs["channels"] if c["name"] == "general"] 
开发者ID:slackapi,项目名称:python-slackclient,代码行数:20,代码来源:test_admin_usergroups.py

示例9: test_uploading_file_with_token_param

# 需要导入模块: import slack [as 别名]
# 或者: from slack import WebClient [as 别名]
def test_uploading_file_with_token_param(self):
        client = WebClient()
        current_dir = os.path.dirname(__file__)
        file = f"{current_dir}/../../tests/data/slack_logo.png"
        upload = client.files_upload(
            token=self.bot_token,
            channels=self.channel_id,
            title="Good Old Slack Logo",
            filename="slack_logo.png",
            file=file,
        )
        self.assertIsNotNone(upload)

        deletion = client.files_delete(
            token=self.bot_token,
            file=upload["file"]["id"],
        )
        self.assertIsNotNone(deletion) 
开发者ID:slackapi,项目名称:python-slackclient,代码行数:20,代码来源:test_web_client.py

示例10: test_uploading_file_with_token_param_async

# 需要导入模块: import slack [as 别名]
# 或者: from slack import WebClient [as 别名]
def test_uploading_file_with_token_param_async(self):
        client = WebClient(run_async=True)
        current_dir = os.path.dirname(__file__)
        file = f"{current_dir}/../../tests/data/slack_logo.png"
        upload = await client.files_upload(
            token=self.bot_token,
            channels=self.channel_id,
            title="Good Old Slack Logo",
            filename="slack_logo.png",
            file=file,
        )
        self.assertIsNotNone(upload)

        deletion = client.files_delete(
            token=self.bot_token,
            file=upload["file"]["id"],
        )
        self.assertIsNotNone(deletion)

    # -------------------------
    # pagination 
开发者ID:slackapi,项目名称:python-slackclient,代码行数:23,代码来源:test_web_client.py

示例11: test_basic_operations_async

# 需要导入模块: import slack [as 别名]
# 或者: from slack import WebClient [as 别名]
def test_basic_operations_async(self):
        self.sent_text: str = None
        self.rtm_client = RTMClient(token=self.bot_token, run_async=True)
        self.async_web_client = WebClient(token=self.bot_token, run_async=True)

        @RTMClient.run_on(event="message")
        async def send_reply(**payload):
            self.logger.debug(payload)
            self.sent_text = payload['data']['text']

        # intentionally not waiting here
        self.rtm_client.start()

        self.assertIsNone(self.sent_text)
        await asyncio.sleep(5)

        text = "This message was sent by <https://slack.dev/python-slackclient/|python-slackclient>! (test_basic_operations_async)"
        new_message = await self.async_web_client.chat_postMessage(channel=self.channel_id, text=text)
        self.assertFalse("error" in new_message)
        await asyncio.sleep(5)
        self.assertEqual(self.sent_text, text) 
开发者ID:slackapi,项目名称:python-slackclient,代码行数:23,代码来源:test_rtm_client.py

示例12: per_request_async

# 需要导入模块: import slack [as 别名]
# 或者: from slack import WebClient [as 别名]
def per_request_async():
    try:
        # This is not optimal and the host should have a large number of FD (File Descriptor)
        loop_for_this_request = asyncio.new_event_loop()

        async_client = WebClient(
            token=os.environ["SLACK_BOT_TOKEN"],
            run_async=True,
            loop=loop_for_this_request
        )
        future = async_client.chat_postMessage(
            channel="#random",
            text="You used the singleton WebClient for posting this message!"
        )
        response = loop_for_this_request.run_until_complete(future)
        return str(response)
    except SlackApiError as e:
        return make_response(str(e), 400) 
开发者ID:slackapi,项目名称:python-slackclient,代码行数:20,代码来源:issue_497.py

示例13: send_message

# 需要导入模块: import slack [as 别名]
# 或者: from slack import WebClient [as 别名]
def send_message(self, message, quiet=False):
        """
        Send queued messages as single communication.

            :param message:     Final message's content
            :param quiet:       Flag for disabling sending report through Slack
            :type message:      String
            :type quiet:        Boolean
        """
        if self._slack_client is None:
            try:
                self._slack_client = slack.WebClient(self._slack_token, proxy=self._proxy, ssl=False)
            except Exception:
                print('!!CRITICAL!! SlackCommunicator::CRITICAL: Could not create client')
                raise
        for channel, message_queue in self._queued_messages.items():
            final_message = message + '\n\n' + '\n'.join(message_queue)
            print(final_message)
            if not quiet and message_queue:
                self._send_to_channel(final_message, channel) 
开发者ID:NervanaSystems,项目名称:ngraph-onnx,代码行数:22,代码来源:SlackCommunicator.py

示例14: slack_status

# 需要导入模块: import slack [as 别名]
# 或者: from slack import WebClient [as 别名]
def slack_status(options):
    channel = options.get('STATUS_CHANNEL', None)
    if channel is None:
        return
    module = options.get('CURRENT_MODULE')

    target = options.get('TARGET')
    message = f':ghost: Start *{module}* on *{target}*'

    client = slack.WebClient(token=options.get('SLACK_BOT_TOKEN'))
    client.chat_postMessage(
        channel=channel,
        blocks=[
            {
                "type": "section",
                "text": {
                    "type": "mrkdwn",
                    "text": message,
                },
            },
            {
                "type": "divider"
            }
        ]
    ) 
开发者ID:j3ssie,项目名称:Osmedeus,代码行数:27,代码来源:slack_noti.py

示例15: slack_file

# 需要导入模块: import slack [as 别名]
# 或者: from slack import WebClient [as 别名]
def slack_file(options, filename, token=None):
    try:
        if not token:
            token = options.get('SLACK_BOT_TOKEN')
        client = slack.WebClient(token=token)
        channel = options.get('REPORT_CHANNEL')
        if channel is None:
            return

        client.files_upload(
            channels=channel,
            file=filename,
            title=filename,
            filetype='text'
        )
    except:
        pass 
开发者ID:j3ssie,项目名称:Osmedeus,代码行数:19,代码来源:slack_noti.py


注:本文中的slack.WebClient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。