當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。