44
55from slack_sdk import WebClient
66from slack_sdk .errors import SlackApiError
7+ from sqlalchemy .orm import Session
78
89from slack_clacks .messaging .exceptions import (
910 ClacksChannelNotFoundError ,
1011 ClacksUserNotFoundError ,
1112)
1213
1314
14- def resolve_channel_id (client : WebClient , channel_identifier : str ) -> str :
15+ def resolve_channel_id (
16+ client : WebClient ,
17+ channel_identifier : str ,
18+ session : Session | None = None ,
19+ context_name : str | None = None ,
20+ ) -> str :
1521 """
1622 Resolve channel identifier to channel ID.
17- Accepts channel ID (C...), channel name (#general or general).
23+ Accepts channel ID (C..., D..., G... ), channel name (#general or general), or alias .
1824 Returns channel ID or raises ClacksChannelNotFoundError if not found.
25+
26+ Resolution order:
27+ 1. Check if already a Slack channel ID (C..., D..., G...)
28+ 2. Check aliases (if session and context_name provided)
29+ 3. Fall back to Slack API
1930 """
20- if channel_identifier .startswith ("C" ) or channel_identifier . startswith ( "D" ):
31+ if channel_identifier .startswith (( "C" , "D" , "G" ) ):
2132 return channel_identifier
2233
2334 channel_name = channel_identifier .lstrip ("#" )
2435
25- # TODO(zomglings): Implement pagination via response_metadata.next_cursor
26- # Currently only searches first page (up to 1000 channels)
27- # Plan: Cache channel list in database to avoid repeated API calls
36+ # Check aliases first (requires context for security)
37+ if session is not None and context_name is not None :
38+ from slack_clacks .rolodex .operations import resolve_alias
39+
40+ alias = resolve_alias (session , channel_name , context_name , "channel" , "slack" )
41+ if alias :
42+ return alias .target_id
43+
44+ # Fall back to API call
2845 try :
2946 response = client .conversations_list (
3047 types = "public_channel,private_channel" , limit = 1000
@@ -38,20 +55,36 @@ def resolve_channel_id(client: WebClient, channel_identifier: str) -> str:
3855 raise ClacksChannelNotFoundError (channel_identifier )
3956
4057
41- def resolve_user_id (client : WebClient , user_identifier : str ) -> str :
58+ def resolve_user_id (
59+ client : WebClient ,
60+ user_identifier : str ,
61+ session : Session | None = None ,
62+ context_name : str | None = None ,
63+ ) -> str :
4264 """
4365 Resolve user identifier to user ID.
44- Accepts user ID (U...), username (@username or username), or email .
66+ Accepts user ID (U...), username (@username or username), email, or alias .
4567 Returns user ID or raises ClacksUserNotFoundError if not found.
68+
69+ Resolution order:
70+ 1. Check if already a Slack user ID (U...)
71+ 2. Check aliases (if session and context_name provided)
72+ 3. Fall back to Slack API
4673 """
4774 if user_identifier .startswith ("U" ):
4875 return user_identifier
4976
5077 username = user_identifier .lstrip ("@" )
5178
52- # TODO(zomglings): Implement pagination via response_metadata.next_cursor
53- # Currently only searches first page (100-200 users depending on tier)
54- # Plan: Cache user list in database to avoid repeated API calls
79+ # Check aliases first (requires context for security)
80+ if session is not None and context_name is not None :
81+ from slack_clacks .rolodex .operations import resolve_alias
82+
83+ alias = resolve_alias (session , username , context_name , "user" , "slack" )
84+ if alias :
85+ return alias .target_id
86+
87+ # Fall back to API call
5588 try :
5689 response = client .users_list ()
5790 for user in response ["members" ]:
0 commit comments