mirror of
https://github.com/datahub-project/datahub.git
synced 2025-09-09 17:20:42 +00:00
feat(ingest/slack): Support profile ingestion using users:info (#10410)
Co-authored-by: Shirshanka Das <shirshanka@apache.org>
This commit is contained in:
parent
8439cd7927
commit
786fe457d0
@ -97,6 +97,7 @@ class SlackSource(Source):
|
|||||||
self.rate_limiter = RateLimiter(
|
self.rate_limiter = RateLimiter(
|
||||||
max_calls=self.config.api_requests_per_min, period=60
|
max_calls=self.config.api_requests_per_min, period=60
|
||||||
)
|
)
|
||||||
|
self._use_users_info = False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, config_dict, ctx):
|
def create(cls, config_dict, ctx):
|
||||||
@ -239,19 +240,31 @@ class SlackSource(Source):
|
|||||||
break
|
break
|
||||||
|
|
||||||
def populate_user_profile(self, user_obj: CorpUser) -> None:
|
def populate_user_profile(self, user_obj: CorpUser) -> None:
|
||||||
|
if not user_obj.slack_id:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
# https://api.slack.com/methods/users.profile.get
|
# https://api.slack.com/methods/users.profile.get
|
||||||
with self.rate_limiter:
|
with self.rate_limiter:
|
||||||
user_profile_res = self.get_slack_client().users_profile_get(
|
if self._use_users_info:
|
||||||
user=user_obj.slack_id
|
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_profile = user_profile_res.get("profile", {})
|
||||||
user_obj.title = user_profile.get("title")
|
user_obj.title = user_profile.get("title")
|
||||||
user_obj.image_url = user_profile.get("image_192")
|
user_obj.image_url = user_profile.get("image_192")
|
||||||
user_obj.phone = user_profile.get("phone")
|
user_obj.phone = user_profile.get("phone")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if "missing_scope" in str(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
|
return
|
||||||
|
|
||||||
def populate_slack_id_from_email(self, user_obj: CorpUser) -> None:
|
def populate_slack_id_from_email(self, user_obj: CorpUser) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user