Skip to content

Commit

Permalink
Fix handling of app installation and sending (#183)
Browse files Browse the repository at this point in the history
welcome message to general channel
  • Loading branch information
fedeq authored Dec 13, 2023
1 parent 2907d77 commit 28c9678
Showing 1 changed file with 31 additions and 26 deletions.
57 changes: 31 additions & 26 deletions src/services/slack_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,35 +405,40 @@ def handle_app_uninstalled_events(body, logger):


def handle_app_installed(request):
team_id = request.form.get("team_id")
team_data = get_team_data(team_id)
if team_data["slack_bot_token"] is None:
logging.info(f"App installed but no token found for team {team_id}")
conversation_list = retry(
lambda: slack_app.client.conversations_list(
token=team_data["slack_bot_token"],
types="public_channel",
exclude_archived=True,
limit=10
try:
team_id = request.form.get("team_id")
team_data = get_team_data(team_id)
if team_data["slack_bot_token"] is None:
logging.info(
f"App installed but no token found for team {team_id}")
conversation_list = retry(
lambda: slack_app.client.conversations_list(
token=team_data["slack_bot_token"],
types="public_channel",
exclude_archived=True,
limit=10
)
)
)
# send message to general channel
for conversation in conversation_list["channels"]:
if conversation["is_general"]:
retry(
lambda: slack_app.client.conversations_join(
token=team_data["slack_bot_token"],
channel=conversation["id"]
# send message to general channel
for conversation in conversation_list["channels"]:
if conversation["is_general"]:
retry(
lambda: slack_app.client.conversations_join(
token=team_data["slack_bot_token"],
channel=conversation["id"]
)
)
)
retry(
lambda: slack_app.client.chat_postMessage(
token=team_data["slack_bot_token"],
channel=conversation["id"],
text=WELCOME_MESSAGE
retry(
lambda: slack_app.client.chat_postMessage(
token=team_data["slack_bot_token"],
channel=conversation["id"],
text=WELCOME_MESSAGE
)
)
)
return "OK"
return "OK"
except Exception as e:
logging.error(e, exc_info=True)
return "Error handling app installation", 500


@slack_app.event("member_joined_channel")
Expand Down

0 comments on commit 28c9678

Please sign in to comment.