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) self.async_client: AsyncWebClient = AsyncWebClient( token=self.org_admin_token) self.team_id = os.environ[SLACK_SDK_TEST_GRID_TEAM_ID] self.idp_group_id = os.environ[SLACK_SDK_TEST_GRID_IDP_USERGROUP_ID] if not hasattr(self, "channel_id"): team_admin_token = os.environ[ SLACK_SDK_TEST_GRID_WORKSPACE_ADMIN_USER_TOKEN] client = WebClient(token=team_admin_token) # Only fetching private channels since admin.conversations.restrictAccess methods do not work for public channels convs = client.conversations_list(exclude_archived=True, limit=100, types="private_channel") self.channel_id = next( (c["id"] for c in convs["channels"] if c["name"] != "general"), None) if self.channel_id is None: millis = int(round(time.time() * 1000)) channel_name = f"private-test-channel-{millis}" self.channel_id = client.conversations_create( name=channel_name, is_private=True, )["channel"]["id"]
import logging logging.basicConfig(level=logging.DEBUG) # export SLACK_API_TOKEN=xoxb-*** # python3 integration_tests/samples/conversations/create_private_channel.py import os from slack_sdk.web import WebClient from time import time client = WebClient(token=os.environ["SLACK_API_TOKEN"]) channel_name = f"my-private-channel-{round(time())}" response = client.conversations_create(name=channel_name, is_private=True) channel_id = response["channel"]["id"] response = client.conversations_info( channel=channel_id, include_num_members=1 # TODO: True ) response = client.conversations_members(channel=channel_id) user_ids = response["members"] print(f"user_ids: {user_ids}") response = client.conversations_archive(channel=channel_id)