agent-messenger 1.0.0 → 1.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/commands/release.md +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.github/workflows/ci.yml +1 -1
- package/.github/workflows/e2e.yml.disabled +69 -0
- package/README.md +16 -14
- package/biome.json +33 -1
- package/bun.lock +63 -0
- package/dist/package.json +8 -4
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +4 -1
- package/dist/src/cli.js.map +1 -1
- package/dist/src/platforms/discord/cli.js +1 -1
- package/dist/src/platforms/discord/client.d.ts.map +1 -1
- package/dist/src/platforms/discord/client.js +3 -3
- package/dist/src/platforms/discord/client.js.map +1 -1
- package/dist/src/platforms/discord/commands/user.d.ts.map +1 -1
- package/dist/src/platforms/discord/commands/user.js +10 -1
- package/dist/src/platforms/discord/commands/user.js.map +1 -1
- package/dist/src/platforms/discord/credential-manager.d.ts.map +1 -1
- package/dist/src/platforms/discord/credential-manager.js +18 -12
- package/dist/src/platforms/discord/credential-manager.js.map +1 -1
- package/dist/src/platforms/slack/cli.js +1 -1
- package/dist/src/platforms/slack/credential-manager.d.ts.map +1 -1
- package/dist/src/platforms/slack/credential-manager.js +20 -6
- package/dist/src/platforms/slack/credential-manager.js.map +1 -1
- package/dist/src/platforms/slack/token-extractor.d.ts.map +1 -1
- package/dist/src/platforms/slack/token-extractor.js +34 -9
- package/dist/src/platforms/slack/token-extractor.js.map +1 -1
- package/dist/src/platforms/teams/cli.d.ts.map +1 -0
- package/dist/{cli.js → src/platforms/teams/cli.js} +11 -10
- package/dist/src/platforms/teams/cli.js.map +1 -0
- package/dist/src/platforms/teams/client.d.ts +32 -0
- package/dist/src/platforms/teams/client.d.ts.map +1 -0
- package/dist/src/platforms/teams/client.js +202 -0
- package/dist/src/platforms/teams/client.js.map +1 -0
- package/dist/src/platforms/teams/commands/auth.d.ts +14 -0
- package/dist/src/platforms/teams/commands/auth.d.ts.map +1 -0
- package/dist/src/platforms/teams/commands/auth.js +176 -0
- package/dist/src/platforms/teams/commands/auth.js.map +1 -0
- package/dist/src/platforms/teams/commands/channel.d.ts +13 -0
- package/dist/src/platforms/teams/commands/channel.d.ts.map +1 -0
- package/dist/src/platforms/teams/commands/channel.js +97 -0
- package/dist/src/platforms/teams/commands/channel.js.map +1 -0
- package/dist/src/platforms/teams/commands/file.d.ts +12 -0
- package/dist/src/platforms/teams/commands/file.d.ts.map +1 -0
- package/dist/src/platforms/teams/commands/file.js +104 -0
- package/dist/src/platforms/teams/commands/file.js.map +1 -0
- package/dist/{commands → src/platforms/teams/commands}/index.d.ts +5 -2
- package/dist/src/platforms/teams/commands/index.d.ts.map +1 -0
- package/dist/{commands → src/platforms/teams/commands}/index.js +5 -2
- package/dist/src/platforms/teams/commands/index.js.map +1 -0
- package/dist/src/platforms/teams/commands/message.d.ts +17 -0
- package/dist/src/platforms/teams/commands/message.d.ts.map +1 -0
- package/dist/src/platforms/teams/commands/message.js +133 -0
- package/dist/src/platforms/teams/commands/message.js.map +1 -0
- package/dist/src/platforms/teams/commands/reaction.d.ts +9 -0
- package/dist/src/platforms/teams/commands/reaction.d.ts.map +1 -0
- package/dist/src/platforms/teams/commands/reaction.js +68 -0
- package/dist/src/platforms/teams/commands/reaction.js.map +1 -0
- package/dist/src/platforms/teams/commands/snapshot.d.ts +10 -0
- package/dist/src/platforms/teams/commands/snapshot.d.ts.map +1 -0
- package/dist/src/platforms/teams/commands/snapshot.js +85 -0
- package/dist/src/platforms/teams/commands/snapshot.js.map +1 -0
- package/dist/src/platforms/teams/commands/team.d.ts +18 -0
- package/dist/src/platforms/teams/commands/team.d.ts.map +1 -0
- package/dist/src/platforms/teams/commands/team.js +130 -0
- package/dist/src/platforms/teams/commands/team.js.map +1 -0
- package/dist/src/platforms/teams/commands/user.d.ts.map +1 -0
- package/dist/src/platforms/teams/commands/user.js +88 -0
- package/dist/src/platforms/teams/commands/user.js.map +1 -0
- package/dist/src/platforms/teams/credential-manager.d.ts +18 -0
- package/dist/src/platforms/teams/credential-manager.d.ts.map +1 -0
- package/dist/src/platforms/teams/credential-manager.js +81 -0
- package/dist/src/platforms/teams/credential-manager.js.map +1 -0
- package/dist/src/platforms/teams/index.d.ts +4 -0
- package/dist/src/platforms/teams/index.d.ts.map +1 -0
- package/dist/src/platforms/teams/index.js +6 -0
- package/dist/src/platforms/teams/index.js.map +1 -0
- package/dist/src/platforms/teams/token-extractor.d.ts +36 -0
- package/dist/src/platforms/teams/token-extractor.d.ts.map +1 -0
- package/dist/src/platforms/teams/token-extractor.js +335 -0
- package/dist/src/platforms/teams/token-extractor.js.map +1 -0
- package/dist/src/platforms/teams/types.d.ts +209 -0
- package/dist/src/platforms/teams/types.d.ts.map +1 -0
- package/dist/src/platforms/teams/types.js +65 -0
- package/dist/src/platforms/teams/types.js.map +1 -0
- package/docs/teams.md +321 -0
- package/e2e/README.md +256 -0
- package/e2e/config.ts +45 -0
- package/e2e/discord.e2e.test.ts +252 -0
- package/e2e/helpers.ts +107 -0
- package/e2e/slack.e2e.test.ts +309 -0
- package/package.json +8 -4
- package/scripts/postbuild.ts +15 -0
- package/skills/agent-teams/SKILL.md +292 -0
- package/skills/agent-teams/references/authentication.md +375 -0
- package/skills/agent-teams/references/common-patterns.md +596 -0
- package/skills/agent-teams/templates/monitor-channel.sh +239 -0
- package/skills/agent-teams/templates/post-message.sh +224 -0
- package/skills/agent-teams/templates/team-summary.sh +210 -0
- package/src/cli.ts +4 -0
- package/src/platforms/discord/client.ts +3 -3
- package/src/platforms/discord/commands/auth.test.ts +48 -32
- package/src/platforms/discord/commands/channel.test.ts +54 -42
- package/src/platforms/discord/commands/file.test.ts +40 -53
- package/src/platforms/discord/commands/guild.test.ts +47 -27
- package/src/platforms/discord/commands/message.test.ts +54 -51
- package/src/platforms/discord/commands/reaction.test.ts +54 -42
- package/src/platforms/discord/commands/user.ts +12 -1
- package/src/platforms/discord/credential-manager.test.ts +137 -136
- package/src/platforms/discord/credential-manager.ts +20 -13
- package/src/platforms/discord/token-extractor.test.ts +133 -383
- package/{tests → src/platforms/slack}/cli.test.ts +3 -3
- package/{tests/slack-client.test.ts → src/platforms/slack/client.test.ts} +1 -1
- package/{tests → src/platforms/slack}/commands/auth.test.ts +25 -13
- package/{tests → src/platforms/slack}/commands/channel.test.ts +2 -2
- package/{tests → src/platforms/slack}/commands/file.test.ts +2 -2
- package/{tests → src/platforms/slack}/commands/message.test.ts +2 -2
- package/{tests → src/platforms/slack}/commands/reaction.test.ts +1 -1
- package/{tests → src/platforms/slack}/commands/snapshot.test.ts +117 -105
- package/{tests → src/platforms/slack}/commands/user.test.ts +3 -3
- package/{tests → src/platforms/slack}/commands/workspace.test.ts +44 -95
- package/{tests → src/platforms/slack}/credential-manager.test.ts +2 -2
- package/src/platforms/slack/credential-manager.ts +22 -7
- package/src/platforms/slack/token-extractor-node-test.ts +40 -0
- package/src/platforms/slack/token-extractor-node.test.ts +10 -0
- package/src/platforms/slack/token-extractor.ts +36 -10
- package/{tests → src/platforms/slack}/types.test.ts +1 -1
- package/src/platforms/teams/cli.ts +36 -0
- package/src/platforms/teams/client.test.ts +500 -0
- package/src/platforms/teams/client.ts +365 -0
- package/src/platforms/teams/commands/auth.test.ts +99 -0
- package/src/platforms/teams/commands/auth.ts +232 -0
- package/src/platforms/teams/commands/channel.test.ts +147 -0
- package/src/platforms/teams/commands/channel.ts +129 -0
- package/src/platforms/teams/commands/file.test.ts +88 -0
- package/src/platforms/teams/commands/file.ts +144 -0
- package/src/platforms/teams/commands/index.ts +12 -0
- package/src/platforms/teams/commands/message.test.ts +110 -0
- package/src/platforms/teams/commands/message.ts +188 -0
- package/src/platforms/teams/commands/reaction.test.ts +87 -0
- package/src/platforms/teams/commands/reaction.ts +104 -0
- package/src/platforms/teams/commands/snapshot.test.ts +35 -0
- package/src/platforms/teams/commands/snapshot.ts +115 -0
- package/src/platforms/teams/commands/team.test.ts +157 -0
- package/src/platforms/teams/commands/team.ts +164 -0
- package/src/platforms/teams/commands/user.test.ts +83 -0
- package/src/platforms/teams/commands/user.ts +112 -0
- package/src/platforms/teams/credential-manager.test.ts +178 -0
- package/src/platforms/teams/credential-manager.ts +92 -0
- package/src/platforms/teams/index.ts +5 -0
- package/src/platforms/teams/token-extractor.test.ts +429 -0
- package/src/platforms/teams/token-extractor.ts +462 -0
- package/src/platforms/teams/types.test.ts +226 -0
- package/src/platforms/teams/types.ts +140 -0
- package/tsconfig.json +1 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/commands/auth.d.ts +0 -3
- package/dist/commands/auth.d.ts.map +0 -1
- package/dist/commands/auth.js +0 -140
- package/dist/commands/auth.js.map +0 -1
- package/dist/commands/channel.d.ts +0 -3
- package/dist/commands/channel.d.ts.map +0 -1
- package/dist/commands/channel.js +0 -118
- package/dist/commands/channel.js.map +0 -1
- package/dist/commands/file.d.ts +0 -3
- package/dist/commands/file.d.ts.map +0 -1
- package/dist/commands/file.js +0 -113
- package/dist/commands/file.js.map +0 -1
- package/dist/commands/index.d.ts.map +0 -1
- package/dist/commands/index.js.map +0 -1
- package/dist/commands/message.d.ts +0 -3
- package/dist/commands/message.d.ts.map +0 -1
- package/dist/commands/message.js +0 -214
- package/dist/commands/message.js.map +0 -1
- package/dist/commands/reaction.d.ts +0 -3
- package/dist/commands/reaction.d.ts.map +0 -1
- package/dist/commands/reaction.js +0 -100
- package/dist/commands/reaction.js.map +0 -1
- package/dist/commands/snapshot.d.ts +0 -3
- package/dist/commands/snapshot.d.ts.map +0 -1
- package/dist/commands/snapshot.js +0 -88
- package/dist/commands/snapshot.js.map +0 -1
- package/dist/commands/user.d.ts.map +0 -1
- package/dist/commands/user.js +0 -96
- package/dist/commands/user.js.map +0 -1
- package/dist/commands/workspace.d.ts +0 -3
- package/dist/commands/workspace.d.ts.map +0 -1
- package/dist/commands/workspace.js +0 -89
- package/dist/commands/workspace.js.map +0 -1
- package/dist/lib/credential-manager.d.ts +0 -13
- package/dist/lib/credential-manager.d.ts.map +0 -1
- package/dist/lib/credential-manager.js +0 -58
- package/dist/lib/credential-manager.js.map +0 -1
- package/dist/lib/index.d.ts +0 -3
- package/dist/lib/index.d.ts.map +0 -1
- package/dist/lib/index.js +0 -3
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/ref-manager.d.ts +0 -26
- package/dist/lib/ref-manager.d.ts.map +0 -1
- package/dist/lib/ref-manager.js +0 -92
- package/dist/lib/ref-manager.js.map +0 -1
- package/dist/lib/slack-client.d.ts +0 -37
- package/dist/lib/slack-client.d.ts.map +0 -1
- package/dist/lib/slack-client.js +0 -379
- package/dist/lib/slack-client.js.map +0 -1
- package/dist/lib/token-extractor.d.ts +0 -28
- package/dist/lib/token-extractor.d.ts.map +0 -1
- package/dist/lib/token-extractor.js +0 -401
- package/dist/lib/token-extractor.js.map +0 -1
- package/dist/src/platforms/discord/client.test.d.ts +0 -2
- package/dist/src/platforms/discord/client.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/client.test.js +0 -367
- package/dist/src/platforms/discord/client.test.js.map +0 -1
- package/dist/src/platforms/discord/commands/auth.test.d.ts +0 -2
- package/dist/src/platforms/discord/commands/auth.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/commands/auth.test.js +0 -65
- package/dist/src/platforms/discord/commands/auth.test.js.map +0 -1
- package/dist/src/platforms/discord/commands/channel.test.d.ts +0 -2
- package/dist/src/platforms/discord/commands/channel.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/commands/channel.test.js +0 -136
- package/dist/src/platforms/discord/commands/channel.test.js.map +0 -1
- package/dist/src/platforms/discord/commands/file.test.d.ts +0 -2
- package/dist/src/platforms/discord/commands/file.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/commands/file.test.js +0 -83
- package/dist/src/platforms/discord/commands/file.test.js.map +0 -1
- package/dist/src/platforms/discord/commands/guild.test.d.ts +0 -2
- package/dist/src/platforms/discord/commands/guild.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/commands/guild.test.js +0 -100
- package/dist/src/platforms/discord/commands/guild.test.js.map +0 -1
- package/dist/src/platforms/discord/commands/message.test.d.ts +0 -2
- package/dist/src/platforms/discord/commands/message.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/commands/message.test.js +0 -91
- package/dist/src/platforms/discord/commands/message.test.js.map +0 -1
- package/dist/src/platforms/discord/commands/reaction.test.d.ts +0 -2
- package/dist/src/platforms/discord/commands/reaction.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/commands/reaction.test.js +0 -115
- package/dist/src/platforms/discord/commands/reaction.test.js.map +0 -1
- package/dist/src/platforms/discord/commands/snapshot.test.d.ts +0 -2
- package/dist/src/platforms/discord/commands/snapshot.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/commands/snapshot.test.js +0 -25
- package/dist/src/platforms/discord/commands/snapshot.test.js.map +0 -1
- package/dist/src/platforms/discord/commands/user.test.d.ts +0 -2
- package/dist/src/platforms/discord/commands/user.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/commands/user.test.js +0 -103
- package/dist/src/platforms/discord/commands/user.test.js.map +0 -1
- package/dist/src/platforms/discord/credential-manager.test.d.ts +0 -2
- package/dist/src/platforms/discord/credential-manager.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/credential-manager.test.js +0 -136
- package/dist/src/platforms/discord/credential-manager.test.js.map +0 -1
- package/dist/src/platforms/discord/token-extractor.test.d.ts +0 -2
- package/dist/src/platforms/discord/token-extractor.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/token-extractor.test.js +0 -789
- package/dist/src/platforms/discord/token-extractor.test.js.map +0 -1
- package/dist/src/platforms/discord/types.test.d.ts +0 -2
- package/dist/src/platforms/discord/types.test.d.ts.map +0 -1
- package/dist/src/platforms/discord/types.test.js +0 -211
- package/dist/src/platforms/discord/types.test.js.map +0 -1
- package/dist/src/shared/utils/concurrency.test.d.ts +0 -2
- package/dist/src/shared/utils/concurrency.test.d.ts.map +0 -1
- package/dist/src/shared/utils/concurrency.test.js +0 -39
- package/dist/src/shared/utils/concurrency.test.js.map +0 -1
- package/dist/tests/cli.test.d.ts +0 -2
- package/dist/tests/cli.test.d.ts.map +0 -1
- package/dist/tests/cli.test.js +0 -83
- package/dist/tests/cli.test.js.map +0 -1
- package/dist/tests/commands/.test-slack-data/Local Storage/leveldb/CURRENT +0 -1
- package/dist/tests/commands/.test-slack-data/Local Storage/leveldb/LOCK +0 -0
- package/dist/tests/commands/.test-slack-data/Local Storage/leveldb/LOG +0 -3
- package/dist/tests/commands/.test-slack-data/Local Storage/leveldb/LOG.old +0 -1
- package/dist/tests/commands/.test-slack-data/Local Storage/leveldb/MANIFEST-000004 +0 -0
- package/dist/tests/commands/auth.test.d.ts +0 -2
- package/dist/tests/commands/auth.test.d.ts.map +0 -1
- package/dist/tests/commands/auth.test.js +0 -304
- package/dist/tests/commands/auth.test.js.map +0 -1
- package/dist/tests/commands/channel.test.d.ts +0 -2
- package/dist/tests/commands/channel.test.d.ts.map +0 -1
- package/dist/tests/commands/channel.test.js +0 -166
- package/dist/tests/commands/channel.test.js.map +0 -1
- package/dist/tests/commands/file.test.d.ts +0 -2
- package/dist/tests/commands/file.test.d.ts.map +0 -1
- package/dist/tests/commands/file.test.js +0 -175
- package/dist/tests/commands/file.test.js.map +0 -1
- package/dist/tests/commands/message.test.d.ts +0 -2
- package/dist/tests/commands/message.test.d.ts.map +0 -1
- package/dist/tests/commands/message.test.js +0 -293
- package/dist/tests/commands/message.test.js.map +0 -1
- package/dist/tests/commands/reaction.test.d.ts +0 -2
- package/dist/tests/commands/reaction.test.d.ts.map +0 -1
- package/dist/tests/commands/reaction.test.js +0 -84
- package/dist/tests/commands/reaction.test.js.map +0 -1
- package/dist/tests/commands/snapshot.test.d.ts +0 -2
- package/dist/tests/commands/snapshot.test.d.ts.map +0 -1
- package/dist/tests/commands/snapshot.test.js +0 -280
- package/dist/tests/commands/snapshot.test.js.map +0 -1
- package/dist/tests/commands/user.test.d.ts +0 -2
- package/dist/tests/commands/user.test.d.ts.map +0 -1
- package/dist/tests/commands/user.test.js +0 -117
- package/dist/tests/commands/user.test.js.map +0 -1
- package/dist/tests/commands/workspace.test.d.ts +0 -2
- package/dist/tests/commands/workspace.test.d.ts.map +0 -1
- package/dist/tests/commands/workspace.test.js +0 -453
- package/dist/tests/commands/workspace.test.js.map +0 -1
- package/dist/tests/credential-manager.test.d.ts +0 -2
- package/dist/tests/credential-manager.test.d.ts.map +0 -1
- package/dist/tests/credential-manager.test.js +0 -199
- package/dist/tests/credential-manager.test.js.map +0 -1
- package/dist/tests/slack-client.test.d.ts +0 -2
- package/dist/tests/slack-client.test.d.ts.map +0 -1
- package/dist/tests/slack-client.test.js +0 -741
- package/dist/tests/slack-client.test.js.map +0 -1
- package/dist/tests/types.test.d.ts +0 -2
- package/dist/tests/types.test.d.ts.map +0 -1
- package/dist/tests/types.test.js +0 -215
- package/dist/tests/types.test.js.map +0 -1
- package/dist/types/index.d.ts +0 -369
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -92
- package/dist/types/index.js.map +0 -1
- package/dist/utils/error-handler.d.ts +0 -2
- package/dist/utils/error-handler.d.ts.map +0 -1
- package/dist/utils/error-handler.js +0 -5
- package/dist/utils/error-handler.js.map +0 -1
- package/dist/utils/output.d.ts +0 -2
- package/dist/utils/output.d.ts.map +0 -1
- package/dist/utils/output.js +0 -4
- package/dist/utils/output.js.map +0 -1
- /package/dist/{cli.d.ts → src/platforms/teams/cli.d.ts} +0 -0
- /package/dist/{commands → src/platforms/teams/commands}/user.d.ts +0 -0
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
# Common Patterns
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This guide covers typical workflows for AI agents interacting with Microsoft Teams using agent-teams.
|
|
6
|
+
|
|
7
|
+
**Important**: Teams uses UUID-style channel IDs (like `19:abc123@thread.tacv2`). You cannot use channel names directly - always get IDs from `channel list` first.
|
|
8
|
+
|
|
9
|
+
**CRITICAL**: Teams tokens expire in 60-90 minutes! All patterns include token refresh handling.
|
|
10
|
+
|
|
11
|
+
## Pattern 1: Send a Simple Message
|
|
12
|
+
|
|
13
|
+
**Use case**: Post a notification or update to a channel
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
#!/bin/bash
|
|
17
|
+
|
|
18
|
+
# First, ensure token is valid
|
|
19
|
+
agent-teams auth extract 2>/dev/null || true
|
|
20
|
+
|
|
21
|
+
# Get channel ID from channel list
|
|
22
|
+
CHANNELS=$(agent-teams channel list)
|
|
23
|
+
CHANNEL_ID=$(echo "$CHANNELS" | jq -r '.[] | select(.name=="General") | .id')
|
|
24
|
+
|
|
25
|
+
# Send message using channel ID
|
|
26
|
+
agent-teams message send "$CHANNEL_ID" "Deployment completed successfully!"
|
|
27
|
+
|
|
28
|
+
# With error handling
|
|
29
|
+
RESULT=$(agent-teams message send "$CHANNEL_ID" "Hello world")
|
|
30
|
+
if echo "$RESULT" | jq -e '.id' > /dev/null 2>&1; then
|
|
31
|
+
echo "Message sent!"
|
|
32
|
+
else
|
|
33
|
+
ERROR=$(echo "$RESULT" | jq -r '.error')
|
|
34
|
+
|
|
35
|
+
# Handle token expiry
|
|
36
|
+
if echo "$ERROR" | grep -qi "expired\|401"; then
|
|
37
|
+
echo "Token expired, refreshing..."
|
|
38
|
+
agent-teams auth extract
|
|
39
|
+
agent-teams message send "$CHANNEL_ID" "Hello world"
|
|
40
|
+
else
|
|
41
|
+
echo "Failed: $ERROR"
|
|
42
|
+
exit 1
|
|
43
|
+
fi
|
|
44
|
+
fi
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**When to use**: Simple one-off messages after looking up the channel ID.
|
|
48
|
+
|
|
49
|
+
## Pattern 2: Monitor Channel for New Messages (with Token Refresh)
|
|
50
|
+
|
|
51
|
+
**Use case**: Watch a channel and respond to new messages
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
#!/bin/bash
|
|
55
|
+
|
|
56
|
+
CHANNEL_ID="19:abc123@thread.tacv2"
|
|
57
|
+
LAST_ID=""
|
|
58
|
+
TOKEN_CHECK_INTERVAL=300 # Check token every 5 minutes
|
|
59
|
+
|
|
60
|
+
last_token_check=$(date +%s)
|
|
61
|
+
|
|
62
|
+
refresh_token_if_needed() {
|
|
63
|
+
local now=$(date +%s)
|
|
64
|
+
local elapsed=$((now - last_token_check))
|
|
65
|
+
|
|
66
|
+
if [ $elapsed -gt $TOKEN_CHECK_INTERVAL ]; then
|
|
67
|
+
STATUS=$(agent-teams auth status)
|
|
68
|
+
EXPIRES_SOON=$(echo "$STATUS" | jq -r '.token_expires_soon // true')
|
|
69
|
+
|
|
70
|
+
if [ "$EXPIRES_SOON" = "true" ]; then
|
|
71
|
+
echo "Token expiring soon, refreshing..."
|
|
72
|
+
agent-teams auth extract
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
last_token_check=$now
|
|
76
|
+
fi
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
while true; do
|
|
80
|
+
# Proactively refresh token
|
|
81
|
+
refresh_token_if_needed
|
|
82
|
+
|
|
83
|
+
# Get latest message
|
|
84
|
+
MESSAGES=$(agent-teams message list "$CHANNEL_ID" --limit 1)
|
|
85
|
+
|
|
86
|
+
# Handle token expiry error
|
|
87
|
+
if echo "$MESSAGES" | jq -e '.error' | grep -qi "expired\|401" 2>/dev/null; then
|
|
88
|
+
echo "Token expired, refreshing..."
|
|
89
|
+
agent-teams auth extract
|
|
90
|
+
continue
|
|
91
|
+
fi
|
|
92
|
+
|
|
93
|
+
LATEST_ID=$(echo "$MESSAGES" | jq -r '.[0].id // ""')
|
|
94
|
+
|
|
95
|
+
# Check if new message
|
|
96
|
+
if [ "$LATEST_ID" != "$LAST_ID" ] && [ -n "$LAST_ID" ]; then
|
|
97
|
+
CONTENT=$(echo "$MESSAGES" | jq -r '.[0].content')
|
|
98
|
+
AUTHOR=$(echo "$MESSAGES" | jq -r '.[0].author')
|
|
99
|
+
|
|
100
|
+
echo "New message from $AUTHOR: $CONTENT"
|
|
101
|
+
|
|
102
|
+
# Process message here
|
|
103
|
+
if echo "$CONTENT" | grep -q "bot"; then
|
|
104
|
+
agent-teams message send "$CHANNEL_ID" "You called?"
|
|
105
|
+
fi
|
|
106
|
+
fi
|
|
107
|
+
|
|
108
|
+
LAST_ID="$LATEST_ID"
|
|
109
|
+
sleep 5
|
|
110
|
+
done
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**When to use**: Building a simple bot that reacts to messages.
|
|
114
|
+
|
|
115
|
+
**Limitations**: Polling-based, not real-time. Token must be refreshed every 60-90 minutes.
|
|
116
|
+
|
|
117
|
+
## Pattern 3: Get Team Overview
|
|
118
|
+
|
|
119
|
+
**Use case**: Understand team state before taking action
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
#!/bin/bash
|
|
123
|
+
|
|
124
|
+
# Ensure fresh token
|
|
125
|
+
agent-teams auth extract 2>/dev/null || true
|
|
126
|
+
|
|
127
|
+
# Get full snapshot
|
|
128
|
+
SNAPSHOT=$(agent-teams snapshot)
|
|
129
|
+
|
|
130
|
+
# Extract key information
|
|
131
|
+
TEAM_NAME=$(echo "$SNAPSHOT" | jq -r '.team.name // "Unknown"')
|
|
132
|
+
CHANNEL_COUNT=$(echo "$SNAPSHOT" | jq -r '.channels | length')
|
|
133
|
+
MEMBER_COUNT=$(echo "$SNAPSHOT" | jq -r '.members | length')
|
|
134
|
+
|
|
135
|
+
echo "Team: $TEAM_NAME"
|
|
136
|
+
echo "Channels: $CHANNEL_COUNT"
|
|
137
|
+
echo "Members: $MEMBER_COUNT"
|
|
138
|
+
|
|
139
|
+
# List all channels
|
|
140
|
+
echo -e "\nChannels:"
|
|
141
|
+
echo "$SNAPSHOT" | jq -r '.channels[] | " #\(.name) (\(.id))"'
|
|
142
|
+
|
|
143
|
+
# List recent activity
|
|
144
|
+
echo -e "\nRecent messages:"
|
|
145
|
+
echo "$SNAPSHOT" | jq -r '.recent_messages[] | " [\(.channel_name)] \(.author): \(.content[0:50])"'
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**When to use**: Initial context gathering, status reports, team summaries.
|
|
149
|
+
|
|
150
|
+
## Pattern 4: Find Channel by Name
|
|
151
|
+
|
|
152
|
+
**Use case**: Get channel ID from channel name
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
#!/bin/bash
|
|
156
|
+
|
|
157
|
+
get_channel_id() {
|
|
158
|
+
local channel_name=$1
|
|
159
|
+
|
|
160
|
+
CHANNELS=$(agent-teams channel list)
|
|
161
|
+
CHANNEL_ID=$(echo "$CHANNELS" | jq -r --arg name "$channel_name" '.[] | select(.name==$name) | .id')
|
|
162
|
+
|
|
163
|
+
if [ -z "$CHANNEL_ID" ]; then
|
|
164
|
+
echo "Channel #$channel_name not found" >&2
|
|
165
|
+
return 1
|
|
166
|
+
fi
|
|
167
|
+
|
|
168
|
+
echo "$CHANNEL_ID"
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
# Usage
|
|
172
|
+
GENERAL_ID=$(get_channel_id "General")
|
|
173
|
+
if [ $? -eq 0 ]; then
|
|
174
|
+
agent-teams message send "$GENERAL_ID" "Hello!"
|
|
175
|
+
fi
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**When to use**: When you know channel name but need the ID.
|
|
179
|
+
|
|
180
|
+
## Pattern 5: Multi-Channel Broadcast
|
|
181
|
+
|
|
182
|
+
**Use case**: Send the same message to multiple channels
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
#!/bin/bash
|
|
186
|
+
|
|
187
|
+
MESSAGE="System maintenance in 30 minutes"
|
|
188
|
+
CHANNEL_NAMES=("General" "Announcements" "Engineering")
|
|
189
|
+
|
|
190
|
+
# Ensure fresh token before bulk operation
|
|
191
|
+
agent-teams auth extract
|
|
192
|
+
|
|
193
|
+
# Get all channels once
|
|
194
|
+
CHANNELS=$(agent-teams channel list)
|
|
195
|
+
|
|
196
|
+
for name in "${CHANNEL_NAMES[@]}"; do
|
|
197
|
+
CHANNEL_ID=$(echo "$CHANNELS" | jq -r --arg n "$name" '.[] | select(.name==$n) | .id')
|
|
198
|
+
|
|
199
|
+
if [ -z "$CHANNEL_ID" ]; then
|
|
200
|
+
echo "Channel #$name not found, skipping"
|
|
201
|
+
continue
|
|
202
|
+
fi
|
|
203
|
+
|
|
204
|
+
echo "Posting to #$name..."
|
|
205
|
+
RESULT=$(agent-teams message send "$CHANNEL_ID" "$MESSAGE")
|
|
206
|
+
|
|
207
|
+
if echo "$RESULT" | jq -e '.id' > /dev/null 2>&1; then
|
|
208
|
+
echo " Posted to #$name"
|
|
209
|
+
else
|
|
210
|
+
echo " Failed to post to #$name"
|
|
211
|
+
fi
|
|
212
|
+
|
|
213
|
+
# Rate limit: Don't spam Teams API
|
|
214
|
+
sleep 1
|
|
215
|
+
done
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
**When to use**: Announcements, alerts, status updates across channels.
|
|
219
|
+
|
|
220
|
+
## Pattern 6: File Upload with Context
|
|
221
|
+
|
|
222
|
+
**Use case**: Share a file with explanation
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
#!/bin/bash
|
|
226
|
+
|
|
227
|
+
CHANNEL_ID="19:abc123@thread.tacv2"
|
|
228
|
+
REPORT_FILE="./daily-report.pdf"
|
|
229
|
+
|
|
230
|
+
# Upload file
|
|
231
|
+
UPLOAD_RESULT=$(agent-teams file upload "$CHANNEL_ID" "$REPORT_FILE")
|
|
232
|
+
|
|
233
|
+
if echo "$UPLOAD_RESULT" | jq -e '.id' > /dev/null 2>&1; then
|
|
234
|
+
FILE_ID=$(echo "$UPLOAD_RESULT" | jq -r '.id')
|
|
235
|
+
echo "File uploaded: $FILE_ID"
|
|
236
|
+
|
|
237
|
+
# Send context message
|
|
238
|
+
agent-teams message send "$CHANNEL_ID" "Daily report is ready! Key highlights:
|
|
239
|
+
- 95% test coverage
|
|
240
|
+
- 3 bugs fixed
|
|
241
|
+
- 2 new features deployed"
|
|
242
|
+
else
|
|
243
|
+
echo "Upload failed: $(echo "$UPLOAD_RESULT" | jq -r '.error')"
|
|
244
|
+
exit 1
|
|
245
|
+
fi
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
**When to use**: Automated reporting, log sharing, artifact distribution.
|
|
249
|
+
|
|
250
|
+
## Pattern 7: User Lookup and Mention
|
|
251
|
+
|
|
252
|
+
**Use case**: Find a user and mention them in a message
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
#!/bin/bash
|
|
256
|
+
|
|
257
|
+
CHANNEL_ID="19:abc123@thread.tacv2"
|
|
258
|
+
USERNAME="john"
|
|
259
|
+
|
|
260
|
+
# Get team members
|
|
261
|
+
USERS=$(agent-teams user list)
|
|
262
|
+
USER=$(echo "$USERS" | jq -r --arg name "$USERNAME" 'first(.[] | select(.displayName | ascii_downcase | contains($name | ascii_downcase)))')
|
|
263
|
+
USER_ID=$(echo "$USER" | jq -r '.id')
|
|
264
|
+
USER_NAME=$(echo "$USER" | jq -r '.displayName')
|
|
265
|
+
|
|
266
|
+
if [ -z "$USER_ID" ] || [ "$USER_ID" = "null" ]; then
|
|
267
|
+
echo "User $USERNAME not found"
|
|
268
|
+
exit 1
|
|
269
|
+
fi
|
|
270
|
+
|
|
271
|
+
# Send message with mention (Teams format)
|
|
272
|
+
agent-teams message send "$CHANNEL_ID" "Hey <at id=\"$USER_ID\">$USER_NAME</at>, the build is ready for review!"
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
**When to use**: Notifications, task assignments, code review requests.
|
|
276
|
+
|
|
277
|
+
**Note**: Teams mentions use format `<at id="USER_ID">Display Name</at>`.
|
|
278
|
+
|
|
279
|
+
## Pattern 8: Reaction-Based Workflow
|
|
280
|
+
|
|
281
|
+
**Use case**: Use reactions as simple state indicators
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
#!/bin/bash
|
|
285
|
+
|
|
286
|
+
CHANNEL_ID="19:abc123@thread.tacv2"
|
|
287
|
+
|
|
288
|
+
# Send deployment message
|
|
289
|
+
RESULT=$(agent-teams message send "$CHANNEL_ID" "Deploying v2.1.0 to production...")
|
|
290
|
+
MSG_ID=$(echo "$RESULT" | jq -r '.id')
|
|
291
|
+
|
|
292
|
+
# Mark as in-progress
|
|
293
|
+
agent-teams reaction add "$CHANNEL_ID" "$MSG_ID" "hourglass"
|
|
294
|
+
|
|
295
|
+
# Simulate deployment
|
|
296
|
+
sleep 5
|
|
297
|
+
|
|
298
|
+
# Remove in-progress, add success
|
|
299
|
+
agent-teams reaction remove "$CHANNEL_ID" "$MSG_ID" "hourglass"
|
|
300
|
+
agent-teams reaction add "$CHANNEL_ID" "$MSG_ID" "checkmark"
|
|
301
|
+
|
|
302
|
+
# Send completion message
|
|
303
|
+
agent-teams message send "$CHANNEL_ID" "Deployed v2.1.0 to production successfully!"
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
**When to use**: Visual status tracking, workflow states, quick acknowledgments.
|
|
307
|
+
|
|
308
|
+
## Pattern 9: Error Handling with Token Refresh
|
|
309
|
+
|
|
310
|
+
**Use case**: Robust message sending with retries and token refresh
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
#!/bin/bash
|
|
314
|
+
|
|
315
|
+
send_with_retry() {
|
|
316
|
+
local channel_id=$1
|
|
317
|
+
local message=$2
|
|
318
|
+
local max_attempts=3
|
|
319
|
+
local attempt=1
|
|
320
|
+
|
|
321
|
+
while [ $attempt -le $max_attempts ]; do
|
|
322
|
+
echo "Attempt $attempt/$max_attempts..."
|
|
323
|
+
|
|
324
|
+
RESULT=$(agent-teams message send "$channel_id" "$message")
|
|
325
|
+
|
|
326
|
+
if echo "$RESULT" | jq -e '.id' > /dev/null 2>&1; then
|
|
327
|
+
echo "Message sent successfully!"
|
|
328
|
+
return 0
|
|
329
|
+
fi
|
|
330
|
+
|
|
331
|
+
ERROR=$(echo "$RESULT" | jq -r '.error // "Unknown error"')
|
|
332
|
+
echo "Failed: $ERROR"
|
|
333
|
+
|
|
334
|
+
# Handle token expiry - refresh and retry
|
|
335
|
+
if echo "$ERROR" | grep -qi "expired\|401\|unauthorized"; then
|
|
336
|
+
echo "Token expired, refreshing..."
|
|
337
|
+
agent-teams auth extract
|
|
338
|
+
# Don't count this as an attempt
|
|
339
|
+
continue
|
|
340
|
+
fi
|
|
341
|
+
|
|
342
|
+
# Don't retry on certain errors
|
|
343
|
+
if echo "$ERROR" | grep -q "Channel not found"; then
|
|
344
|
+
echo "Channel not found - not retrying"
|
|
345
|
+
return 1
|
|
346
|
+
fi
|
|
347
|
+
|
|
348
|
+
if [ $attempt -lt $max_attempts ]; then
|
|
349
|
+
sleep $((attempt * 2)) # Exponential backoff
|
|
350
|
+
fi
|
|
351
|
+
|
|
352
|
+
attempt=$((attempt + 1))
|
|
353
|
+
done
|
|
354
|
+
|
|
355
|
+
echo "Failed after $max_attempts attempts"
|
|
356
|
+
return 1
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
# Usage
|
|
360
|
+
CHANNEL_ID="19:abc123@thread.tacv2"
|
|
361
|
+
send_with_retry "$CHANNEL_ID" "Important message!"
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
**When to use**: Production scripts, critical notifications, unreliable networks.
|
|
365
|
+
|
|
366
|
+
## Pattern 10: Switch Teams for Operations
|
|
367
|
+
|
|
368
|
+
**Use case**: Work with multiple Teams
|
|
369
|
+
|
|
370
|
+
```bash
|
|
371
|
+
#!/bin/bash
|
|
372
|
+
|
|
373
|
+
# List all teams
|
|
374
|
+
TEAMS=$(agent-teams team list)
|
|
375
|
+
echo "Available teams:"
|
|
376
|
+
echo "$TEAMS" | jq -r '.[] | " \(.name) (\(.id)) \(if .current then "[current]" else "" end)"'
|
|
377
|
+
|
|
378
|
+
# Switch to a specific team
|
|
379
|
+
TARGET_TEAM=$(echo "$TEAMS" | jq -r '.[] | select(.name | contains("Production")) | .id')
|
|
380
|
+
if [ -n "$TARGET_TEAM" ]; then
|
|
381
|
+
agent-teams team switch "$TARGET_TEAM"
|
|
382
|
+
echo "Switched to Production team"
|
|
383
|
+
fi
|
|
384
|
+
|
|
385
|
+
# Now operations use the new team
|
|
386
|
+
agent-teams channel list
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
**When to use**: Managing multiple teams, cross-team operations.
|
|
390
|
+
|
|
391
|
+
## Pattern 11: Token Refresh Wrapper (TEAMS-SPECIFIC)
|
|
392
|
+
|
|
393
|
+
**Use case**: Wrap any operation with automatic token refresh
|
|
394
|
+
|
|
395
|
+
```bash
|
|
396
|
+
#!/bin/bash
|
|
397
|
+
|
|
398
|
+
# Wrapper function that handles token refresh
|
|
399
|
+
teams_cmd() {
|
|
400
|
+
local result
|
|
401
|
+
|
|
402
|
+
# First attempt
|
|
403
|
+
result=$("$@" 2>&1)
|
|
404
|
+
|
|
405
|
+
# Check for token expiry
|
|
406
|
+
if echo "$result" | grep -qi "expired\|401\|unauthorized"; then
|
|
407
|
+
echo "Token expired, refreshing..." >&2
|
|
408
|
+
agent-teams auth extract >&2
|
|
409
|
+
|
|
410
|
+
# Retry
|
|
411
|
+
result=$("$@" 2>&1)
|
|
412
|
+
fi
|
|
413
|
+
|
|
414
|
+
echo "$result"
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
# Usage - wrap any agent-teams command
|
|
418
|
+
CHANNELS=$(teams_cmd agent-teams channel list)
|
|
419
|
+
RESULT=$(teams_cmd agent-teams message send "$CHANNEL_ID" "Hello!")
|
|
420
|
+
SNAPSHOT=$(teams_cmd agent-teams snapshot)
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
**When to use**: Any script that runs for more than a few minutes.
|
|
424
|
+
|
|
425
|
+
## Best Practices
|
|
426
|
+
|
|
427
|
+
### 1. Always Handle Token Expiry
|
|
428
|
+
|
|
429
|
+
```bash
|
|
430
|
+
# Good - handle token expiry
|
|
431
|
+
RESULT=$(agent-teams message send "$CHANNEL_ID" "Hello")
|
|
432
|
+
if echo "$RESULT" | grep -qi "expired\|401"; then
|
|
433
|
+
agent-teams auth extract
|
|
434
|
+
RESULT=$(agent-teams message send "$CHANNEL_ID" "Hello")
|
|
435
|
+
fi
|
|
436
|
+
|
|
437
|
+
# Bad - assume token is always valid
|
|
438
|
+
agent-teams message send "$CHANNEL_ID" "Hello"
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
### 2. Refresh Token Proactively for Long-Running Scripts
|
|
442
|
+
|
|
443
|
+
```bash
|
|
444
|
+
# Good - check token age periodically
|
|
445
|
+
while true; do
|
|
446
|
+
STATUS=$(agent-teams auth status)
|
|
447
|
+
if [ "$(echo "$STATUS" | jq -r '.token_expires_soon')" = "true" ]; then
|
|
448
|
+
agent-teams auth extract
|
|
449
|
+
fi
|
|
450
|
+
|
|
451
|
+
# Do work...
|
|
452
|
+
sleep 60
|
|
453
|
+
done
|
|
454
|
+
|
|
455
|
+
# Bad - wait for failure
|
|
456
|
+
while true; do
|
|
457
|
+
agent-teams message send "$CHANNEL_ID" "Status update" # Will fail after 60-90 min
|
|
458
|
+
sleep 60
|
|
459
|
+
done
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
### 3. Always Get Channel IDs First
|
|
463
|
+
|
|
464
|
+
```bash
|
|
465
|
+
# Good - look up channel ID
|
|
466
|
+
CHANNELS=$(agent-teams channel list)
|
|
467
|
+
CHANNEL_ID=$(echo "$CHANNELS" | jq -r '.[] | select(.name=="General") | .id')
|
|
468
|
+
agent-teams message send "$CHANNEL_ID" "Hello"
|
|
469
|
+
|
|
470
|
+
# Bad - hardcoded IDs without documentation
|
|
471
|
+
agent-teams message send "19:abc123@thread.tacv2" "Hello"
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
### 4. Check for Success
|
|
475
|
+
|
|
476
|
+
```bash
|
|
477
|
+
# Good
|
|
478
|
+
RESULT=$(agent-teams message send "$CHANNEL_ID" "Hello")
|
|
479
|
+
if echo "$RESULT" | jq -e '.id' > /dev/null 2>&1; then
|
|
480
|
+
echo "Success!"
|
|
481
|
+
else
|
|
482
|
+
echo "Failed: $(echo "$RESULT" | jq -r '.error')"
|
|
483
|
+
fi
|
|
484
|
+
|
|
485
|
+
# Bad
|
|
486
|
+
agent-teams message send "$CHANNEL_ID" "Hello" # No error checking
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
### 5. Rate Limit Your Requests
|
|
490
|
+
|
|
491
|
+
```bash
|
|
492
|
+
# Good - respect Teams API limits
|
|
493
|
+
for channel_id in "${CHANNEL_IDS[@]}"; do
|
|
494
|
+
agent-teams message send "$channel_id" "$MESSAGE"
|
|
495
|
+
sleep 1 # 1 second between requests
|
|
496
|
+
done
|
|
497
|
+
|
|
498
|
+
# Bad - rapid-fire requests
|
|
499
|
+
for channel_id in "${CHANNEL_IDS[@]}"; do
|
|
500
|
+
agent-teams message send "$channel_id" "$MESSAGE"
|
|
501
|
+
done
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
### 6. Cache Channel Lists
|
|
505
|
+
|
|
506
|
+
```bash
|
|
507
|
+
# Good - fetch once, reuse
|
|
508
|
+
CHANNELS=$(agent-teams channel list)
|
|
509
|
+
for name in "${CHANNEL_NAMES[@]}"; do
|
|
510
|
+
id=$(echo "$CHANNELS" | jq -r --arg n "$name" '.[] | select(.name==$n) | .id')
|
|
511
|
+
agent-teams message send "$id" "$MESSAGE"
|
|
512
|
+
done
|
|
513
|
+
|
|
514
|
+
# Bad - fetch repeatedly
|
|
515
|
+
for name in "${CHANNEL_NAMES[@]}"; do
|
|
516
|
+
CHANNELS=$(agent-teams channel list) # Wasteful!
|
|
517
|
+
id=$(echo "$CHANNELS" | jq -r --arg n "$name" '.[] | select(.name==$n) | .id')
|
|
518
|
+
agent-teams message send "$id" "$MESSAGE"
|
|
519
|
+
done
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
## Anti-Patterns
|
|
523
|
+
|
|
524
|
+
### Don't Ignore Token Expiry
|
|
525
|
+
|
|
526
|
+
```bash
|
|
527
|
+
# Bad - ignores the 60-90 minute token limit
|
|
528
|
+
while true; do
|
|
529
|
+
agent-teams message list "$CHANNEL_ID" --limit 1
|
|
530
|
+
sleep 10
|
|
531
|
+
done
|
|
532
|
+
# Will fail silently after ~1 hour
|
|
533
|
+
|
|
534
|
+
# Good - handle token refresh
|
|
535
|
+
while true; do
|
|
536
|
+
# Check and refresh token periodically
|
|
537
|
+
if should_refresh_token; then
|
|
538
|
+
agent-teams auth extract
|
|
539
|
+
fi
|
|
540
|
+
|
|
541
|
+
agent-teams message list "$CHANNEL_ID" --limit 1
|
|
542
|
+
sleep 10
|
|
543
|
+
done
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
### Don't Poll Too Frequently
|
|
547
|
+
|
|
548
|
+
```bash
|
|
549
|
+
# Bad - polls every second (may get rate limited)
|
|
550
|
+
while true; do
|
|
551
|
+
agent-teams message list "$CHANNEL_ID" --limit 1
|
|
552
|
+
sleep 1
|
|
553
|
+
done
|
|
554
|
+
|
|
555
|
+
# Good - reasonable interval
|
|
556
|
+
while true; do
|
|
557
|
+
agent-teams message list "$CHANNEL_ID" --limit 1
|
|
558
|
+
sleep 10 # 10 seconds
|
|
559
|
+
done
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
### Don't Ignore Errors
|
|
563
|
+
|
|
564
|
+
```bash
|
|
565
|
+
# Bad
|
|
566
|
+
agent-teams message send "$CHANNEL_ID" "Hello"
|
|
567
|
+
# Continues even if it failed
|
|
568
|
+
|
|
569
|
+
# Good
|
|
570
|
+
RESULT=$(agent-teams message send "$CHANNEL_ID" "Hello")
|
|
571
|
+
if ! echo "$RESULT" | jq -e '.id' > /dev/null 2>&1; then
|
|
572
|
+
echo "Failed to send message"
|
|
573
|
+
exit 1
|
|
574
|
+
fi
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
### Don't Spam Channels
|
|
578
|
+
|
|
579
|
+
```bash
|
|
580
|
+
# Bad - sends 100 messages
|
|
581
|
+
for i in {1..100}; do
|
|
582
|
+
agent-teams message send "$CHANNEL_ID" "Message $i"
|
|
583
|
+
done
|
|
584
|
+
|
|
585
|
+
# Good - batch into single message
|
|
586
|
+
MESSAGE="Updates:"
|
|
587
|
+
for i in {1..100}; do
|
|
588
|
+
MESSAGE="$MESSAGE\n$i. Item $i"
|
|
589
|
+
done
|
|
590
|
+
agent-teams message send "$CHANNEL_ID" "$MESSAGE"
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
## See Also
|
|
594
|
+
|
|
595
|
+
- [Authentication Guide](authentication.md) - Setting up credentials and token management
|
|
596
|
+
- [Templates](../templates/) - Runnable example scripts
|