Skip to content

Commit

Permalink
Fix KeyError when is_im not present. (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
nzlosh authored Mar 25, 2024
1 parent e8d7dd4 commit e9b0b62
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- refactored user cache to allow organisation level users/bots #95 (@gdelaney)
### Fixed
- setting SlackRoom purpose. (@jcfrt)
- Fixed channelname raising KeyError: 'is_im'. #103 (@nzlosh)

## [0.2.1] 2022-10-02
### Added
Expand Down
8 changes: 3 additions & 5 deletions src/slackv3/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,9 @@ def _cache_user_info(self):
# Normal users
if res.get("user").get("team_id"):
team = res["user"]["team_id"]

# Users in a ORG/grid setup do not have a team ID
elif res.get("user").get("enterprise_user"):
team = res.get("user").get("enterprise_user").get("enterprise_id")

elif res.get("user", {}).get("enterprise_user"):
team = res["user"]["enterprise_user"].get("enterprise_id")
else:
log.warning(
f"Failed to find team_id or enterprise_user details for userid {self._userid}."
Expand All @@ -134,7 +132,7 @@ def channelname(self):
Convert a Slack channel ID to its channel name
"""
channel_name_key = "name"
if self._channel_info["is_im"] is True:
if self._channel_info.get("is_im") is True:
channel_name_key = "user"

return self._channel_info[channel_name_key]
Expand Down

0 comments on commit e9b0b62

Please sign in to comment.