arcade-slack 1.0.0__py3-none-any.whl → 1.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,36 @@
1
+ from typing import Annotated, Any
2
+
3
+ from arcade_tdk import ToolContext, tool
4
+ from arcade_tdk.auth import Slack
5
+ from slack_sdk.web.async_client import AsyncWebClient
6
+
7
+ from arcade_slack.who_am_i_util import build_who_am_i_response
8
+
9
+
10
+ @tool(
11
+ requires_auth=Slack(
12
+ scopes=[
13
+ "users:read",
14
+ "users:read.email",
15
+ ]
16
+ )
17
+ )
18
+ async def who_am_i(
19
+ context: ToolContext,
20
+ ) -> Annotated[
21
+ dict[str, Any],
22
+ "Get comprehensive user profile and Slack information.",
23
+ ]:
24
+ """
25
+ Get comprehensive user profile and Slack information.
26
+
27
+ This tool provides detailed information about the authenticated user including
28
+ their name, email, profile picture, and other important profile details from
29
+ Slack services.
30
+ """
31
+
32
+ auth_token = context.get_auth_token_or_empty()
33
+ slack_client = AsyncWebClient(token=auth_token)
34
+ user_info = await build_who_am_i_response(context, slack_client)
35
+
36
+ return dict(user_info)
@@ -0,0 +1,122 @@
1
+ from typing import Any, TypedDict, cast
2
+
3
+ from slack_sdk.web.async_client import AsyncWebClient
4
+
5
+
6
+ class WhoAmIResponse(TypedDict, total=False):
7
+ user_id: str
8
+ username: str
9
+ display_name: str
10
+ real_name: str
11
+ email: str
12
+ profile_picture_url: str
13
+ title: str
14
+ phone: str
15
+ first_name: str
16
+ last_name: str
17
+ pronouns: str
18
+ status_text: str
19
+ status_emoji: str
20
+ slack_access: bool
21
+
22
+
23
+ async def build_who_am_i_response(context: Any, slack_client: AsyncWebClient) -> WhoAmIResponse:
24
+ """Build complete who_am_i response from Slack APIs."""
25
+ auth_token = context.get_auth_token_or_empty()
26
+
27
+ auth_info = await _get_auth_info(slack_client)
28
+
29
+ user_profile = await _get_user_profile(auth_token, auth_info["user_id"])
30
+
31
+ user_info: dict[str, Any] = {}
32
+ user_info.update(_extract_auth_info(auth_info))
33
+ user_info.update(_extract_user_profile(user_profile))
34
+
35
+ return cast(WhoAmIResponse, user_info)
36
+
37
+
38
+ async def _get_auth_info(slack_client: AsyncWebClient) -> dict[str, Any]:
39
+ """Get authentication information including user_id and team info."""
40
+ response = await slack_client.auth_test()
41
+ return cast(dict[str, Any], response.data)
42
+
43
+
44
+ async def _get_user_profile(auth_token: str, user_id: str) -> dict[str, Any]:
45
+ """Get detailed user profile information."""
46
+ slack_client = AsyncWebClient(token=auth_token)
47
+ response = await slack_client.users_info(user=user_id)
48
+ response_dict = cast(dict[str, Any], response)
49
+ if not response_dict.get("ok"):
50
+ error = response_dict.get("error", "Unknown error")
51
+ raise RuntimeError(f"Failed to get user info: {error}")
52
+ return cast(dict[str, Any], response_dict["user"])
53
+
54
+
55
+ def _extract_auth_info(auth_info: dict[str, Any]) -> dict[str, Any]:
56
+ """Extract authentication information."""
57
+ extracted = {}
58
+
59
+ if auth_info.get("user_id"):
60
+ extracted["user_id"] = auth_info["user_id"]
61
+ if auth_info.get("user"):
62
+ extracted["username"] = auth_info["user"]
63
+
64
+ extracted["slack_access"] = bool(auth_info.get("ok"))
65
+
66
+ return extracted
67
+
68
+
69
+ def _extract_user_profile(user_profile: dict[str, Any]) -> dict[str, Any]:
70
+ """Extract user profile information."""
71
+ extracted = {}
72
+
73
+ if user_profile.get("real_name"):
74
+ extracted["real_name"] = user_profile["real_name"]
75
+ if user_profile.get("name"):
76
+ extracted["username"] = user_profile["name"]
77
+
78
+ profile = user_profile.get("profile", {})
79
+ extracted.update(_extract_profile_fields(profile))
80
+ extracted.update(_extract_profile_picture(profile))
81
+
82
+ return extracted
83
+
84
+
85
+ def _extract_profile_fields(profile: dict[str, Any]) -> dict[str, Any]:
86
+ """Extract profile fields from user profile."""
87
+ extracted = {}
88
+
89
+ fields = [
90
+ ("display_name", "display_name"),
91
+ ("real_name", "real_name"),
92
+ ("email", "email"),
93
+ ("title", "title"),
94
+ ("phone", "phone"),
95
+ ("first_name", "first_name"),
96
+ ("last_name", "last_name"),
97
+ ("pronouns", "pronouns"),
98
+ ("status_text", "status_text"),
99
+ ("status_emoji", "status_emoji"),
100
+ ]
101
+
102
+ for profile_key, extracted_key in fields:
103
+ if profile.get(profile_key):
104
+ extracted[extracted_key] = profile[profile_key]
105
+
106
+ return extracted
107
+
108
+
109
+ def _extract_profile_picture(profile: dict[str, Any]) -> dict[str, Any]:
110
+ """Extract profile picture URL from user profile."""
111
+ for size in [
112
+ "image_1024",
113
+ "image_512",
114
+ "image_192",
115
+ "image_72",
116
+ "image_48",
117
+ "image_32",
118
+ "image_24",
119
+ ]:
120
+ if profile.get(size):
121
+ return {"profile_picture_url": profile[size]}
122
+ return {}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: arcade_slack
3
- Version: 1.0.0
3
+ Version: 1.1.0
4
4
  Summary: Arcade.dev LLM tools for Slack
5
5
  Author-email: Arcade <dev@arcade.dev>
6
6
  License: Proprietary - Arcade Software License Agreement v1.0
@@ -8,10 +8,12 @@ arcade_slack/message_retrieval.py,sha256=XdzWLJdKtc5DL7H_qQBei6qJ-rz2uGs-Q0HfYqx
8
8
  arcade_slack/models.py,sha256=-zlkAxaDNEcIkQqePYTZXAqcRX4gO5jocJIixeWpK7A,12213
9
9
  arcade_slack/user_retrieval.py,sha256=cdfzBbm2fsVNCztt2XbIV2UKuCdHaotfFBdo10EpBcE,6774
10
10
  arcade_slack/utils.py,sha256=z6G7GCDXn_7_TshQRx-rnhgmQG8eCQSND5It9_uvhmE,21776
11
+ arcade_slack/who_am_i_util.py,sha256=Nf6EdRiURva5jMhVx1lFOoKQ-2SuMwjXYbPCmtj6Zcw,3670
11
12
  arcade_slack/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
13
  arcade_slack/tools/chat.py,sha256=KWDalEiOhay4Z71EB97dVllm3Uo7sXxjXFfmcpvuWYE,38125
14
+ arcade_slack/tools/system_context.py,sha256=l2gZh_WhrIVL2LzttGAz5yiv0Cl6q_6AFyBBUBskz3E,961
13
15
  arcade_slack/tools/users.py,sha256=Kw3MWNOwuUY17X5HGf3JMAH_mfloLRdRzXSBC7Zo7ug,4233
14
- arcade_slack-1.0.0.dist-info/METADATA,sha256=zQpW_DaNQ_t9YEFDhXdt2C6WeG9GC686DbJEjua7meQ,1015
15
- arcade_slack-1.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
- arcade_slack-1.0.0.dist-info/licenses/LICENSE,sha256=ixeE7aL9b2B-_ZYHTY1vQcJB4NufKeo-LWwKNObGDN0,1960
17
- arcade_slack-1.0.0.dist-info/RECORD,,
16
+ arcade_slack-1.1.0.dist-info/METADATA,sha256=7xIdWupyKsoxoT8kgUBoJh-m72gSIa8NdH8IP8OTIhE,1015
17
+ arcade_slack-1.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
18
+ arcade_slack-1.1.0.dist-info/licenses/LICENSE,sha256=ixeE7aL9b2B-_ZYHTY1vQcJB4NufKeo-LWwKNObGDN0,1960
19
+ arcade_slack-1.1.0.dist-info/RECORD,,