-
Notifications
You must be signed in to change notification settings - Fork 1
/
slack.py
28 lines (22 loc) · 1002 Bytes
/
slack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import json
from slackipycore import invite, get_team_info
from slackipycore import (AlreadyInTeam, InvalidInviteeEmail,
InvalidAuthToken, AlreadyInvited, APIRequestError)
from flask import current_app
def invite_user(email):
api_token = current_app.config['SLACK_API_TOKEN']
team_id = current_app.config['SLACK_TEAM_ID']
try:
if invite(team_id=team_id, api_token=api_token,
invitee_email=email):
return {'status': 'success'}
except (AlreadyInTeam, InvalidInviteeEmail, InvalidAuthToken,
AlreadyInvited, APIRequestError) as e:
return _response_message(message=str(e))
def get_team_name():
api_token = current_app.config['SLACK_API_TOKEN']
team_id = current_app.config['SLACK_TEAM_ID']
team_info = get_team_info(team_id=team_id, api_token=api_token)
return team_info['name']
def _response_message(message):
return {'status': 'fail', 'error': message}