1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Listing channels that Slackbot is a member of

Discussão em 'Python' iniciado por Stack, Setembro 28, 2024 às 09:02.

  1. Stack

    Stack Membro Participativo

    I have a small script which uses the slack API to create group chats with users and send an intro message. There are around ~100 of these group chats that I have created, but unfortunately I only noted down the channel ID's of 2 of them. I need to find the other 98 channel ID's.

    I have the following script to determine the 98 channel ID's based on the is_member field returned in the response:

    # Imports
    from slack_sdk import WebClient
    import config

    # Slack Client
    slack_client = WebClient(config.OAUTH_TOKEN)

    api_call = slack_client.conversations_list(type='private', limit=10000)

    channels = api_call['channels']

    for channel in channels:
    if channel['is_member']:
    print(channel['id'])



    Unfortunately nothing is printed to the console. However, since I have 2 of the channel ID's, I have used the following to get info about these channels:

    api_call = slack_client.conversations_info(channel=<known channel ID>)


    This returns the following:

    {'ok': True, 'channel': {'id': <known channel ID>, 'name': <redacted>, 'is_channel': True,
    'is_group': False, 'is_im': False, 'is_mpim': True, 'is_private': True, 'created': 1721671251,
    'is_archived': False, 'is_general': False, 'unlinked': 0, 'name_normalized': <redacted>,
    'is_shared': True, 'is_org_shared': True, 'is_pending_ext_shared': False, 'pending_shared': [],
    'context_team_id': <redacted> , 'updated': 1721671251297, 'parent_conversation': None,
    'creator': <redacted>, 'is_read_only': False, 'is_thread_only': False, 'is_non_threadable':
    False, 'is_moved': 0, 'is_ext_shared': False, 'enterprise_id': <redacted>, 'is_global_shared':
    False, 'is_org_default': False, 'is_org_mandatory': False, 'shared_team_ids': [],
    'internal_team_ids': [], 'connected_team_ids': [], 'connected_limited_team_ids': [],
    'pending_connected_team_ids': [], 'is_member': True, 'last_read': '0000000000.000000',
    'is_open': True, 'topic': {'value': '', 'creator': '', 'last_set': 0}, 'purpose': {'value':
    <redacted>, 'creator': <redacted>, 'last_set': 1721671251}}}


    The main thing I notice here is that the is_private field is set to True. However, when I make the call slack_client.conversations_list(type='private', limit=10000) I only get returned channels where is_private is set to False. Maybe it is an issue with scopes, but I have the following scopes: channels:history, channels:read, chat:write, groups:history, groups:read, groups:write, im:history, mpim:history, mpim:read, mpim:write. Any help would be much appreciated! `

    Continue reading...

Compartilhe esta Página