Module: Slk::Support::UserResolver
- Included in:
- Commands::Catchup, Commands::Unread
- Defined in:
- lib/slk/support/user_resolver.rb
Overview
Shared logic for resolving user and channel names from Slack data. Include this module in commands that need to look up user/channel names.
Required Interface
Including classes must provide these methods:
-
runner: Returns the Runner instance for API access
-
cache_store: Returns the CacheStore for name lookups
-
debug(message): Logs debug messages (can be a no-op)
Instance Method Summary collapse
-
#extract_user_from_message(msg, workspace) ⇒ String
Extracts the user name from a message hash.
-
#resolve_conversation_label(workspace, channel_id) ⇒ String
Resolves a channel ID to a formatted label (@username or #channel).
-
#resolve_dm_user_name(workspace, channel_id, conversations) ⇒ String
Resolves a DM channel ID to the user’s display name.
Instance Method Details
#extract_user_from_message(msg, workspace) ⇒ String
Extracts the user name from a message hash
84 85 86 87 88 89 |
# File 'lib/slk/support/user_resolver.rb', line 84 def (msg, workspace) name_from_user_profile(msg) || name_from_username(msg) || name_from_cache(msg, workspace) || msg['user'] || msg['bot_id'] || 'unknown' end |
#resolve_conversation_label(workspace, channel_id) ⇒ String
Resolves a channel ID to a formatted label (@username or #channel)
74 75 76 77 78 |
# File 'lib/slk/support/user_resolver.rb', line 74 def resolve_conversation_label(workspace, channel_id) return resolve_dm_label(workspace, channel_id) if channel_id.start_with?('D') resolve_channel_label(workspace, channel_id) end |
#resolve_dm_user_name(workspace, channel_id, conversations) ⇒ String
Resolves a DM channel ID to the user’s display name
19 20 21 22 23 24 25 26 27 |
# File 'lib/slk/support/user_resolver.rb', line 19 def resolve_dm_user_name(workspace, channel_id, conversations) user_id = get_dm_user_id(channel_id, conversations) return channel_id unless user_id lookup_user_name(workspace, user_id) || user_id rescue ApiError => e debug("DM info lookup failed for #{channel_id}: #{e.}") channel_id end |