feat(ingest/slack): Support profile ingestion using users:info (#10410)

Co-authored-by: Shirshanka Das <shirshanka@apache.org>
This commit is contained in:
Andrew Sikowitz 2024-05-12 19:31:53 -04:00 committed by GitHub
parent 8439cd7927
commit 786fe457d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -97,6 +97,7 @@ class SlackSource(Source):
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 @@ class SlackSource(Source):
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: