Making WordPress.org

Changeset 10823


Ignore:
Timestamp:
03/17/2021 12:52:21 AM (5 years ago)
Author:
dd32
Message:

Slack: Update the /subgroup command to use the conversations.* api methods, rather than the now deprecated groups.* api methods.

See https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/dotorg/slack/subgroup.php

    r2989 r10823  
    3333
    3434// Get a list of all groups @wordpressdotorg is in.
    35 $groups = api_call( 'groups.list' )['groups'];
     35$groups = api_call(
     36        // https://api.slack.com/methods/conversations.list
     37        'conversations.list',
     38        [
     39                'exclude_archived' => true,
     40                'types'            => 'private_channel',
     41                'limit'            => 999,
     42        ]
     43);
    3644
    3745// Find the group that we are in right now.
    38 foreach ( $groups as $group ) {
     46foreach ( $groups['channels'] as $group ) {
    3947        if ( $group['id'] === $current_group_id ) {
    4048                $found = true;
     
    6674                        die( "Must create a group that starts with `{$group['name']}-`." );
    6775                }
    68        
    69                 $new_group = api_call( 'groups.create', array( 'name' => $subcommand ) );
     76
     77                // Create the new private channel.
     78                $new_group = api_call(
     79                        'conversations.create',
     80                        [
     81                                'name' => $subcommand,
     82                                'is_private' => true,
     83                        ]
     84                );
    7085                if ( empty( $new_group['ok'] ) ) {
    7186                        die( "Group creation failed. Does it already exist?" );
    7287                }
    73        
    74                 foreach ( $group['members'] as $member ) {
    75                         api_call( 'groups.invite', array( 'channel' => $new_group['group']['id'], 'user' => $member ) );
     88
     89                // Post a message to the parent channel about this channels creation.
     90                api_call(
     91                        // https://api.slack.com/methods/chat.postMessage
     92                        'chat.postMessage',
     93                        [
     94                                'channel' => $group['id'],
     95                                'text'    => sprintf(
     96                                        'Group %s created by <@%s>.',
     97                                        $new_group['group']['name'],
     98                                        $_POST['user_id']
     99                                ),
     100                                'as_user' => true,
     101                        ]
     102                );
     103
     104                // Invite all current parent channel members to the new channel.
     105                $members = api_call(
     106                        // https://api.slack.com/methods/conversations.members
     107                        'conversations.members',
     108                        [
     109                                'channel' => 'CMYKV0D7B',
     110                                'limit'            => 999,
     111                        ]
     112                );
     113                if ( empty( $members['members'] ) ) {
     114                        die( sprintf( "Group %s created, but could not invite members.", $new_group['group']['name'] ) );
    76115                }
    77        
    78                 api_call( 'chat.postMessage', array(
    79                         'channel' => $group['id'],
    80                         'text'    => sprintf( 'Group %s created by <@%s>.', $new_group['group']['name'], $_POST['user_id'] ),
    81                         'as_user' => true,
    82                 ) );
     116
     117                api_call(
     118                        // https://api.slack.com/methods/conversations.invite
     119                        'conversations.invite',
     120                        [
     121                                'channel' => $new_group['group']['id'],
     122                                'users'   => implode( ',', $members['members'] ),
     123                        ]
     124                );
    83125
    84126                die( sprintf( "Group %s created.", $new_group['group']['name'] ) );
     
    88130                foreach ( $groups as $group ) {
    89131                        if ( $group['name'] === $subcommand ) {
    90                                 api_call( 'groups.invite', array( 'channel' => $group['id'], 'user' => $_POST['user_id'] ) );
     132                                api_call(
     133                                        // https://api.slack.com/methods/conversations.invite
     134                                        'conversations.invite',
     135                                        [
     136                                                'channel' => $group['id'],
     137                                                'users'   => $_POST['user_id'],
     138                                        ]
     139                                );
     140
    91141                                die( "Invited to {$group['name']}." );
    92142                        }
    93143                }
    94        
     144
    95145                die( "$subcommand group not found." );
    96        
     146
    97147        case 'list':
    98148        default:
    99149                $groups_to_add = array();
    100        
     150
    101151                $parent_group = $group;
    102152                foreach ( $groups as $group ) {
     
    107157                        }
    108158                }
    109        
     159
    110160                if ( $groups_to_add ) {
    111161                        echo "You may join any of these groups:\n -- `" . implode( "`\n -- `", $groups_to_add ) . "`\n\n\n";
     
    113163                        echo "You are in all {$parent_group['name']} subgroups that the @wordpressdotorg user knows about.\n\n";
    114164                }
    115        
     165
    116166                die( "*Help:*\n`/subgroup list` - display this message\n`/subgroup join {name}` - join a subgroup\n`/subgroup create {name}` - create a subgroup" );
    117167}
    118        
     168
Note: See TracChangeset for help on using the changeset viewer.