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