Created
May 8, 2019 00:35
-
-
Save klizhentas/5322d3cc99ed5d885f7c8abee8549586 to your computer and use it in GitHub Desktop.
This Zap creates a private slack channel for an interview candidate, and invites the candidate to the channel.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import datetime | |
import uuid | |
channel_name='int-'+uuid.uuid4().hex[:8] | |
candidate_email = input['candidate_email'] | |
# Fetch the slack token from the encrypted storage | |
storage_secret = input['storage_secret'] | |
storage_client = StoreClient(storage_secret) | |
token = storage_client.get('slack_token') | |
headers = { | |
'Content-Type': 'application/x-www-form-urlencoded;', | |
'Authorization': 'Bearer '+token, | |
'Accept': 'application/json' | |
} | |
re = requests.post('https://slack.com/api/groups.create', headers=headers, data={ | |
'name': channel_name, | |
'validate': True, | |
}) | |
re.raise_for_status() | |
data = re.json() | |
print(data) | |
if not data['ok']: | |
raise ValueError(data['error']) | |
channel_id = re.json()['group']['id'] | |
re = requests.post('https://slack.com/api/users.admin.invite', headers=headers, data={ | |
'channels': channel_id, | |
'email':candidate_email, | |
# single channel guest | |
'ultra_restricted': True, | |
'resend': True, | |
# expires in a month | |
'expiration_ts': (datetime.datetime.utcnow() + datetime.timedelta(days=30)).strftime('%s'), | |
'set_active': True, | |
}) | |
re.raise_for_status() | |
data = re.json() | |
print(data) | |
if not data['ok']: | |
raise ValueError(data['error']) | |
output = [{'channel_id': channel_id, 'status': 'created'}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment