agent-messenger 2.10.2 → 2.11.1
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/plugin.json +1 -1
- package/.env.template +4 -1
- package/README.md +77 -27
- package/bun.lock +26 -0
- package/dist/package.json +21 -1
- package/dist/src/platforms/channeltalk/commands/auth.d.ts +2 -1
- package/dist/src/platforms/channeltalk/commands/auth.d.ts.map +1 -1
- package/dist/src/platforms/channeltalk/commands/auth.js +5 -3
- package/dist/src/platforms/channeltalk/commands/auth.js.map +1 -1
- package/dist/src/platforms/channeltalk/token-extractor.d.ts +2 -1
- package/dist/src/platforms/channeltalk/token-extractor.d.ts.map +1 -1
- package/dist/src/platforms/channeltalk/token-extractor.js +22 -6
- package/dist/src/platforms/channeltalk/token-extractor.js.map +1 -1
- package/dist/src/platforms/channeltalkbot/cli.d.ts.map +1 -1
- package/dist/src/platforms/channeltalkbot/cli.js +11 -1
- package/dist/src/platforms/channeltalkbot/cli.js.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/auth.d.ts.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/auth.js +1 -5
- package/dist/src/platforms/channeltalkbot/commands/auth.js.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/bot.d.ts.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/bot.js +1 -6
- package/dist/src/platforms/channeltalkbot/commands/bot.js.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/chat.d.ts.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/chat.js +1 -6
- package/dist/src/platforms/channeltalkbot/commands/chat.js.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/group.d.ts.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/group.js +1 -6
- package/dist/src/platforms/channeltalkbot/commands/group.js.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/manager.d.ts.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/manager.js +1 -6
- package/dist/src/platforms/channeltalkbot/commands/manager.js.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/message.d.ts.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/message.js +1 -6
- package/dist/src/platforms/channeltalkbot/commands/message.js.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/whoami.d.ts.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/whoami.js +1 -6
- package/dist/src/platforms/channeltalkbot/commands/whoami.js.map +1 -1
- package/dist/src/platforms/channeltalkbot/credential-manager.d.ts +5 -0
- package/dist/src/platforms/channeltalkbot/credential-manager.d.ts.map +1 -1
- package/dist/src/platforms/channeltalkbot/credential-manager.js +34 -4
- package/dist/src/platforms/channeltalkbot/credential-manager.js.map +1 -1
- package/dist/src/platforms/discord/commands/auth.d.ts +1 -0
- package/dist/src/platforms/discord/commands/auth.d.ts.map +1 -1
- package/dist/src/platforms/discord/commands/auth.js +3 -1
- package/dist/src/platforms/discord/commands/auth.js.map +1 -1
- package/dist/src/platforms/discord/listener.d.ts +2 -0
- package/dist/src/platforms/discord/listener.d.ts.map +1 -1
- package/dist/src/platforms/discord/listener.js +51 -21
- package/dist/src/platforms/discord/listener.js.map +1 -1
- package/dist/src/platforms/discord/token-extractor.d.ts +2 -1
- package/dist/src/platforms/discord/token-extractor.d.ts.map +1 -1
- package/dist/src/platforms/discord/token-extractor.js +21 -6
- package/dist/src/platforms/discord/token-extractor.js.map +1 -1
- package/dist/src/platforms/discordbot/cli.d.ts.map +1 -1
- package/dist/src/platforms/discordbot/cli.js +12 -1
- package/dist/src/platforms/discordbot/cli.js.map +1 -1
- package/dist/src/platforms/discordbot/client.d.ts +3 -0
- package/dist/src/platforms/discordbot/client.d.ts.map +1 -1
- package/dist/src/platforms/discordbot/client.js +3 -0
- package/dist/src/platforms/discordbot/client.js.map +1 -1
- package/dist/src/platforms/discordbot/commands/auth.d.ts.map +1 -1
- package/dist/src/platforms/discordbot/commands/auth.js +1 -5
- package/dist/src/platforms/discordbot/commands/auth.js.map +1 -1
- package/dist/src/platforms/discordbot/commands/message.d.ts.map +1 -1
- package/dist/src/platforms/discordbot/commands/message.js +1 -6
- package/dist/src/platforms/discordbot/commands/message.js.map +1 -1
- package/dist/src/platforms/discordbot/commands/server.d.ts.map +1 -1
- package/dist/src/platforms/discordbot/commands/server.js +1 -4
- package/dist/src/platforms/discordbot/commands/server.js.map +1 -1
- package/dist/src/platforms/discordbot/commands/whoami.d.ts.map +1 -1
- package/dist/src/platforms/discordbot/commands/whoami.js +1 -6
- package/dist/src/platforms/discordbot/commands/whoami.js.map +1 -1
- package/dist/src/platforms/discordbot/index.d.ts +3 -1
- package/dist/src/platforms/discordbot/index.d.ts.map +1 -1
- package/dist/src/platforms/discordbot/index.js +2 -1
- package/dist/src/platforms/discordbot/index.js.map +1 -1
- package/dist/src/platforms/discordbot/listener.d.ts +43 -0
- package/dist/src/platforms/discordbot/listener.d.ts.map +1 -0
- package/dist/src/platforms/discordbot/listener.js +292 -0
- package/dist/src/platforms/discordbot/listener.js.map +1 -0
- package/dist/src/platforms/discordbot/types.d.ts +161 -0
- package/dist/src/platforms/discordbot/types.d.ts.map +1 -1
- package/dist/src/platforms/discordbot/types.js +34 -0
- package/dist/src/platforms/discordbot/types.js.map +1 -1
- package/dist/src/platforms/instagram/commands/auth.d.ts.map +1 -1
- package/dist/src/platforms/instagram/commands/auth.js +3 -1
- package/dist/src/platforms/instagram/commands/auth.js.map +1 -1
- package/dist/src/platforms/instagram/token-extractor.d.ts +2 -1
- package/dist/src/platforms/instagram/token-extractor.d.ts.map +1 -1
- package/dist/src/platforms/instagram/token-extractor.js +11 -2
- package/dist/src/platforms/instagram/token-extractor.js.map +1 -1
- package/dist/src/platforms/slack/commands/auth.d.ts.map +1 -1
- package/dist/src/platforms/slack/commands/auth.js +4 -2
- package/dist/src/platforms/slack/commands/auth.js.map +1 -1
- package/dist/src/platforms/slack/token-extractor.d.ts +4 -1
- package/dist/src/platforms/slack/token-extractor.d.ts.map +1 -1
- package/dist/src/platforms/slack/token-extractor.js +64 -15
- package/dist/src/platforms/slack/token-extractor.js.map +1 -1
- package/dist/src/platforms/slackbot/cli.d.ts.map +1 -1
- package/dist/src/platforms/slackbot/cli.js +15 -3
- package/dist/src/platforms/slackbot/cli.js.map +1 -1
- package/dist/src/platforms/slackbot/client.d.ts +22 -1
- package/dist/src/platforms/slackbot/client.d.ts.map +1 -1
- package/dist/src/platforms/slackbot/client.js +104 -1
- package/dist/src/platforms/slackbot/client.js.map +1 -1
- package/dist/src/platforms/slackbot/commands/auth.d.ts.map +1 -1
- package/dist/src/platforms/slackbot/commands/auth.js +1 -5
- package/dist/src/platforms/slackbot/commands/auth.js.map +1 -1
- package/dist/src/platforms/slackbot/commands/file.d.ts +3 -0
- package/dist/src/platforms/slackbot/commands/file.d.ts.map +1 -0
- package/dist/src/platforms/slackbot/commands/file.js +164 -0
- package/dist/src/platforms/slackbot/commands/file.js.map +1 -0
- package/dist/src/platforms/slackbot/commands/index.d.ts +1 -0
- package/dist/src/platforms/slackbot/commands/index.d.ts.map +1 -1
- package/dist/src/platforms/slackbot/commands/index.js +1 -0
- package/dist/src/platforms/slackbot/commands/index.js.map +1 -1
- package/dist/src/platforms/slackbot/commands/message.d.ts.map +1 -1
- package/dist/src/platforms/slackbot/commands/message.js +19 -0
- package/dist/src/platforms/slackbot/commands/message.js.map +1 -1
- package/dist/src/platforms/slackbot/commands/whoami.d.ts.map +1 -1
- package/dist/src/platforms/slackbot/commands/whoami.js +1 -6
- package/dist/src/platforms/slackbot/commands/whoami.js.map +1 -1
- package/dist/src/platforms/slackbot/credential-manager.d.ts +1 -0
- package/dist/src/platforms/slackbot/credential-manager.d.ts.map +1 -1
- package/dist/src/platforms/slackbot/credential-manager.js +30 -2
- package/dist/src/platforms/slackbot/credential-manager.js.map +1 -1
- package/dist/src/platforms/slackbot/index.d.ts +4 -1
- package/dist/src/platforms/slackbot/index.d.ts.map +1 -1
- package/dist/src/platforms/slackbot/index.js +1 -0
- package/dist/src/platforms/slackbot/index.js.map +1 -1
- package/dist/src/platforms/slackbot/listener.d.ts +44 -0
- package/dist/src/platforms/slackbot/listener.d.ts.map +1 -0
- package/dist/src/platforms/slackbot/listener.js +313 -0
- package/dist/src/platforms/slackbot/listener.js.map +1 -0
- package/dist/src/platforms/slackbot/types.d.ts +196 -1
- package/dist/src/platforms/slackbot/types.d.ts.map +1 -1
- package/dist/src/platforms/slackbot/types.js +4 -1
- package/dist/src/platforms/slackbot/types.js.map +1 -1
- package/dist/src/platforms/teams/commands/auth.d.ts +1 -0
- package/dist/src/platforms/teams/commands/auth.d.ts.map +1 -1
- package/dist/src/platforms/teams/commands/auth.js +37 -6
- package/dist/src/platforms/teams/commands/auth.js.map +1 -1
- package/dist/src/platforms/teams/ensure-auth.js +31 -9
- package/dist/src/platforms/teams/ensure-auth.js.map +1 -1
- package/dist/src/platforms/teams/token-extractor.d.ts +4 -1
- package/dist/src/platforms/teams/token-extractor.d.ts.map +1 -1
- package/dist/src/platforms/teams/token-extractor.js +71 -29
- package/dist/src/platforms/teams/token-extractor.js.map +1 -1
- package/dist/src/platforms/webex/commands/auth.d.ts +1 -0
- package/dist/src/platforms/webex/commands/auth.d.ts.map +1 -1
- package/dist/src/platforms/webex/commands/auth.js +3 -1
- package/dist/src/platforms/webex/commands/auth.js.map +1 -1
- package/dist/src/platforms/webex/token-extractor.d.ts +3 -1
- package/dist/src/platforms/webex/token-extractor.d.ts.map +1 -1
- package/dist/src/platforms/webex/token-extractor.js +16 -2
- package/dist/src/platforms/webex/token-extractor.js.map +1 -1
- package/dist/src/platforms/wechatbot/cli.d.ts.map +1 -1
- package/dist/src/platforms/wechatbot/cli.js +11 -1
- package/dist/src/platforms/wechatbot/cli.js.map +1 -1
- package/dist/src/platforms/wechatbot/commands/auth.d.ts.map +1 -1
- package/dist/src/platforms/wechatbot/commands/auth.js +1 -5
- package/dist/src/platforms/wechatbot/commands/auth.js.map +1 -1
- package/dist/src/platforms/wechatbot/commands/message.d.ts.map +1 -1
- package/dist/src/platforms/wechatbot/commands/message.js +1 -6
- package/dist/src/platforms/wechatbot/commands/message.js.map +1 -1
- package/dist/src/platforms/wechatbot/commands/template.d.ts.map +1 -1
- package/dist/src/platforms/wechatbot/commands/template.js +1 -6
- package/dist/src/platforms/wechatbot/commands/template.js.map +1 -1
- package/dist/src/platforms/wechatbot/commands/user.d.ts.map +1 -1
- package/dist/src/platforms/wechatbot/commands/user.js +1 -6
- package/dist/src/platforms/wechatbot/commands/user.js.map +1 -1
- package/dist/src/platforms/wechatbot/commands/whoami.d.ts.map +1 -1
- package/dist/src/platforms/wechatbot/commands/whoami.js +1 -6
- package/dist/src/platforms/wechatbot/commands/whoami.js.map +1 -1
- package/dist/src/platforms/whatsappbot/cli.d.ts.map +1 -1
- package/dist/src/platforms/whatsappbot/cli.js +11 -1
- package/dist/src/platforms/whatsappbot/cli.js.map +1 -1
- package/dist/src/platforms/whatsappbot/commands/auth.d.ts.map +1 -1
- package/dist/src/platforms/whatsappbot/commands/auth.js +1 -5
- package/dist/src/platforms/whatsappbot/commands/auth.js.map +1 -1
- package/dist/src/platforms/whatsappbot/commands/message.d.ts.map +1 -1
- package/dist/src/platforms/whatsappbot/commands/message.js +1 -6
- package/dist/src/platforms/whatsappbot/commands/message.js.map +1 -1
- package/dist/src/platforms/whatsappbot/commands/template.d.ts.map +1 -1
- package/dist/src/platforms/whatsappbot/commands/template.js +1 -6
- package/dist/src/platforms/whatsappbot/commands/template.js.map +1 -1
- package/dist/src/platforms/whatsappbot/commands/whoami.d.ts.map +1 -1
- package/dist/src/platforms/whatsappbot/commands/whoami.js +1 -6
- package/dist/src/platforms/whatsappbot/commands/whoami.js.map +1 -1
- package/dist/src/shared/chromium/browsers.d.ts +8 -0
- package/dist/src/shared/chromium/browsers.d.ts.map +1 -1
- package/dist/src/shared/chromium/browsers.js +58 -3
- package/dist/src/shared/chromium/browsers.js.map +1 -1
- package/dist/src/shared/chromium/cli-options.d.ts +5 -0
- package/dist/src/shared/chromium/cli-options.d.ts.map +1 -0
- package/dist/src/shared/chromium/cli-options.js +8 -0
- package/dist/src/shared/chromium/cli-options.js.map +1 -0
- package/dist/src/shared/chromium/index.d.ts +3 -1
- package/dist/src/shared/chromium/index.d.ts.map +1 -1
- package/dist/src/shared/chromium/index.js +2 -1
- package/dist/src/shared/chromium/index.js.map +1 -1
- package/dist/src/shared/utils/cli-output.d.ts +7 -0
- package/dist/src/shared/utils/cli-output.d.ts.map +1 -0
- package/dist/src/shared/utils/cli-output.js +7 -0
- package/dist/src/shared/utils/cli-output.js.map +1 -0
- package/dist/src/tui/app.d.ts.map +1 -1
- package/dist/src/tui/app.js +73 -20
- package/dist/src/tui/app.js.map +1 -1
- package/docs/content/docs/cli/channeltalk.mdx +4 -0
- package/docs/content/docs/cli/discord.mdx +5 -0
- package/docs/content/docs/cli/instagram.mdx +3 -0
- package/docs/content/docs/cli/slack.mdx +5 -0
- package/docs/content/docs/cli/slackbot.mdx +60 -22
- package/docs/content/docs/cli/teams.mdx +5 -0
- package/docs/content/docs/cli/webex.mdx +3 -0
- package/docs/content/docs/sdk/channeltalkbot.mdx +38 -1
- package/docs/content/docs/sdk/discordbot.mdx +501 -0
- package/docs/content/docs/sdk/meta.json +2 -0
- package/docs/content/docs/sdk/slackbot.mdx +576 -0
- package/e2e/README.md +1 -1
- package/e2e/config.ts +9 -4
- package/examples/discordbot-listen.ts +65 -0
- package/examples/slackbot-listen.ts +65 -0
- package/package.json +21 -1
- package/skills/agent-channeltalk/SKILL.md +5 -1
- package/skills/agent-channeltalk/references/authentication.md +5 -1
- package/skills/agent-channeltalkbot/SKILL.md +17 -3
- package/skills/agent-channeltalkbot/references/authentication.md +7 -5
- package/skills/agent-discord/SKILL.md +5 -1
- package/skills/agent-discord/references/authentication.md +7 -1
- package/skills/agent-discordbot/SKILL.md +13 -2
- package/skills/agent-discordbot/references/common-patterns.md +1 -1
- package/skills/agent-instagram/SKILL.md +7 -1
- package/skills/agent-instagram/references/authentication.md +6 -0
- package/skills/agent-kakaotalk/SKILL.md +1 -1
- package/skills/agent-line/SKILL.md +1 -1
- package/skills/agent-slack/SKILL.md +5 -1
- package/skills/agent-slack/references/authentication.md +7 -1
- package/skills/agent-slackbot/SKILL.md +56 -4
- package/skills/agent-slackbot/references/authentication.md +4 -0
- package/skills/agent-teams/SKILL.md +5 -1
- package/skills/agent-teams/references/authentication.md +7 -1
- package/skills/agent-telegram/SKILL.md +1 -1
- package/skills/agent-webex/SKILL.md +7 -1
- package/skills/agent-webex/references/authentication.md +6 -0
- package/skills/agent-wechatbot/SKILL.md +16 -1
- package/skills/agent-wechatbot/references/authentication.md +219 -0
- package/skills/agent-wechatbot/references/common-patterns.md +358 -0
- package/skills/agent-wechatbot/templates/account-summary.sh +122 -0
- package/skills/agent-wechatbot/templates/post-message.sh +122 -0
- package/skills/agent-wechatbot/templates/send-template.sh +152 -0
- package/skills/agent-whatsapp/SKILL.md +1 -1
- package/skills/agent-whatsappbot/SKILL.md +30 -1
- package/src/platforms/channeltalk/commands/auth.test.ts +15 -3
- package/src/platforms/channeltalk/commands/auth.ts +15 -5
- package/src/platforms/channeltalk/token-extractor.ts +24 -5
- package/src/platforms/channeltalkbot/cli.ts +9 -0
- package/src/platforms/channeltalkbot/commands/auth.ts +1 -5
- package/src/platforms/channeltalkbot/commands/bot.ts +1 -6
- package/src/platforms/channeltalkbot/commands/chat.ts +1 -6
- package/src/platforms/channeltalkbot/commands/group.ts +1 -6
- package/src/platforms/channeltalkbot/commands/manager.ts +1 -6
- package/src/platforms/channeltalkbot/commands/message.ts +1 -6
- package/src/platforms/channeltalkbot/commands/whoami.test.ts +2 -0
- package/src/platforms/channeltalkbot/commands/whoami.ts +1 -6
- package/src/platforms/channeltalkbot/credential-manager.test.ts +96 -2
- package/src/platforms/channeltalkbot/credential-manager.ts +37 -4
- package/src/platforms/discord/commands/auth.ts +13 -2
- package/src/platforms/discord/listener.test.ts +59 -1
- package/src/platforms/discord/listener.ts +43 -19
- package/src/platforms/discord/token-extractor.ts +30 -6
- package/src/platforms/discordbot/cli.ts +10 -0
- package/src/platforms/discordbot/client.ts +4 -0
- package/src/platforms/discordbot/commands/auth.ts +1 -5
- package/src/platforms/discordbot/commands/message.ts +1 -6
- package/src/platforms/discordbot/commands/server.ts +1 -5
- package/src/platforms/discordbot/commands/whoami.ts +1 -6
- package/src/platforms/discordbot/index.test.ts +82 -0
- package/src/platforms/discordbot/index.ts +27 -9
- package/src/platforms/discordbot/listener.test.ts +1002 -0
- package/src/platforms/discordbot/listener.ts +321 -0
- package/src/platforms/discordbot/types.ts +163 -0
- package/src/platforms/instagram/commands/auth.ts +9 -1
- package/src/platforms/instagram/token-extractor.ts +13 -1
- package/src/platforms/slack/commands/auth.ts +11 -2
- package/src/platforms/slack/token-extractor.test.ts +96 -0
- package/src/platforms/slack/token-extractor.ts +76 -13
- package/src/platforms/slackbot/cli.ts +13 -1
- package/src/platforms/slackbot/client.test.ts +274 -0
- package/src/platforms/slackbot/client.ts +130 -2
- package/src/platforms/slackbot/commands/auth.ts +1 -5
- package/src/platforms/slackbot/commands/file.test.ts +201 -0
- package/src/platforms/slackbot/commands/file.ts +212 -0
- package/src/platforms/slackbot/commands/index.ts +1 -0
- package/src/platforms/slackbot/commands/message.ts +22 -0
- package/src/platforms/slackbot/commands/whoami.ts +1 -6
- package/src/platforms/slackbot/credential-manager.test.ts +62 -2
- package/src/platforms/slackbot/credential-manager.ts +32 -2
- package/src/platforms/slackbot/index.test.ts +59 -0
- package/src/platforms/slackbot/index.ts +31 -7
- package/src/platforms/slackbot/listener.test.ts +1012 -0
- package/src/platforms/slackbot/listener.ts +362 -0
- package/src/platforms/slackbot/types.ts +224 -1
- package/src/platforms/teams/commands/auth.test.ts +1 -1
- package/src/platforms/teams/commands/auth.ts +66 -7
- package/src/platforms/teams/ensure-auth.test.ts +56 -5
- package/src/platforms/teams/ensure-auth.ts +39 -11
- package/src/platforms/teams/token-extractor.test.ts +146 -24
- package/src/platforms/teams/token-extractor.ts +87 -29
- package/src/platforms/webex/commands/auth.ts +13 -2
- package/src/platforms/webex/token-extractor.ts +25 -3
- package/src/platforms/wechatbot/cli.ts +9 -0
- package/src/platforms/wechatbot/commands/auth.ts +1 -5
- package/src/platforms/wechatbot/commands/message.ts +1 -6
- package/src/platforms/wechatbot/commands/template.ts +1 -6
- package/src/platforms/wechatbot/commands/user.ts +1 -6
- package/src/platforms/wechatbot/commands/whoami.ts +1 -6
- package/src/platforms/whatsappbot/cli.ts +9 -0
- package/src/platforms/whatsappbot/commands/auth.ts +1 -5
- package/src/platforms/whatsappbot/commands/message.ts +1 -6
- package/src/platforms/whatsappbot/commands/template.ts +1 -6
- package/src/platforms/whatsappbot/commands/whoami.ts +1 -6
- package/src/shared/chromium/browsers.test.ts +80 -0
- package/src/shared/chromium/browsers.ts +72 -3
- package/src/shared/chromium/cli-options.test.ts +22 -0
- package/src/shared/chromium/cli-options.ts +12 -0
- package/src/shared/chromium/index.ts +3 -0
- package/src/shared/utils/cli-output.test.ts +57 -0
- package/src/shared/utils/cli-output.ts +8 -0
- package/src/tui/app.ts +129 -20
|
@@ -28,10 +28,16 @@ agent-webex auth extract
|
|
|
28
28
|
|
|
29
29
|
# With debug output
|
|
30
30
|
agent-webex auth extract --debug
|
|
31
|
+
|
|
32
|
+
# Scan custom Chromium profile/user-data dirs (repeatable or comma-separated)
|
|
33
|
+
agent-webex auth extract --browser-profile ~/browser-data
|
|
34
|
+
agent-webex auth extract --browser-profile "$HOME/work-profile,$HOME/personal-profile"
|
|
31
35
|
```
|
|
32
36
|
|
|
33
37
|
**Requirements**: You must be logged into web.webex.com in a supported Chromium browser. The browser does not need to be running — the CLI reads directly from on-disk LevelDB files.
|
|
34
38
|
|
|
39
|
+
Use `--browser-profile <path>` for agent-browser profiles, custom Chrome user data dirs, or portable browser profiles. The option can be repeated or given comma-separated paths.
|
|
40
|
+
|
|
35
41
|
**Limitations**: Direct messages (`message dm`) require an existing conversation with the recipient. The extracted token cannot create new 1:1 conversations — start one from the Webex app first, then use the CLI.
|
|
36
42
|
|
|
37
43
|
### OAuth Device Grant
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: agent-wechatbot
|
|
3
3
|
description: Interact with WeChat Official Account using API credentials - send messages, manage templates, list followers
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.11.1
|
|
5
5
|
allowed-tools: Bash(agent-wechatbot:*)
|
|
6
6
|
metadata:
|
|
7
7
|
openclaw:
|
|
@@ -255,6 +255,8 @@ agent-wechatbot template list --pretty
|
|
|
255
255
|
|
|
256
256
|
## Common Patterns
|
|
257
257
|
|
|
258
|
+
See `references/common-patterns.md` for additional workflows.
|
|
259
|
+
|
|
258
260
|
### Send a customer service message within 48h window
|
|
259
261
|
|
|
260
262
|
Customer service messages can be sent to users who have interacted with your account within the last 48 hours:
|
|
@@ -305,6 +307,14 @@ agent-wechatbot template send oABCD1234 deployment_alert \
|
|
|
305
307
|
--data '{"version":{"value":"v2.1.0"},"environment":{"value":"production"},"status":{"value":"success"}}'
|
|
306
308
|
```
|
|
307
309
|
|
|
310
|
+
## Templates
|
|
311
|
+
|
|
312
|
+
See `templates/` directory for runnable examples:
|
|
313
|
+
|
|
314
|
+
- `post-message.sh` - Send a customer service message with error handling and retries
|
|
315
|
+
- `account-summary.sh` - Generate account, template, and follower summary
|
|
316
|
+
- `send-template.sh` - Send a template message with parameters
|
|
317
|
+
|
|
308
318
|
## Error Handling
|
|
309
319
|
|
|
310
320
|
All commands return consistent error format:
|
|
@@ -392,3 +402,8 @@ These indicate an expired or invalid access token. The CLI handles automatic tok
|
|
|
392
402
|
### Rate limiting (45009)
|
|
393
403
|
|
|
394
404
|
WeChat enforces API call frequency limits. If you hit error `45009`, wait before retrying. For bulk operations, add delays between requests.
|
|
405
|
+
|
|
406
|
+
## References
|
|
407
|
+
|
|
408
|
+
- [Authentication Guide](references/authentication.md)
|
|
409
|
+
- [Common Patterns](references/common-patterns.md)
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# Authentication Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
agent-wechatbot uses the WeChat Official Account API with App ID + App Secret authentication. Credentials come from the WeChat Official Account admin panel. No desktop app extraction or pairing codes needed.
|
|
6
|
+
|
|
7
|
+
## API Credential Setup
|
|
8
|
+
|
|
9
|
+
### How It Works
|
|
10
|
+
|
|
11
|
+
1. You log in to the WeChat Official Account admin panel
|
|
12
|
+
2. Open **Development > Basic Configuration**
|
|
13
|
+
3. Copy your **App ID** and **App Secret**
|
|
14
|
+
4. Add your server's IP to the **IP Whitelist**
|
|
15
|
+
5. Store both credentials in the CLI with `auth set`
|
|
16
|
+
|
|
17
|
+
The CLI validates credentials against the WeChat Official Account API before saving.
|
|
18
|
+
|
|
19
|
+
### Setting Credentials
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
agent-wechatbot auth set <app-id> <app-secret>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Response on success:
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{ "success": true, "app_id": "wx1234567890", "account_name": "wx1234567890" }
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Response on failure:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"error": "Invalid credentials. Check your App ID and App Secret."
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Getting Credentials from the WeChat Admin Panel
|
|
40
|
+
|
|
41
|
+
1. Log in to the [WeChat Official Account admin panel](https://mp.weixin.qq.com/)
|
|
42
|
+
2. Navigate to **Development > Basic Configuration**
|
|
43
|
+
3. **App ID**: shown directly under "Developer ID (AppID)"
|
|
44
|
+
4. **App Secret**: under "Developer Password (AppSecret)" — click **View** or **Reset** to retrieve. The secret is shown only once on creation; keep it safe.
|
|
45
|
+
5. **IP Whitelist**: in the same screen, add the IP address(es) of any server that will run the CLI. WeChat returns error `40164` if the calling IP is not whitelisted.
|
|
46
|
+
6. Run `agent-wechatbot auth set <app-id> <app-secret>`
|
|
47
|
+
|
|
48
|
+
### Access Token Lifecycle
|
|
49
|
+
|
|
50
|
+
WeChat issues a short-lived access token internally on every API call. The CLI handles token caching and refresh automatically:
|
|
51
|
+
|
|
52
|
+
- **Access tokens** expire after 7200 seconds (2 hours)
|
|
53
|
+
- The CLI fetches a new token on demand and caches it in memory for the duration of the process
|
|
54
|
+
- You do **not** store the access token yourself — only the App ID + App Secret
|
|
55
|
+
|
|
56
|
+
## Multi-Account Management
|
|
57
|
+
|
|
58
|
+
Multiple WeChat Official Accounts can be stored simultaneously.
|
|
59
|
+
|
|
60
|
+
### List Accounts
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
agent-wechatbot auth list
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
[
|
|
68
|
+
{
|
|
69
|
+
"account_id": "wx1234567890",
|
|
70
|
+
"app_id": "wx1234567890",
|
|
71
|
+
"account_name": "Acme Notifications",
|
|
72
|
+
"current": true
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"account_id": "wx0987654321",
|
|
76
|
+
"app_id": "wx0987654321",
|
|
77
|
+
"account_name": "Acme Marketing",
|
|
78
|
+
"current": false
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Switch Account
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
agent-wechatbot auth use wx0987654321
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Per-Command Account
|
|
90
|
+
|
|
91
|
+
Commands accept `--account <id>` to use a specific account without switching:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
agent-wechatbot message send oABCD1234 "Hello" --account wx0987654321
|
|
95
|
+
agent-wechatbot template list --account wx0987654321
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Remove Account
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
agent-wechatbot auth remove <account-id>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Credential Storage
|
|
105
|
+
|
|
106
|
+
### Location
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
~/.config/agent-messenger/wechatbot-credentials.json
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Format
|
|
113
|
+
|
|
114
|
+
```json
|
|
115
|
+
{
|
|
116
|
+
"current": { "account_id": "wx1234567890" },
|
|
117
|
+
"accounts": {
|
|
118
|
+
"wx1234567890": {
|
|
119
|
+
"app_id": "wx1234567890",
|
|
120
|
+
"app_secret": "...",
|
|
121
|
+
"account_name": "wx1234567890"
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Security
|
|
128
|
+
|
|
129
|
+
- File permissions: `0600` (owner read/write only)
|
|
130
|
+
- App secrets are stored in plaintext
|
|
131
|
+
- Keep this file secure. The App Secret grants full messaging access to your Official Account
|
|
132
|
+
- Never commit to version control
|
|
133
|
+
|
|
134
|
+
## Authentication Status
|
|
135
|
+
|
|
136
|
+
Check current auth state:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
agent-wechatbot auth status
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Output when authenticated:
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"authenticated": true,
|
|
147
|
+
"account_id": "wx1234567890",
|
|
148
|
+
"app_id": "wx1234567890",
|
|
149
|
+
"account_name": "Acme Notifications"
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Output when not authenticated:
|
|
154
|
+
|
|
155
|
+
```json
|
|
156
|
+
{
|
|
157
|
+
"error": "No credentials. Run \"auth set <app-id> <app-secret>\" first."
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Check a specific account:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
agent-wechatbot auth status --account wx0987654321
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Clear Credentials
|
|
168
|
+
|
|
169
|
+
Remove all stored credentials:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
agent-wechatbot auth clear
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Re-authentication
|
|
176
|
+
|
|
177
|
+
If commands start failing with auth errors:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
# Check current status
|
|
181
|
+
agent-wechatbot auth status
|
|
182
|
+
|
|
183
|
+
# Re-set credentials (e.g., after rotating the App Secret)
|
|
184
|
+
agent-wechatbot auth set <app-id> <new-app-secret>
|
|
185
|
+
|
|
186
|
+
# Verify it worked
|
|
187
|
+
agent-wechatbot auth status
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Common Auth Errors
|
|
191
|
+
|
|
192
|
+
| WeChat errcode | Meaning | Fix |
|
|
193
|
+
| -------------- | ----------------------------------------------- | ----------------------------------------------------------------------------------------- |
|
|
194
|
+
| `40001` | Invalid access token | Token rotation race; retry. Persistent errors mean the App Secret is wrong. |
|
|
195
|
+
| `40013` | Invalid App ID | Verify the App ID matches your account in the admin panel |
|
|
196
|
+
| `40125` | Invalid App Secret | The App Secret is incorrect. Reset it in the admin panel and re-run `auth set`. |
|
|
197
|
+
| `40164` | Calling IP not in IP whitelist | Add your server's public IP to the IP Whitelist in **Development > Basic Configuration**. |
|
|
198
|
+
| `42001` | Access token expired | The CLI will refresh automatically. Persistent errors indicate a network issue. |
|
|
199
|
+
| `45009` | API call frequency limit exceeded | Slow down. Add delays between calls in batch operations. |
|
|
200
|
+
|
|
201
|
+
## Security Considerations
|
|
202
|
+
|
|
203
|
+
### What agent-wechatbot Can Access
|
|
204
|
+
|
|
205
|
+
With stored credentials, agent-wechatbot can:
|
|
206
|
+
|
|
207
|
+
- Send customer service messages (text, image, news) to followers within the 48h window
|
|
208
|
+
- Send pre-approved template messages to followers at any time
|
|
209
|
+
- List and inspect message templates
|
|
210
|
+
- List followers and retrieve follower info (OpenID, language, subscribe time)
|
|
211
|
+
|
|
212
|
+
### What agent-wechatbot Cannot Do
|
|
213
|
+
|
|
214
|
+
- Read or list received messages (webhook-only for inbound)
|
|
215
|
+
- Access group chats (Official Accounts are 1:1 with followers)
|
|
216
|
+
- Make voice or video calls
|
|
217
|
+
- Manage Official Account settings
|
|
218
|
+
- Upload media (images must be uploaded to WeChat's media platform separately and referenced by media ID)
|
|
219
|
+
- Edit or delete sent messages
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
# Common Patterns
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This guide covers typical workflows for AI agents interacting with WeChat Official Account API using agent-wechatbot.
|
|
6
|
+
|
|
7
|
+
## Pattern 1: Send a Customer Service Message
|
|
8
|
+
|
|
9
|
+
**Use case**: Reply to a follower within the 48-hour customer service window
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
#!/bin/bash
|
|
13
|
+
|
|
14
|
+
OPENID="oABCD1234"
|
|
15
|
+
|
|
16
|
+
# Direct approach
|
|
17
|
+
agent-wechatbot message send "$OPENID" "Thanks for reaching out!"
|
|
18
|
+
|
|
19
|
+
# With error handling
|
|
20
|
+
RESULT=$(agent-wechatbot message send "$OPENID" "Hello")
|
|
21
|
+
if echo "$RESULT" | jq -e '.error' > /dev/null 2>&1; then
|
|
22
|
+
echo "Failed: $(echo "$RESULT" | jq -r '.error')"
|
|
23
|
+
exit 1
|
|
24
|
+
fi
|
|
25
|
+
echo "Message sent"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**When to use**: Replying to a follower who interacted with the Official Account in the last 48 hours.
|
|
29
|
+
|
|
30
|
+
**Note**: Free-form text only works within the 48-hour customer service window. Outside that window, use template messages.
|
|
31
|
+
|
|
32
|
+
## Pattern 2: Send a Template Notification
|
|
33
|
+
|
|
34
|
+
**Use case**: Send a pre-approved template message at any time
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
#!/bin/bash
|
|
38
|
+
|
|
39
|
+
OPENID="oABCD1234"
|
|
40
|
+
TEMPLATE_ID="TM00001"
|
|
41
|
+
|
|
42
|
+
# First, list available templates
|
|
43
|
+
agent-wechatbot template list --pretty
|
|
44
|
+
|
|
45
|
+
# Send the template with data
|
|
46
|
+
agent-wechatbot template send "$OPENID" "$TEMPLATE_ID" \
|
|
47
|
+
--data '{"order_id":{"value":"ORD-9876"},"customer_name":{"value":"Alice"}}' \
|
|
48
|
+
--url "https://example.com/orders/9876"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**When to use**: Order confirmations, shipping updates, appointment reminders, system notifications outside the 48h window.
|
|
52
|
+
|
|
53
|
+
**Important**: Templates must be created and approved in the WeChat admin panel before use.
|
|
54
|
+
|
|
55
|
+
## Pattern 3: Discover Templates
|
|
56
|
+
|
|
57
|
+
**Use case**: Find the right template and its required parameters
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
#!/bin/bash
|
|
61
|
+
|
|
62
|
+
# List all templates
|
|
63
|
+
TEMPLATES=$(agent-wechatbot template list)
|
|
64
|
+
|
|
65
|
+
# Extract required parameters for each template
|
|
66
|
+
echo "$TEMPLATES" | jq '.template_list[] | {template_id, title, content, example}'
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**When to use**: First time sending templates, or when you need to verify parameter structure.
|
|
70
|
+
|
|
71
|
+
## Pattern 4: Send a News/Article Message
|
|
72
|
+
|
|
73
|
+
**Use case**: Share a rich content card with a follower
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
#!/bin/bash
|
|
77
|
+
|
|
78
|
+
OPENID="oABCD1234"
|
|
79
|
+
|
|
80
|
+
agent-wechatbot message send-news "$OPENID" \
|
|
81
|
+
--title "Your Order Update" \
|
|
82
|
+
--description "Your order #12345 has shipped and will arrive in 3 days" \
|
|
83
|
+
--url "https://example.com/orders/12345" \
|
|
84
|
+
--picurl "https://example.com/images/shipping.jpg"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**When to use**: Sending order updates, blog posts, marketing content with a clickable card. Within 48h window only.
|
|
88
|
+
|
|
89
|
+
## Pattern 5: Send an Image Message
|
|
90
|
+
|
|
91
|
+
**Use case**: Share an image with a follower (requires pre-uploaded media ID)
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
#!/bin/bash
|
|
95
|
+
|
|
96
|
+
OPENID="oABCD1234"
|
|
97
|
+
MEDIA_ID="MEDIA_ID_FROM_UPLOAD_API" # Obtain via WeChat's media upload API separately
|
|
98
|
+
|
|
99
|
+
agent-wechatbot message send-image "$OPENID" "$MEDIA_ID"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**When to use**: Product photos, QR codes, support screenshots. Within 48h window only.
|
|
103
|
+
|
|
104
|
+
**Note**: Images must be uploaded to WeChat's media platform first using the [media upload API](https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/New_temporary_materials.html). The CLI does not handle media upload; it expects an existing `media_id`.
|
|
105
|
+
|
|
106
|
+
## Pattern 6: List and Inspect Followers
|
|
107
|
+
|
|
108
|
+
**Use case**: Discover follower OpenIDs and basic info
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
#!/bin/bash
|
|
112
|
+
|
|
113
|
+
# Get first page of followers (up to 10,000)
|
|
114
|
+
FOLLOWERS=$(agent-wechatbot user list)
|
|
115
|
+
|
|
116
|
+
# Extract OpenIDs
|
|
117
|
+
echo "$FOLLOWERS" | jq -r '.data.openid[]'
|
|
118
|
+
|
|
119
|
+
# Paginate (next page)
|
|
120
|
+
NEXT=$(echo "$FOLLOWERS" | jq -r '.next_openid')
|
|
121
|
+
if [ -n "$NEXT" ] && [ "$NEXT" != "null" ]; then
|
|
122
|
+
agent-wechatbot user list --next-openid "$NEXT"
|
|
123
|
+
fi
|
|
124
|
+
|
|
125
|
+
# Get details for a specific follower
|
|
126
|
+
agent-wechatbot user get oABCD1234 --pretty
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**When to use**: Building a follower list for broadcasts, discovering OpenIDs to message.
|
|
130
|
+
|
|
131
|
+
## Pattern 7: Multi-Recipient Template Notification
|
|
132
|
+
|
|
133
|
+
**Use case**: Send the same template to multiple followers
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
#!/bin/bash
|
|
137
|
+
|
|
138
|
+
TEMPLATE_ID="TM00001"
|
|
139
|
+
OPENIDS=("oABCD1234" "oEFGH5678" "oIJKL9012")
|
|
140
|
+
|
|
141
|
+
for openid in "${OPENIDS[@]}"; do
|
|
142
|
+
echo "Sending to $openid..."
|
|
143
|
+
RESULT=$(agent-wechatbot template send "$openid" "$TEMPLATE_ID" \
|
|
144
|
+
--data '{"order_id":{"value":"ORD-001"},"status":{"value":"shipped"}}')
|
|
145
|
+
|
|
146
|
+
if echo "$RESULT" | jq -e '.error' > /dev/null 2>&1; then
|
|
147
|
+
echo " Failed: $(echo "$RESULT" | jq -r '.error')"
|
|
148
|
+
else
|
|
149
|
+
echo " Sent"
|
|
150
|
+
fi
|
|
151
|
+
|
|
152
|
+
# Respect rate limits
|
|
153
|
+
sleep 1
|
|
154
|
+
done
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**When to use**: Broadcasting order updates, scheduled reminders, bulk notifications.
|
|
158
|
+
|
|
159
|
+
## Pattern 8: Multi-Account Workflow
|
|
160
|
+
|
|
161
|
+
**Use case**: Send from different Official Accounts
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
#!/bin/bash
|
|
165
|
+
|
|
166
|
+
# Send from notifications account
|
|
167
|
+
agent-wechatbot template send oABCD1234 TM00001 \
|
|
168
|
+
--data '{"order_id":{"value":"ORD-001"}}' \
|
|
169
|
+
--account wx1234567890
|
|
170
|
+
|
|
171
|
+
# Send from marketing account
|
|
172
|
+
agent-wechatbot message send oABCD1234 "Check out our new products!" \
|
|
173
|
+
--account wx0987654321
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**When to use**: Managing multiple Official Accounts (notifications, marketing, support).
|
|
177
|
+
|
|
178
|
+
## Pattern 9: CI/CD Deployment Notification
|
|
179
|
+
|
|
180
|
+
**Use case**: Notify a team via template after deployment
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
#!/bin/bash
|
|
184
|
+
|
|
185
|
+
VERSION="v2.1.0"
|
|
186
|
+
ENVIRONMENT="production"
|
|
187
|
+
STATUS="success"
|
|
188
|
+
ON_CALL_OPENID="oABCD1234"
|
|
189
|
+
|
|
190
|
+
agent-wechatbot template send "$ON_CALL_OPENID" deployment_alert \
|
|
191
|
+
--data "{\"version\":{\"value\":\"$VERSION\"},\"environment\":{\"value\":\"$ENVIRONMENT\"},\"status\":{\"value\":\"$STATUS\"}}" \
|
|
192
|
+
--url "https://ci.example.com/builds/$VERSION"
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**When to use**: Automated deployment notifications, build status alerts.
|
|
196
|
+
|
|
197
|
+
## Pattern 10: Error Handling and Retry
|
|
198
|
+
|
|
199
|
+
**Use case**: Robust message sending with retries
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
#!/bin/bash
|
|
203
|
+
|
|
204
|
+
send_with_retry() {
|
|
205
|
+
local openid=$1
|
|
206
|
+
local message=$2
|
|
207
|
+
local max_attempts=3
|
|
208
|
+
local attempt=1
|
|
209
|
+
|
|
210
|
+
while [ $attempt -le $max_attempts ]; do
|
|
211
|
+
echo "Attempt $attempt/$max_attempts..."
|
|
212
|
+
|
|
213
|
+
RESULT=$(agent-wechatbot message send "$openid" "$message" 2>&1)
|
|
214
|
+
|
|
215
|
+
if ! echo "$RESULT" | jq -e '.error' > /dev/null 2>&1; then
|
|
216
|
+
echo "Message sent!"
|
|
217
|
+
return 0
|
|
218
|
+
fi
|
|
219
|
+
|
|
220
|
+
ERROR=$(echo "$RESULT" | jq -r '.error')
|
|
221
|
+
echo "Failed: $ERROR"
|
|
222
|
+
|
|
223
|
+
# Don't retry auth errors
|
|
224
|
+
if echo "$ERROR" | grep -q "No credentials"; then
|
|
225
|
+
echo "Not authenticated. Run: agent-wechatbot auth set <app-id> <app-secret>"
|
|
226
|
+
return 1
|
|
227
|
+
fi
|
|
228
|
+
|
|
229
|
+
# Don't retry IP whitelist errors
|
|
230
|
+
if echo "$ERROR" | grep -q "40164"; then
|
|
231
|
+
echo "IP not whitelisted. Add server IP in WeChat admin panel."
|
|
232
|
+
return 1
|
|
233
|
+
fi
|
|
234
|
+
|
|
235
|
+
# Don't retry if outside 48h window
|
|
236
|
+
if echo "$ERROR" | grep -q "48h\|48-hour"; then
|
|
237
|
+
echo "Use template messages instead: agent-wechatbot template send ..."
|
|
238
|
+
return 1
|
|
239
|
+
fi
|
|
240
|
+
|
|
241
|
+
if [ $attempt -lt $max_attempts ]; then
|
|
242
|
+
SLEEP_TIME=$((attempt * 3))
|
|
243
|
+
echo "Retrying in ${SLEEP_TIME}s..."
|
|
244
|
+
sleep $SLEEP_TIME
|
|
245
|
+
fi
|
|
246
|
+
|
|
247
|
+
attempt=$((attempt + 1))
|
|
248
|
+
done
|
|
249
|
+
|
|
250
|
+
echo "Failed after $max_attempts attempts"
|
|
251
|
+
return 1
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
# Usage
|
|
255
|
+
send_with_retry "oABCD1234" "Important update!"
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
**When to use**: Production scripts, critical notifications, unreliable networks.
|
|
259
|
+
|
|
260
|
+
## Best Practices
|
|
261
|
+
|
|
262
|
+
### 1. Cache Template Info
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
# Good: discover once, reuse
|
|
266
|
+
TEMPLATES=$(agent-wechatbot template list)
|
|
267
|
+
# ... use template info for multiple sends
|
|
268
|
+
|
|
269
|
+
# Bad: fetch templates before every send
|
|
270
|
+
agent-wechatbot template list # Wasteful
|
|
271
|
+
agent-wechatbot template send ...
|
|
272
|
+
agent-wechatbot template list # Wasteful
|
|
273
|
+
agent-wechatbot template send ...
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### 2. Use Memory for Known Templates
|
|
277
|
+
|
|
278
|
+
Store frequently used template IDs and their parameters in `~/.config/agent-messenger/MEMORY.md` to skip `template list` calls in future sessions.
|
|
279
|
+
|
|
280
|
+
### 3. Respect Rate Limits
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
# Good: pause between operations
|
|
284
|
+
for openid in "${OPENIDS[@]}"; do
|
|
285
|
+
agent-wechatbot template send "$openid" "$TEMPLATE_ID" ...
|
|
286
|
+
sleep 1
|
|
287
|
+
done
|
|
288
|
+
|
|
289
|
+
# Bad: rapid-fire (will hit errcode 45009)
|
|
290
|
+
for openid in "${OPENIDS[@]}"; do
|
|
291
|
+
agent-wechatbot template send "$openid" "$TEMPLATE_ID" ...
|
|
292
|
+
done
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### 4. Check Auth Before Multi-Step Workflows
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
# Good: verify auth upfront
|
|
299
|
+
STATUS=$(agent-wechatbot auth status)
|
|
300
|
+
if echo "$STATUS" | jq -e '.error' > /dev/null 2>&1; then
|
|
301
|
+
echo "Not authenticated"
|
|
302
|
+
exit 1
|
|
303
|
+
fi
|
|
304
|
+
|
|
305
|
+
# Proceed with workflow
|
|
306
|
+
agent-wechatbot template list
|
|
307
|
+
agent-wechatbot template send ...
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### 5. Use Templates for Proactive Messages
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
# Bad: will fail outside 48h window
|
|
314
|
+
agent-wechatbot message send oABCD1234 "Your order shipped!"
|
|
315
|
+
|
|
316
|
+
# Good: works anytime
|
|
317
|
+
agent-wechatbot template send oABCD1234 shipping_update \
|
|
318
|
+
--data '{"order_id":{"value":"ORD-001"}}'
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
## Anti-Patterns
|
|
322
|
+
|
|
323
|
+
### Don't Send Customer Service Messages Outside the 48h Window
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
# Bad: will fail if follower hasn't interacted recently
|
|
327
|
+
agent-wechatbot message send oABCD1234 "Reminder: your appointment is tomorrow"
|
|
328
|
+
|
|
329
|
+
# Good: use a template
|
|
330
|
+
agent-wechatbot template send oABCD1234 appointment_reminder \
|
|
331
|
+
--data '{"date":{"value":"2024-01-15"},"time":{"value":"14:00"}}'
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### Don't Hardcode Template Data Structure
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
# Bad: fragile if template parameters change
|
|
338
|
+
agent-wechatbot template send oABCD1234 order_confirmation \
|
|
339
|
+
--data '{"name":{"value":"Alice"}}'
|
|
340
|
+
|
|
341
|
+
# Good: verify template structure first
|
|
342
|
+
TEMPLATE=$(agent-wechatbot template list | jq '.template_list[] | select(.template_id=="TM00001")')
|
|
343
|
+
# Inspect required parameters, then build data dynamically
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### Don't Forget the IP Whitelist
|
|
347
|
+
|
|
348
|
+
```bash
|
|
349
|
+
# Bad: deploying to a new server without updating the WeChat admin panel
|
|
350
|
+
# Result: errcode 40164 — IP not in whitelist
|
|
351
|
+
|
|
352
|
+
# Good: add the server IP to the WeChat admin panel BEFORE deploying
|
|
353
|
+
# Development > Basic Configuration > IP Whitelist
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
## See Also
|
|
357
|
+
|
|
358
|
+
- [Authentication Guide](authentication.md) - Setting up API credentials
|