Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 17 additions & 4 deletions metadata-ingestion/src/datahub/ingestion/source/slack/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down