From c6991e27aa9f71d56df1de301ded1475cbd523f6 Mon Sep 17 00:00:00 2001 From: Adam Vartanian Date: Tue, 11 Oct 2022 16:07:37 +0100 Subject: [PATCH] Small updates to Slack user syncing (#382) * Small updates to Slack user syncing Makes some small changes to make Slack user syncing work: * Don't try to decode() the phone number, it's already a str * Skip users with `is_bot` set * Check if `phone` is nonempty before trying to parse * Fix formatting error --- src/oncall/notifier/reminder.py | 2 +- src/oncall/user_sync/slack.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/oncall/notifier/reminder.py b/src/oncall/notifier/reminder.py index cf1c41a..6632136 100644 --- a/src/oncall/notifier/reminder.py +++ b/src/oncall/notifier/reminder.py @@ -74,7 +74,7 @@ def reminder(config): WHERE `e`.`id` IS NULL AND `user`.`active` = 1 ''' - while(1): + while (1): logger.info('Reminder polling loop started') window_end = int(time.time()) diff --git a/src/oncall/user_sync/slack.py b/src/oncall/user_sync/slack.py index 0d2bd83..a954e48 100644 --- a/src/oncall/user_sync/slack.py +++ b/src/oncall/user_sync/slack.py @@ -13,7 +13,7 @@ logger = logging.getLogger(__name__) def normalize_phone_number(num): - return format_number(parse(num.decode('utf-8'), 'US'), PhoneNumberFormat.INTERNATIONAL) + return format_number(parse(num, 'US'), PhoneNumberFormat.INTERNATIONAL) def fetch_oncall_usernames(connection): @@ -68,7 +68,7 @@ def sync_action(slack_client): slack_users = {} for m in slack_members: - if m['name'] == 'slackbot' or m['deleted']: + if m['name'] == 'slackbot' or m['deleted'] or m['is_bot']: continue user_profile = m['profile'] slack_users[m['name']] = { @@ -77,7 +77,7 @@ def sync_action(slack_client): 'photo_url': user_profile['image_512'], 'email': user_profile['email'], } - if 'phone' in user_profile: + if 'phone' in user_profile and user_profile['phone']: slack_users[m['name']]['phone'] = normalize_phone_number(user_profile['phone']) connection = db.connect()