File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,8 +55,7 @@ async def invite(request: SlackApiRequest, app: SirBot):
5555
5656 except SlackAPIError as e :
5757 logger .info ("Slack invite resulted in SlackAPIError: " + e .error )
58- if e .error != "already_invited" and e .error != "already_in_team" :
59- await handle_slack_invite_error (email , e , slack )
58+ await handle_slack_invite_error (email , e , slack )
6059 return e .data
6160
6261 except Exception as e :
Original file line number Diff line number Diff line change 1212
1313
1414async def _slack_info_from_email (
15- email : str , slack : SlackAPI , fallback : Optional [str ] = None
16- ):
15+ email : str , slack : SlackAPI , fallback : Optional [dict ] = None
16+ ) -> dict :
1717 try :
1818 response = await slack .query (
1919 url = ROOT_URL + "users.lookupByEmail" , data = {"email" : email }
@@ -55,7 +55,21 @@ def invite_failure_attachments(email: str, error: str) -> list:
5555
5656
5757async def handle_slack_invite_error (email , error , slack ):
58+ if error .error == "already_invited" :
59+ return error .data
60+
5861 attachments = invite_failure_attachments (email , error )
62+
63+ if error .error == "already_in_team" :
64+ slack_user = await _slack_info_from_email (email , slack )
65+ attachments [0 ]["fields" ].append (
66+ {
67+ "title" : "Slack Username" ,
68+ "value" : f"<@{ slack_user ['id' ]} >" ,
69+ "short" : True ,
70+ }
71+ )
72+
5973 response = {
6074 "channel" : TICKET_CHANNEL ,
6175 "attachments" : attachments ,
You can’t perform that action at this time.
0 commit comments