agent-messenger 2.0.0 → 2.2.0

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.
Files changed (272) hide show
  1. package/.claude-plugin/marketplace.json +14 -1
  2. package/.claude-plugin/plugin.json +4 -2
  3. package/.env.template +35 -17
  4. package/README.md +37 -33
  5. package/bun.lock +6 -6
  6. package/dist/package.json +11 -3
  7. package/dist/src/cli.d.ts.map +1 -1
  8. package/dist/src/cli.js +3 -0
  9. package/dist/src/cli.js.map +1 -1
  10. package/dist/src/platforms/channeltalk/commands/auth.d.ts.map +1 -1
  11. package/dist/src/platforms/channeltalk/commands/auth.js +35 -28
  12. package/dist/src/platforms/channeltalk/commands/auth.js.map +1 -1
  13. package/dist/src/platforms/channeltalk/ensure-auth.js +6 -6
  14. package/dist/src/platforms/channeltalk/ensure-auth.js.map +1 -1
  15. package/dist/src/platforms/channeltalk/token-extractor.d.ts +23 -1
  16. package/dist/src/platforms/channeltalk/token-extractor.d.ts.map +1 -1
  17. package/dist/src/platforms/channeltalk/token-extractor.js +299 -29
  18. package/dist/src/platforms/channeltalk/token-extractor.js.map +1 -1
  19. package/dist/src/platforms/discord/commands/auth.d.ts.map +1 -1
  20. package/dist/src/platforms/discord/commands/auth.js +57 -49
  21. package/dist/src/platforms/discord/commands/auth.js.map +1 -1
  22. package/dist/src/platforms/discord/ensure-auth.js +3 -3
  23. package/dist/src/platforms/discord/ensure-auth.js.map +1 -1
  24. package/dist/src/platforms/discord/token-extractor.d.ts +6 -1
  25. package/dist/src/platforms/discord/token-extractor.d.ts.map +1 -1
  26. package/dist/src/platforms/discord/token-extractor.js +167 -14
  27. package/dist/src/platforms/discord/token-extractor.js.map +1 -1
  28. package/dist/src/platforms/instagram/client.d.ts +2 -0
  29. package/dist/src/platforms/instagram/client.d.ts.map +1 -1
  30. package/dist/src/platforms/instagram/client.js +2 -2
  31. package/dist/src/platforms/instagram/client.js.map +1 -1
  32. package/dist/src/platforms/instagram/commands/auth.d.ts.map +1 -1
  33. package/dist/src/platforms/instagram/commands/auth.js +107 -14
  34. package/dist/src/platforms/instagram/commands/auth.js.map +1 -1
  35. package/dist/src/platforms/instagram/ensure-auth.d.ts.map +1 -1
  36. package/dist/src/platforms/instagram/ensure-auth.js +57 -11
  37. package/dist/src/platforms/instagram/ensure-auth.js.map +1 -1
  38. package/dist/src/platforms/instagram/index.d.ts +1 -0
  39. package/dist/src/platforms/instagram/index.d.ts.map +1 -1
  40. package/dist/src/platforms/instagram/index.js +1 -0
  41. package/dist/src/platforms/instagram/index.js.map +1 -1
  42. package/dist/src/platforms/instagram/token-extractor.d.ts +44 -0
  43. package/dist/src/platforms/instagram/token-extractor.d.ts.map +1 -0
  44. package/dist/src/platforms/instagram/token-extractor.js +407 -0
  45. package/dist/src/platforms/instagram/token-extractor.js.map +1 -0
  46. package/dist/src/platforms/kakaotalk/client.d.ts.map +1 -1
  47. package/dist/src/platforms/kakaotalk/client.js +2 -1
  48. package/dist/src/platforms/kakaotalk/client.js.map +1 -1
  49. package/dist/src/platforms/kakaotalk/commands/auth.d.ts.map +1 -1
  50. package/dist/src/platforms/kakaotalk/commands/auth.js +14 -13
  51. package/dist/src/platforms/kakaotalk/commands/auth.js.map +1 -1
  52. package/dist/src/platforms/kakaotalk/protocol/connection.d.ts.map +1 -1
  53. package/dist/src/platforms/kakaotalk/protocol/connection.js +2 -1
  54. package/dist/src/platforms/kakaotalk/protocol/connection.js.map +1 -1
  55. package/dist/src/platforms/line/commands/auth.d.ts.map +1 -1
  56. package/dist/src/platforms/line/commands/auth.js +6 -5
  57. package/dist/src/platforms/line/commands/auth.js.map +1 -1
  58. package/dist/src/platforms/slack/commands/auth.d.ts.map +1 -1
  59. package/dist/src/platforms/slack/commands/auth.js +11 -10
  60. package/dist/src/platforms/slack/commands/auth.js.map +1 -1
  61. package/dist/src/platforms/slack/token-extractor.d.ts +9 -0
  62. package/dist/src/platforms/slack/token-extractor.d.ts.map +1 -1
  63. package/dist/src/platforms/slack/token-extractor.js +300 -23
  64. package/dist/src/platforms/slack/token-extractor.js.map +1 -1
  65. package/dist/src/platforms/teams/commands/auth.d.ts.map +1 -1
  66. package/dist/src/platforms/teams/commands/auth.js +9 -8
  67. package/dist/src/platforms/teams/commands/auth.js.map +1 -1
  68. package/dist/src/platforms/teams/ensure-auth.d.ts.map +1 -1
  69. package/dist/src/platforms/teams/ensure-auth.js +2 -1
  70. package/dist/src/platforms/teams/ensure-auth.js.map +1 -1
  71. package/dist/src/platforms/teams/token-extractor.d.ts +5 -0
  72. package/dist/src/platforms/teams/token-extractor.d.ts.map +1 -1
  73. package/dist/src/platforms/teams/token-extractor.js +161 -29
  74. package/dist/src/platforms/teams/token-extractor.js.map +1 -1
  75. package/dist/src/platforms/telegram/client.d.ts.map +1 -1
  76. package/dist/src/platforms/telegram/client.js +25 -7
  77. package/dist/src/platforms/telegram/client.js.map +1 -1
  78. package/dist/src/platforms/telegram/commands/auth.d.ts.map +1 -1
  79. package/dist/src/platforms/telegram/commands/auth.js +6 -5
  80. package/dist/src/platforms/telegram/commands/auth.js.map +1 -1
  81. package/dist/src/platforms/webex/app-config.d.ts +7 -0
  82. package/dist/src/platforms/webex/app-config.d.ts.map +1 -0
  83. package/dist/src/platforms/webex/app-config.js +20 -0
  84. package/dist/src/platforms/webex/app-config.js.map +1 -0
  85. package/dist/src/platforms/webex/cli.d.ts +5 -0
  86. package/dist/src/platforms/webex/cli.d.ts.map +1 -0
  87. package/dist/src/platforms/webex/cli.js +32 -0
  88. package/dist/src/platforms/webex/cli.js.map +1 -0
  89. package/dist/src/platforms/webex/client.d.ts +55 -0
  90. package/dist/src/platforms/webex/client.d.ts.map +1 -0
  91. package/dist/src/platforms/webex/client.js +299 -0
  92. package/dist/src/platforms/webex/client.js.map +1 -0
  93. package/dist/src/platforms/webex/commands/auth.d.ts +19 -0
  94. package/dist/src/platforms/webex/commands/auth.d.ts.map +1 -0
  95. package/dist/src/platforms/webex/commands/auth.js +166 -0
  96. package/dist/src/platforms/webex/commands/auth.js.map +1 -0
  97. package/dist/src/platforms/webex/commands/index.d.ts +6 -0
  98. package/dist/src/platforms/webex/commands/index.d.ts.map +1 -0
  99. package/dist/src/platforms/webex/commands/index.js +6 -0
  100. package/dist/src/platforms/webex/commands/index.js.map +1 -0
  101. package/dist/src/platforms/webex/commands/member.d.ts +7 -0
  102. package/dist/src/platforms/webex/commands/member.d.ts.map +1 -0
  103. package/dist/src/platforms/webex/commands/member.js +34 -0
  104. package/dist/src/platforms/webex/commands/member.js.map +1 -0
  105. package/dist/src/platforms/webex/commands/message.d.ts +26 -0
  106. package/dist/src/platforms/webex/commands/message.d.ts.map +1 -0
  107. package/dist/src/platforms/webex/commands/message.js +153 -0
  108. package/dist/src/platforms/webex/commands/message.js.map +1 -0
  109. package/dist/src/platforms/webex/commands/snapshot.d.ts +9 -0
  110. package/dist/src/platforms/webex/commands/snapshot.d.ts.map +1 -0
  111. package/dist/src/platforms/webex/commands/snapshot.js +72 -0
  112. package/dist/src/platforms/webex/commands/snapshot.js.map +1 -0
  113. package/dist/src/platforms/webex/commands/space.d.ts +11 -0
  114. package/dist/src/platforms/webex/commands/space.d.ts.map +1 -0
  115. package/dist/src/platforms/webex/commands/space.js +59 -0
  116. package/dist/src/platforms/webex/commands/space.js.map +1 -0
  117. package/dist/src/platforms/webex/credential-manager.d.ts +23 -0
  118. package/dist/src/platforms/webex/credential-manager.d.ts.map +1 -0
  119. package/dist/src/platforms/webex/credential-manager.js +148 -0
  120. package/dist/src/platforms/webex/credential-manager.js.map +1 -0
  121. package/dist/src/platforms/webex/ensure-auth.d.ts +2 -0
  122. package/dist/src/platforms/webex/ensure-auth.d.ts.map +1 -0
  123. package/dist/src/platforms/webex/ensure-auth.js +36 -0
  124. package/dist/src/platforms/webex/ensure-auth.js.map +1 -0
  125. package/dist/src/platforms/webex/index.d.ts +8 -0
  126. package/dist/src/platforms/webex/index.d.ts.map +1 -0
  127. package/dist/src/platforms/webex/index.js +6 -0
  128. package/dist/src/platforms/webex/index.js.map +1 -0
  129. package/dist/src/platforms/webex/token-extractor.d.ts +28 -0
  130. package/dist/src/platforms/webex/token-extractor.d.ts.map +1 -0
  131. package/dist/src/platforms/webex/token-extractor.js +344 -0
  132. package/dist/src/platforms/webex/token-extractor.js.map +1 -0
  133. package/dist/src/platforms/webex/types.d.ts +127 -0
  134. package/dist/src/platforms/webex/types.d.ts.map +1 -0
  135. package/dist/src/platforms/webex/types.js +64 -0
  136. package/dist/src/platforms/webex/types.js.map +1 -0
  137. package/dist/src/platforms/whatsapp/client.d.ts.map +1 -1
  138. package/dist/src/platforms/whatsapp/client.js +6 -2
  139. package/dist/src/platforms/whatsapp/client.js.map +1 -1
  140. package/dist/src/shared/utils/derived-key-cache.d.ts +1 -1
  141. package/dist/src/shared/utils/derived-key-cache.d.ts.map +1 -1
  142. package/dist/src/shared/utils/error-handler.d.ts +1 -1
  143. package/dist/src/shared/utils/error-handler.d.ts.map +1 -1
  144. package/dist/src/shared/utils/error-handler.js +3 -2
  145. package/dist/src/shared/utils/error-handler.js.map +1 -1
  146. package/dist/src/shared/utils/stderr.d.ts +5 -0
  147. package/dist/src/shared/utils/stderr.d.ts.map +1 -0
  148. package/dist/src/shared/utils/stderr.js +18 -0
  149. package/dist/src/shared/utils/stderr.js.map +1 -0
  150. package/dist/src/tui/adapters/webex-adapter.d.ts +14 -0
  151. package/dist/src/tui/adapters/webex-adapter.d.ts.map +1 -0
  152. package/dist/src/tui/adapters/webex-adapter.js +79 -0
  153. package/dist/src/tui/adapters/webex-adapter.js.map +1 -0
  154. package/dist/src/tui/app.d.ts.map +1 -1
  155. package/dist/src/tui/app.js +2 -0
  156. package/dist/src/tui/app.js.map +1 -1
  157. package/docs/content/docs/cli/channeltalk.mdx +7 -7
  158. package/docs/content/docs/cli/discord.mdx +3 -3
  159. package/docs/content/docs/cli/instagram.mdx +28 -6
  160. package/docs/content/docs/cli/meta.json +1 -0
  161. package/docs/content/docs/cli/slack.mdx +2 -2
  162. package/docs/content/docs/cli/teams.mdx +6 -4
  163. package/docs/content/docs/cli/webex.mdx +310 -0
  164. package/docs/content/docs/sdk/meta.json +1 -1
  165. package/docs/content/docs/sdk/webex.mdx +260 -0
  166. package/docs/content/docs/tui.mdx +4 -3
  167. package/docs/src/app/page.tsx +2 -2
  168. package/e2e/README.md +132 -8
  169. package/e2e/channeltalk.e2e.test.ts +2 -7
  170. package/e2e/channeltalkbot.e2e.test.ts +2 -6
  171. package/e2e/config.ts +172 -10
  172. package/e2e/helpers.ts +7 -0
  173. package/e2e/instagram.e2e.test.ts +97 -0
  174. package/e2e/kakaotalk.e2e.test.ts +74 -0
  175. package/e2e/line.e2e.test.ts +92 -0
  176. package/e2e/teams.e2e.test.ts +46 -1
  177. package/e2e/telegram.e2e.test.ts +84 -0
  178. package/e2e/webex.e2e.test.ts +190 -0
  179. package/e2e/whatsapp.e2e.test.ts +90 -0
  180. package/e2e/whatsappbot.e2e.test.ts +78 -0
  181. package/package.json +11 -3
  182. package/skills/agent-channeltalk/SKILL.md +9 -9
  183. package/skills/agent-channeltalk/references/authentication.md +21 -18
  184. package/skills/agent-channeltalkbot/SKILL.md +1 -1
  185. package/skills/agent-discord/SKILL.md +5 -5
  186. package/skills/agent-discord/references/authentication.md +8 -8
  187. package/skills/agent-discordbot/SKILL.md +1 -1
  188. package/skills/agent-instagram/SKILL.md +51 -9
  189. package/skills/agent-instagram/references/authentication.md +35 -3
  190. package/skills/agent-kakaotalk/SKILL.md +1 -1
  191. package/skills/agent-line/SKILL.md +1 -1
  192. package/skills/agent-slack/SKILL.md +5 -5
  193. package/skills/agent-slack/references/authentication.md +8 -8
  194. package/skills/agent-slackbot/SKILL.md +1 -1
  195. package/skills/agent-teams/SKILL.md +6 -6
  196. package/skills/agent-teams/references/authentication.md +8 -8
  197. package/skills/agent-telegram/SKILL.md +1 -1
  198. package/skills/agent-webex/SKILL.md +406 -0
  199. package/skills/agent-webex/references/authentication.md +371 -0
  200. package/skills/agent-webex/references/common-patterns.md +726 -0
  201. package/skills/agent-webex/templates/monitor-space.sh +165 -0
  202. package/skills/agent-webex/templates/post-message.sh +170 -0
  203. package/skills/agent-whatsapp/SKILL.md +1 -1
  204. package/skills/agent-whatsappbot/SKILL.md +1 -1
  205. package/src/cli.ts +4 -0
  206. package/src/platforms/channeltalk/commands/auth.test.ts +5 -5
  207. package/src/platforms/channeltalk/commands/auth.ts +38 -32
  208. package/src/platforms/channeltalk/ensure-auth.test.ts +6 -6
  209. package/src/platforms/channeltalk/ensure-auth.ts +6 -6
  210. package/src/platforms/channeltalk/token-extractor.test.ts +182 -15
  211. package/src/platforms/channeltalk/token-extractor.ts +344 -30
  212. package/src/platforms/discord/commands/auth.test.ts +3 -3
  213. package/src/platforms/discord/commands/auth.ts +58 -54
  214. package/src/platforms/discord/ensure-auth.test.ts +3 -3
  215. package/src/platforms/discord/ensure-auth.ts +3 -3
  216. package/src/platforms/discord/token-extractor.test.ts +199 -27
  217. package/src/platforms/discord/token-extractor.ts +190 -17
  218. package/src/platforms/instagram/client.ts +2 -2
  219. package/src/platforms/instagram/commands/auth.ts +133 -14
  220. package/src/platforms/instagram/ensure-auth.ts +63 -12
  221. package/src/platforms/instagram/index.ts +1 -0
  222. package/src/platforms/instagram/token-extractor.test.ts +424 -0
  223. package/src/platforms/instagram/token-extractor.ts +478 -0
  224. package/src/platforms/kakaotalk/client.ts +3 -1
  225. package/src/platforms/kakaotalk/commands/auth.ts +14 -13
  226. package/src/platforms/kakaotalk/protocol/connection.ts +3 -1
  227. package/src/platforms/line/commands/auth.ts +7 -6
  228. package/src/platforms/slack/cli.test.ts +6 -5
  229. package/src/platforms/slack/commands/auth.test.ts +11 -7
  230. package/src/platforms/slack/commands/auth.ts +11 -10
  231. package/src/platforms/slack/token-extractor.test.ts +98 -1
  232. package/src/platforms/slack/token-extractor.ts +338 -26
  233. package/src/platforms/teams/commands/auth.ts +9 -8
  234. package/src/platforms/teams/ensure-auth.ts +3 -1
  235. package/src/platforms/teams/token-extractor.test.ts +136 -17
  236. package/src/platforms/teams/token-extractor.ts +182 -31
  237. package/src/platforms/telegram/client.test.ts +134 -0
  238. package/src/platforms/telegram/client.ts +27 -6
  239. package/src/platforms/telegram/commands/auth.ts +6 -5
  240. package/src/platforms/webex/app-config.test.ts +98 -0
  241. package/src/platforms/webex/app-config.ts +31 -0
  242. package/src/platforms/webex/cli.test.ts +58 -0
  243. package/src/platforms/webex/cli.ts +39 -0
  244. package/src/platforms/webex/client.test.ts +743 -0
  245. package/src/platforms/webex/client.ts +405 -0
  246. package/src/platforms/webex/commands/auth.test.ts +222 -0
  247. package/src/platforms/webex/commands/auth.ts +243 -0
  248. package/src/platforms/webex/commands/index.ts +5 -0
  249. package/src/platforms/webex/commands/member.test.ts +112 -0
  250. package/src/platforms/webex/commands/member.ts +45 -0
  251. package/src/platforms/webex/commands/message.test.ts +235 -0
  252. package/src/platforms/webex/commands/message.ts +204 -0
  253. package/src/platforms/webex/commands/snapshot.test.ts +105 -0
  254. package/src/platforms/webex/commands/snapshot.ts +91 -0
  255. package/src/platforms/webex/commands/space.test.ts +216 -0
  256. package/src/platforms/webex/commands/space.ts +74 -0
  257. package/src/platforms/webex/credential-manager.test.ts +314 -0
  258. package/src/platforms/webex/credential-manager.ts +197 -0
  259. package/src/platforms/webex/ensure-auth.test.ts +89 -0
  260. package/src/platforms/webex/ensure-auth.ts +38 -0
  261. package/src/platforms/webex/index.test.ts +25 -0
  262. package/src/platforms/webex/index.ts +19 -0
  263. package/src/platforms/webex/token-extractor.test.ts +327 -0
  264. package/src/platforms/webex/token-extractor.ts +393 -0
  265. package/src/platforms/webex/types.test.ts +307 -0
  266. package/src/platforms/webex/types.ts +129 -0
  267. package/src/platforms/whatsapp/client.ts +11 -7
  268. package/src/shared/utils/derived-key-cache.ts +1 -1
  269. package/src/shared/utils/error-handler.ts +4 -2
  270. package/src/shared/utils/stderr.ts +22 -0
  271. package/src/tui/adapters/webex-adapter.ts +103 -0
  272. package/src/tui/app.ts +2 -0
@@ -0,0 +1,726 @@
1
+ # Common Patterns
2
+
3
+ ## Overview
4
+
5
+ This guide covers typical workflows for AI agents interacting with Cisco Webex using agent-webex.
6
+
7
+ **Note**: Webex uses opaque Base64-encoded IDs for spaces, messages, and people. You can't guess them. Always get IDs from `space list` or `member list` first.
8
+
9
+ ## Auth Patterns
10
+
11
+ ### Pattern 1: Authenticate
12
+
13
+ **Use case**: First-time setup or token renewal
14
+
15
+ ```bash
16
+ #!/bin/bash
17
+
18
+ # Recommended: Browser extraction (zero-config, sends as you, no "via" label)
19
+ agent-webex auth extract
20
+
21
+ # Fallback: Device Grant (zero-config, opens browser, shows "via agent-messenger")
22
+ agent-webex auth login
23
+
24
+ # With a bot token (never expires, for CI/CD)
25
+ agent-webex auth login --token "YOUR_BOT_TOKEN_HERE"
26
+
27
+ # With a PAT (12-hour lifetime, for quick testing)
28
+ agent-webex auth login --token "YOUR_PAT_HERE"
29
+ ```
30
+
31
+ **When to use**: Before any other command, if not already authenticated. Browser extraction is preferred — it auto-runs when no valid token is stored.
32
+
33
+ ### Pattern 2: Check Auth Status
34
+
35
+ **Use case**: Verify authentication before running operations
36
+
37
+ ```bash
38
+ #!/bin/bash
39
+
40
+ STATUS=$(agent-webex auth status)
41
+
42
+ if echo "$STATUS" | jq -e '.error' > /dev/null 2>&1; then
43
+ echo "Not authenticated. Run 'auth login' first."
44
+ exit 1
45
+ fi
46
+
47
+ USER=$(echo "$STATUS" | jq -r '.displayName')
48
+ echo "Authenticated as: $USER"
49
+ ```
50
+
51
+ **When to use**: Start of any script or workflow.
52
+
53
+ ### Pattern 3: Log Out
54
+
55
+ **Use case**: Remove stored credentials
56
+
57
+ ```bash
58
+ #!/bin/bash
59
+
60
+ agent-webex auth logout
61
+ ```
62
+
63
+ **When to use**: Switching accounts, cleaning up, or revoking access.
64
+
65
+ ### Pattern 4: Send a Direct Message
66
+
67
+ **Use case**: Message someone directly by email, without finding a space ID first
68
+
69
+ ```bash
70
+ #!/bin/bash
71
+
72
+ # Send a DM by email
73
+ agent-webex message dm alice@example.com "Hey, quick question about the PR"
74
+
75
+ # Send a DM with markdown
76
+ agent-webex message dm alice@example.com "**Build failed** - can you check?" --markdown
77
+ ```
78
+
79
+ **When to use**: Quick 1:1 messages when you know the recipient's email.
80
+
81
+ ## Space Patterns
82
+
83
+ ### Pattern 5: List All Spaces
84
+
85
+ **Use case**: Discover available spaces
86
+
87
+ ```bash
88
+ #!/bin/bash
89
+
90
+ # List all spaces
91
+ SPACES=$(agent-webex space list)
92
+ echo "$SPACES" | jq -r '.[] | "\(.title) (\(.id))"'
93
+ ```
94
+
95
+ ### Pattern 6: Filter Spaces by Type
96
+
97
+ **Use case**: Show only group spaces or direct messages
98
+
99
+ ```bash
100
+ #!/bin/bash
101
+
102
+ # Group spaces only
103
+ agent-webex space list --type group
104
+
105
+ # Direct messages only
106
+ agent-webex space list --type direct
107
+
108
+ # Limit results
109
+ agent-webex space list --type group --limit 10
110
+ ```
111
+
112
+ ### Pattern 7: Get Space Info
113
+
114
+ **Use case**: Look up details for a specific space
115
+
116
+ ```bash
117
+ #!/bin/bash
118
+
119
+ SPACE_ID="Y2lzY29zcGFyazovL..."
120
+
121
+ INFO=$(agent-webex space info "$SPACE_ID")
122
+ TITLE=$(echo "$INFO" | jq -r '.title')
123
+ TYPE=$(echo "$INFO" | jq -r '.type')
124
+
125
+ echo "Space: $TITLE ($TYPE)"
126
+ ```
127
+
128
+ ### Pattern 8: Find Space by Title
129
+
130
+ **Use case**: Get a space ID from its title
131
+
132
+ ```bash
133
+ #!/bin/bash
134
+
135
+ find_space_id() {
136
+ local title=$1
137
+
138
+ SPACES=$(agent-webex space list)
139
+ SPACE_ID=$(echo "$SPACES" | jq -r --arg t "$title" '.[] | select(.title==$t) | .id')
140
+
141
+ if [ -z "$SPACE_ID" ]; then
142
+ echo "Space '$title' not found" >&2
143
+ return 1
144
+ fi
145
+
146
+ echo "$SPACE_ID"
147
+ }
148
+
149
+ # Usage
150
+ ENG_ID=$(find_space_id "Engineering")
151
+ if [ $? -eq 0 ]; then
152
+ agent-webex message send "$ENG_ID" "Hello Engineering!"
153
+ fi
154
+ ```
155
+
156
+ **When to use**: When you know the space title but need the ID.
157
+
158
+ ## Message Patterns
159
+
160
+ ### Pattern 9: Send a Simple Message
161
+
162
+ **Use case**: Post a notification or update
163
+
164
+ ```bash
165
+ #!/bin/bash
166
+
167
+ SPACE_ID="Y2lzY29zcGFyazovL..."
168
+
169
+ RESULT=$(agent-webex message send "$SPACE_ID" "Deployment completed successfully!")
170
+
171
+ if echo "$RESULT" | jq -e '.id' > /dev/null 2>&1; then
172
+ echo "Message sent!"
173
+ else
174
+ echo "Failed: $(echo "$RESULT" | jq -r '.error')"
175
+ exit 1
176
+ fi
177
+ ```
178
+
179
+ ### Pattern 10: Send a Markdown Message
180
+
181
+ **Use case**: Rich formatting in messages
182
+
183
+ ```bash
184
+ #!/bin/bash
185
+
186
+ SPACE_ID="Y2lzY29zcGFyazovL..."
187
+
188
+ agent-webex message send "$SPACE_ID" "**Build Status**
189
+ - Branch: \`main\`
190
+ - Tests: 142 passed, 0 failed
191
+ - Coverage: 94.2%" --markdown
192
+ ```
193
+
194
+ ### Pattern 11: List Recent Messages
195
+
196
+ **Use case**: Read conversation history
197
+
198
+ ```bash
199
+ #!/bin/bash
200
+
201
+ SPACE_ID="Y2lzY29zcGFyazovL..."
202
+
203
+ # Get last 10 messages
204
+ MESSAGES=$(agent-webex message list "$SPACE_ID" --limit 10)
205
+
206
+ echo "$MESSAGES" | jq -r '.[] | "[\(.created)] \(.personEmail): \(.text)"'
207
+ ```
208
+
209
+ ### Pattern 12: Get a Specific Message
210
+
211
+ **Use case**: Retrieve a message by ID
212
+
213
+ ```bash
214
+ #!/bin/bash
215
+
216
+ MESSAGE_ID="Y2lzY29zcGFyazovL..."
217
+
218
+ MSG=$(agent-webex message get "$MESSAGE_ID")
219
+ echo "$MSG" | jq -r '.text'
220
+ ```
221
+
222
+ ### Pattern 13: Delete a Message
223
+
224
+ **Use case**: Remove a message (your own or as moderator)
225
+
226
+ ```bash
227
+ #!/bin/bash
228
+
229
+ MESSAGE_ID="Y2lzY29zcGFyazovL..."
230
+
231
+ # With confirmation prompt
232
+ agent-webex message delete "$MESSAGE_ID"
233
+
234
+ # Skip confirmation
235
+ agent-webex message delete "$MESSAGE_ID" --force
236
+ ```
237
+
238
+ ### Pattern 14: Edit a Message
239
+
240
+ **Use case**: Update an existing message
241
+
242
+ ```bash
243
+ #!/bin/bash
244
+
245
+ MESSAGE_ID="Y2lzY29zcGFyazovL..."
246
+ SPACE_ID="Y2lzY29zcGFyazovL..."
247
+
248
+ agent-webex message edit "$MESSAGE_ID" "$SPACE_ID" "Updated: all systems operational"
249
+
250
+ # With markdown
251
+ agent-webex message edit "$MESSAGE_ID" "$SPACE_ID" "**Updated**: all systems operational" --markdown
252
+ ```
253
+
254
+ ### Pattern 15: Send and Track a Message
255
+
256
+ **Use case**: Send a message and save its ID for later editing or deletion
257
+
258
+ ```bash
259
+ #!/bin/bash
260
+
261
+ SPACE_ID="Y2lzY29zcGFyazovL..."
262
+
263
+ # Send initial status
264
+ RESULT=$(agent-webex message send "$SPACE_ID" "Deploying v2.1.0...")
265
+ MSG_ID=$(echo "$RESULT" | jq -r '.id')
266
+
267
+ # ... do work ...
268
+ sleep 5
269
+
270
+ # Update the message with final status
271
+ agent-webex message edit "$MSG_ID" "$SPACE_ID" "Deployed v2.1.0 successfully!"
272
+ ```
273
+
274
+ ## Member Patterns
275
+
276
+ ### Pattern 16: List Space Members
277
+
278
+ **Use case**: See who's in a space
279
+
280
+ ```bash
281
+ #!/bin/bash
282
+
283
+ SPACE_ID="Y2lzY29zcGFyazovL..."
284
+
285
+ MEMBERS=$(agent-webex member list "$SPACE_ID")
286
+ echo "$MEMBERS" | jq -r '.[] | "\(.personDisplayName) (\(.personEmail))"'
287
+ ```
288
+
289
+ ### Pattern 17: List Members with Limit
290
+
291
+ **Use case**: Large spaces with many members
292
+
293
+ ```bash
294
+ #!/bin/bash
295
+
296
+ SPACE_ID="Y2lzY29zcGFyazovL..."
297
+
298
+ # Get first 50 members
299
+ agent-webex member list "$SPACE_ID" --limit 50
300
+ ```
301
+
302
+ ### Pattern 18: Find a Specific Member
303
+
304
+ **Use case**: Look up a person in a space
305
+
306
+ ```bash
307
+ #!/bin/bash
308
+
309
+ SPACE_ID="Y2lzY29zcGFyazovL..."
310
+ SEARCH_NAME="alice"
311
+
312
+ MEMBERS=$(agent-webex member list "$SPACE_ID")
313
+ MATCH=$(echo "$MEMBERS" | jq -r --arg name "$SEARCH_NAME" \
314
+ 'first(.[] | select(.personDisplayName | ascii_downcase | contains($name | ascii_downcase)))')
315
+
316
+ if [ -z "$MATCH" ] || [ "$MATCH" = "null" ]; then
317
+ echo "No member matching '$SEARCH_NAME'"
318
+ exit 1
319
+ fi
320
+
321
+ echo "Found: $(echo "$MATCH" | jq -r '.personDisplayName') ($(echo "$MATCH" | jq -r '.personEmail'))"
322
+ ```
323
+
324
+ ## Snapshot Patterns
325
+
326
+ ### Pattern 19: Full Workspace Snapshot
327
+
328
+ **Use case**: Get complete workspace state for AI context
329
+
330
+ ```bash
331
+ #!/bin/bash
332
+
333
+ SNAPSHOT=$(agent-webex snapshot)
334
+
335
+ SPACE_COUNT=$(echo "$SNAPSHOT" | jq -r '.spaces | length')
336
+ echo "Total spaces: $SPACE_COUNT"
337
+
338
+ # List all spaces
339
+ echo "$SNAPSHOT" | jq -r '.spaces[] | " \(.title) (\(.type))"'
340
+ ```
341
+
342
+ ### Pattern 20: Spaces-Only Snapshot
343
+
344
+ **Use case**: Quick overview without messages or members
345
+
346
+ ```bash
347
+ #!/bin/bash
348
+
349
+ agent-webex snapshot --spaces-only
350
+ ```
351
+
352
+ ### Pattern 21: Members-Only Snapshot
353
+
354
+ **Use case**: Get member lists across all spaces
355
+
356
+ ```bash
357
+ #!/bin/bash
358
+
359
+ agent-webex snapshot --members-only
360
+ ```
361
+
362
+ ### Pattern 22: Snapshot with Message Limit
363
+
364
+ **Use case**: Control how many messages per space
365
+
366
+ ```bash
367
+ #!/bin/bash
368
+
369
+ # Get snapshot with last 5 messages per space
370
+ agent-webex snapshot --limit 5
371
+ ```
372
+
373
+ ## Pipeline Patterns
374
+
375
+ ### Pattern 23: Send to Multiple Spaces
376
+
377
+ **Use case**: Broadcast a message across spaces
378
+
379
+ ```bash
380
+ #!/bin/bash
381
+
382
+ MESSAGE="System maintenance in 30 minutes"
383
+ SPACE_NAMES=("Engineering" "Product" "General")
384
+
385
+ # Get all spaces once
386
+ SPACES=$(agent-webex space list)
387
+
388
+ for name in "${SPACE_NAMES[@]}"; do
389
+ SPACE_ID=$(echo "$SPACES" | jq -r --arg t "$name" '.[] | select(.title==$t) | .id')
390
+
391
+ if [ -z "$SPACE_ID" ]; then
392
+ echo "Space '$name' not found, skipping"
393
+ continue
394
+ fi
395
+
396
+ echo "Posting to $name..."
397
+ RESULT=$(agent-webex message send "$SPACE_ID" "$MESSAGE")
398
+
399
+ if echo "$RESULT" | jq -e '.id' > /dev/null 2>&1; then
400
+ echo " Sent to $name"
401
+ else
402
+ echo " Failed: $(echo "$RESULT" | jq -r '.error')"
403
+ fi
404
+
405
+ # Rate limit: don't spam the API
406
+ sleep 1
407
+ done
408
+ ```
409
+
410
+ ### Pattern 24: Conditional Messaging
411
+
412
+ **Use case**: Send different messages based on conditions
413
+
414
+ ```bash
415
+ #!/bin/bash
416
+
417
+ SPACE_ID="Y2lzY29zcGFyazovL..."
418
+ BUILD_STATUS=$1 # "success" or "failure"
419
+
420
+ if [ "$BUILD_STATUS" = "success" ]; then
421
+ agent-webex message send "$SPACE_ID" "Build passed. All tests green." --markdown
422
+ else
423
+ agent-webex message send "$SPACE_ID" "**Build failed.** Check CI logs for details." --markdown
424
+ fi
425
+ ```
426
+
427
+ ### Pattern 25: Error Handling with Retry
428
+
429
+ **Use case**: Robust message sending for production scripts
430
+
431
+ ```bash
432
+ #!/bin/bash
433
+
434
+ send_with_retry() {
435
+ local space_id=$1
436
+ local message=$2
437
+ local max_attempts=3
438
+ local attempt=1
439
+
440
+ while [ $attempt -le $max_attempts ]; do
441
+ RESULT=$(agent-webex message send "$space_id" "$message")
442
+
443
+ if echo "$RESULT" | jq -e '.id' > /dev/null 2>&1; then
444
+ echo "Message sent successfully!"
445
+ return 0
446
+ fi
447
+
448
+ ERROR=$(echo "$RESULT" | jq -r '.error // "Unknown error"')
449
+ echo "Attempt $attempt failed: $ERROR"
450
+
451
+ # Don't retry on auth errors
452
+ if echo "$ERROR" | grep -qi "401\|unauthorized\|not authenticated"; then
453
+ echo "Authentication error. Fix credentials and try again."
454
+ return 1
455
+ fi
456
+
457
+ # Don't retry on not-found errors
458
+ if echo "$ERROR" | grep -qi "not found\|404"; then
459
+ echo "Resource not found. Check your IDs."
460
+ return 1
461
+ fi
462
+
463
+ if [ $attempt -lt $max_attempts ]; then
464
+ SLEEP_TIME=$((attempt * 2))
465
+ echo "Retrying in ${SLEEP_TIME}s..."
466
+ sleep $SLEEP_TIME
467
+ fi
468
+
469
+ attempt=$((attempt + 1))
470
+ done
471
+
472
+ echo "Failed after $max_attempts attempts"
473
+ return 1
474
+ }
475
+
476
+ # Usage
477
+ SPACE_ID="Y2lzY29zcGFyazovL..."
478
+ send_with_retry "$SPACE_ID" "Important notification!"
479
+ ```
480
+
481
+ ### Pattern 26: Token Refresh Wrapper (for PAT/bot tokens)
482
+
483
+ > **Note**: If using Device Grant auth (the default), tokens auto-refresh. This wrapper is only needed for manual PAT/bot token auth.
484
+
485
+ **Use case**: Handle PAT expiry in long-running scripts
486
+
487
+ ```bash
488
+ #!/bin/bash
489
+
490
+ # Wrapper that checks auth before each operation
491
+ webex_cmd() {
492
+ local result
493
+ result=$("$@" 2>&1)
494
+
495
+ # Check for auth failure
496
+ if echo "$result" | grep -qi "401\|unauthorized"; then
497
+ echo "Token expired. Please provide a new token:" >&2
498
+ read -r NEW_TOKEN
499
+ agent-webex auth login --token "$NEW_TOKEN" >&2
500
+
501
+ # Retry
502
+ result=$("$@" 2>&1)
503
+ fi
504
+
505
+ echo "$result"
506
+ }
507
+
508
+ # Usage
509
+ SPACES=$(webex_cmd agent-webex space list)
510
+ RESULT=$(webex_cmd agent-webex message send "$SPACE_ID" "Hello!")
511
+ ```
512
+
513
+ ### Pattern 27: Daily Summary Report
514
+
515
+ **Use case**: Generate a workspace activity summary
516
+
517
+ ```bash
518
+ #!/bin/bash
519
+
520
+ SPACE_ID="Y2lzY29zcGFyazovL..."
521
+
522
+ # Get recent messages
523
+ MESSAGES=$(agent-webex message list "$SPACE_ID" --limit 50)
524
+ MSG_COUNT=$(echo "$MESSAGES" | jq 'length')
525
+
526
+ # Get members
527
+ MEMBERS=$(agent-webex member list "$SPACE_ID")
528
+ MEMBER_COUNT=$(echo "$MEMBERS" | jq 'length')
529
+
530
+ # Get unique authors from recent messages
531
+ AUTHORS=$(echo "$MESSAGES" | jq -r '[.[].personEmail] | unique | length')
532
+
533
+ SUMMARY="**Daily Summary**
534
+ - Messages (last 50): $MSG_COUNT
535
+ - Active authors: $AUTHORS
536
+ - Total members: $MEMBER_COUNT"
537
+
538
+ agent-webex message send "$SPACE_ID" "$SUMMARY" --markdown
539
+ ```
540
+
541
+ ### Pattern 28: Monitor and Respond
542
+
543
+ **Use case**: Poll a space and respond to keywords
544
+
545
+ ```bash
546
+ #!/bin/bash
547
+
548
+ SPACE_ID="Y2lzY29zcGFyazovL..."
549
+ LAST_ID=""
550
+
551
+ while true; do
552
+ MESSAGES=$(agent-webex message list "$SPACE_ID" --limit 1)
553
+
554
+ # Check for errors
555
+ if echo "$MESSAGES" | jq -e '.error' > /dev/null 2>&1; then
556
+ echo "Error: $(echo "$MESSAGES" | jq -r '.error')"
557
+ sleep 10
558
+ continue
559
+ fi
560
+
561
+ LATEST_ID=$(echo "$MESSAGES" | jq -r '.[0].id // ""')
562
+
563
+ if [ "$LATEST_ID" != "$LAST_ID" ] && [ -n "$LAST_ID" ]; then
564
+ TEXT=$(echo "$MESSAGES" | jq -r '.[0].text // ""')
565
+ AUTHOR=$(echo "$MESSAGES" | jq -r '.[0].personEmail // ""')
566
+
567
+ echo "New message from $AUTHOR: $TEXT"
568
+
569
+ # Respond to keywords
570
+ if echo "$TEXT" | grep -qi "status"; then
571
+ agent-webex message send "$SPACE_ID" "All systems operational."
572
+ fi
573
+ fi
574
+
575
+ LAST_ID="$LATEST_ID"
576
+ sleep 10
577
+ done
578
+ ```
579
+
580
+ ### Pattern 29: Batch Message Cleanup
581
+
582
+ **Use case**: Delete multiple messages (e.g., bot spam cleanup)
583
+
584
+ ```bash
585
+ #!/bin/bash
586
+
587
+ SPACE_ID="Y2lzY29zcGFyazovL..."
588
+
589
+ # Get recent messages
590
+ MESSAGES=$(agent-webex message list "$SPACE_ID" --limit 20)
591
+
592
+ # Delete messages from a specific sender
593
+ echo "$MESSAGES" | jq -r '.[] | select(.personEmail=="bot@example.com") | .id' | while read -r msg_id; do
594
+ echo "Deleting $msg_id..."
595
+ agent-webex message delete "$msg_id" --force
596
+ sleep 1
597
+ done
598
+ ```
599
+
600
+ ## Best Practices
601
+
602
+ ### 1. Always Check for Success
603
+
604
+ ```bash
605
+ # Good
606
+ RESULT=$(agent-webex message send "$SPACE_ID" "Hello")
607
+ if echo "$RESULT" | jq -e '.id' > /dev/null 2>&1; then
608
+ echo "Success!"
609
+ else
610
+ echo "Failed: $(echo "$RESULT" | jq -r '.error')"
611
+ fi
612
+
613
+ # Bad
614
+ agent-webex message send "$SPACE_ID" "Hello" # No error checking
615
+ ```
616
+
617
+ ### 2. Cache Space Lists
618
+
619
+ ```bash
620
+ # Good - fetch once, reuse
621
+ SPACES=$(agent-webex space list)
622
+ for title in "${SPACE_TITLES[@]}"; do
623
+ id=$(echo "$SPACES" | jq -r --arg t "$title" '.[] | select(.title==$t) | .id')
624
+ agent-webex message send "$id" "$MESSAGE"
625
+ done
626
+
627
+ # Bad - fetch repeatedly
628
+ for title in "${SPACE_TITLES[@]}"; do
629
+ SPACES=$(agent-webex space list) # Wasteful!
630
+ id=$(echo "$SPACES" | jq -r --arg t "$title" '.[] | select(.title==$t) | .id')
631
+ agent-webex message send "$id" "$MESSAGE"
632
+ done
633
+ ```
634
+
635
+ ### 3. Rate Limit Your Requests
636
+
637
+ ```bash
638
+ # Good - respect Webex API limits
639
+ for space_id in "${SPACE_IDS[@]}"; do
640
+ agent-webex message send "$space_id" "$MESSAGE"
641
+ sleep 1
642
+ done
643
+
644
+ # Bad - rapid-fire requests
645
+ for space_id in "${SPACE_IDS[@]}"; do
646
+ agent-webex message send "$space_id" "$MESSAGE"
647
+ done
648
+ ```
649
+
650
+ ### 4. Use Bot Tokens or Device Grant for Automation
651
+
652
+ ```bash
653
+ # Best: Device Grant (auto-refreshes, no token management)
654
+ agent-webex auth login
655
+
656
+ # Also good: bot token (never expires)
657
+ agent-webex auth login --token "$BOT_TOKEN"
658
+
659
+ # Risky: PAT expires in 12 hours
660
+ agent-webex auth login --token "$PAT_TOKEN"
661
+ ```
662
+
663
+ ### 5. Don't Spam Spaces
664
+
665
+ ```bash
666
+ # Bad - sends 100 messages
667
+ for i in {1..100}; do
668
+ agent-webex message send "$SPACE_ID" "Item $i"
669
+ done
670
+
671
+ # Good - batch into single message
672
+ MESSAGE="Updates:"
673
+ for i in {1..100}; do
674
+ MESSAGE="$MESSAGE\n$i. Item $i"
675
+ done
676
+ agent-webex message send "$SPACE_ID" "$MESSAGE"
677
+ ```
678
+
679
+ ## Anti-Patterns
680
+
681
+ ### Don't Ignore Auth Errors
682
+
683
+ ```bash
684
+ # Bad
685
+ agent-webex message send "$SPACE_ID" "Hello"
686
+ # Continues even if not authenticated
687
+
688
+ # Good
689
+ RESULT=$(agent-webex message send "$SPACE_ID" "Hello")
690
+ if echo "$RESULT" | grep -qi "401\|unauthorized\|not authenticated"; then
691
+ echo "Auth failed. Run 'auth login' to re-authenticate."
692
+ exit 1
693
+ fi
694
+ ```
695
+
696
+ ### Don't Poll Too Frequently
697
+
698
+ ```bash
699
+ # Bad - polls every second
700
+ while true; do
701
+ agent-webex message list "$SPACE_ID" --limit 1
702
+ sleep 1
703
+ done
704
+
705
+ # Good - reasonable interval
706
+ while true; do
707
+ agent-webex message list "$SPACE_ID" --limit 1
708
+ sleep 10
709
+ done
710
+ ```
711
+
712
+ ### Don't Hardcode IDs Without Context
713
+
714
+ ```bash
715
+ # Bad - mystery ID
716
+ agent-webex message send "Y2lzY29zcGFyazovL..." "Hello"
717
+
718
+ # Good - document what the ID refers to
719
+ ENGINEERING_SPACE="Y2lzY29zcGFyazovL..." # Engineering space
720
+ agent-webex message send "$ENGINEERING_SPACE" "Hello"
721
+ ```
722
+
723
+ ## See Also
724
+
725
+ - [Authentication Guide](authentication.md) - Token types, storage, and troubleshooting
726
+ - [Templates](../templates/) - Runnable example scripts