diff --git a/metadata-ingestion/src/datahub/ingestion/source/slack/slack.py b/metadata-ingestion/src/datahub/ingestion/source/slack/slack.py index ef7301238e4528..746f71fb0af370 100644 --- a/metadata-ingestion/src/datahub/ingestion/source/slack/slack.py +++ b/metadata-ingestion/src/datahub/ingestion/source/slack/slack.py @@ -97,6 +97,7 @@ def __init__(self, ctx: PipelineContext, config: SlackSourceConfig): self.rate_limiter = RateLimiter( max_calls=self.config.api_requests_per_min, period=60 ) + self._use_users_info = False @classmethod def create(cls, config_dict, ctx): @@ -239,19 +240,31 @@ def get_public_channels(self) -> Iterable[MetadataWorkUnit]: break def populate_user_profile(self, user_obj: CorpUser) -> None: + if not user_obj.slack_id: + return try: # https://api.slack.com/methods/users.profile.get with self.rate_limiter: - user_profile_res = self.get_slack_client().users_profile_get( - user=user_obj.slack_id - ) + if self._use_users_info: + user_profile_res = self.get_slack_client().users_info( + user=user_obj.slack_id + ) + user_profile_res = user_profile_res.get("user", {}) + else: + user_profile_res = self.get_slack_client().users_profile_get( + user=user_obj.slack_id + ) + logger.debug(f"User profile: {user_profile_res}") user_profile = user_profile_res.get("profile", {}) user_obj.title = user_profile.get("title") user_obj.image_url = user_profile.get("image_192") user_obj.phone = user_profile.get("phone") except Exception as e: if "missing_scope" in str(e): - raise e + if self._use_users_info: + raise e + self._use_users_info = True + self.populate_user_profile(user_obj) return def populate_slack_id_from_email(self, user_obj: CorpUser) -> None: