public function handle() { $token = Seat::get('slack_token'); if ($token == null) { throw new SlackSettingException("missing slack_token in settings"); } // get members list from slack team $api = new SlackApi($token); $members = $api->members(); // iterate over each member, check if the user mail match with a seat account and update the relation table foreach ($members as $m) { if ($m['id'] != 'USLACKBOT' && $m['deleted'] == false && $m['is_bot'] == false && !key_exists('api_app_id', $m['profile'])) { $user = User::where('email', '=', $m['profile']['email'])->first(); if ($user != null) { $slackUser = SlackUser::find($user->id); if ($slackUser == null) { $slackUser = new SlackUser(); $slackUser->user_id = $user->id; $slackUser->invited = true; } $slackUser->slack_id = $m['id']; $slackUser->save(); } } } }
public function testChannelUpdate() { // pre test Seat::set('slack_token', getenv('slack_token')); // test // get list of channels $channels = array_merge($this->slackApi->channels(false), $this->slackApi->channels(true)); // store all channels in an array of object $artifacts = []; foreach ($channels as $c) { $artifacts[] = new SlackChannel(['id' => $c['id'], 'name' => $c['name']]); } // call slack:update:channels command $job = new SlackChannelsUpdate(); $job->handle(); // fetch in database channels $inDatabase = SlackChannel::all(['id', 'name']); // convert to an array of "new object" $result = []; foreach ($inDatabase as $object) { $result[] = new SlackChannel(['id' => $object->id, 'name' => $object->name]); } // compare both array $this->assertEquals($artifacts, $result); }
public function handle() { $token = Seat::get('slack_token'); if ($token == null) { throw new SlackSettingException("missing slack_token in settings"); } // init Slack Api using token $api = new SlackApi($token); // make a call in order to fetch both public and private channels $channels = array_merge($api->channels(false), $api->channels(true)); $slackChannelIds = []; // iterate over each slack channel and create or update information from SeAT foreach ($channels as $channel) { // init channels ids array which will be used later in order to remove outdate channels $slackChannelIds[] = $channel['id']; // init flags to default value $isGroup = true; $isGeneral = false; // try to get channel object from SeAT $slackChannel = SlackChannel::find($channel['id']); // Determine if this is a group (private channel) or a channel if (substr($channel['id'], 0, 1) === 'C') { $isGroup = false; } if ($isGroup == false) { $isGeneral = (bool) $channel['is_general']; } // create the channel if it doesn't exist if ($slackChannel == null) { SlackChannel::create(['id' => $channel['id'], 'name' => $channel['name'], 'is_group' => $isGroup, 'is_general' => $isGeneral]); continue; } // update the channel if it is already known by SeAT $slackChannel->update(['name' => $channel['name'], 'is_general' => $isGeneral]); } // get all known channels from SeAT SlackChannel::whereNotIn('id', $slackChannelIds)->delete(); /* // iterate over each of them and check if they are still valid // if not, we will remove them from the database since they are no longer usable foreach ($seatChannels as $channel) { if (in_array($channel->id, $slackChannelIds) == false) { $channel->delete(); } } */ }
private function restoreGroup($groupId) { // load token and team uri from settings $token = Seat::get('slack_token'); if ($token == null) { throw new SlackSettingException("missing slack_token in settings"); } $slackApi = new SlackApi($token); $apiGroup = $slackApi->info($groupId, true); SlackChannel::create(['id' => $apiGroup['id'], 'name' => $apiGroup['name'], 'is_group' => true]); }
public function testOwnerKick() { $testUser = '******'; $this->assertNull($this->slackApi->kick($testUser, 'C1Z920QKD', false)); }