agent-messenger 2.10.2 → 2.11.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/plugin.json +1 -1
- package/.env.template +4 -1
- package/README.md +77 -27
- package/bun.lock +26 -0
- package/dist/package.json +14 -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 +14 -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
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Discord Bot
|
|
3
|
+
description: TypeScript SDK reference for Discord Bot — client, real-time Gateway listener, credential management, and types.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install agent-messenger
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import {
|
|
14
|
+
DiscordBotClient,
|
|
15
|
+
DiscordBotCredentialManager,
|
|
16
|
+
DiscordBotError,
|
|
17
|
+
DiscordBotListener,
|
|
18
|
+
} from 'agent-messenger/discordbot'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## DiscordBotClient
|
|
22
|
+
|
|
23
|
+
The main client for interacting with Discord's REST API using a bot token. All methods include automatic rate-limit handling with per-bucket and global rate-limit tracking.
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { DiscordBotClient } from 'agent-messenger/discordbot'
|
|
27
|
+
|
|
28
|
+
const client = await new DiscordBotClient().login({ token: 'YOUR_BOT_TOKEN' })
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or use stored credentials — credentials are read from `~/.config/agent-messenger/discordbot-credentials.json` (managed by `agent-discordbot auth set`):
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
const client = await new DiscordBotClient().login()
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Authentication
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
// Verify bot credentials and get the bot's identity
|
|
41
|
+
const me = await client.testAuth()
|
|
42
|
+
// → DiscordUser { id, username, global_name?, avatar?, bot? }
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Servers (Guilds)
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
// List all servers the bot has been added to
|
|
49
|
+
const guilds = await client.listGuilds()
|
|
50
|
+
// → DiscordGuild[]
|
|
51
|
+
|
|
52
|
+
// Get a specific server by ID
|
|
53
|
+
const guild = await client.getGuild(guildId)
|
|
54
|
+
// → DiscordGuild { id, name, icon?, owner? }
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Channels
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
// List all channels in a server
|
|
61
|
+
const channels = await client.listChannels(guildId)
|
|
62
|
+
// → DiscordChannel[]
|
|
63
|
+
|
|
64
|
+
// Get a specific channel by ID
|
|
65
|
+
const channel = await client.getChannel(channelId)
|
|
66
|
+
// → DiscordChannel { id, guild_id, name, type, topic?, position?, parent_id?, thread_metadata? }
|
|
67
|
+
|
|
68
|
+
// Resolve a channel by name or ID — returns the channel ID
|
|
69
|
+
const channelId = await client.resolveChannel(guildId, '#general')
|
|
70
|
+
const sameId = await client.resolveChannel(guildId, '1234567890123456789')
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Messages
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
// Send a message to a channel
|
|
77
|
+
const msg = await client.sendMessage(channelId, 'Hello world')
|
|
78
|
+
|
|
79
|
+
// Send a message in a thread
|
|
80
|
+
const reply = await client.sendMessage(channelId, 'Reply', { thread_id: threadId })
|
|
81
|
+
// → DiscordMessage { id, channel_id, author, content, timestamp }
|
|
82
|
+
|
|
83
|
+
// Get recent messages from a channel (default limit: 50)
|
|
84
|
+
const messages = await client.getMessages(channelId)
|
|
85
|
+
const limited = await client.getMessages(channelId, 25)
|
|
86
|
+
// → DiscordMessage[]
|
|
87
|
+
|
|
88
|
+
// Get a single message by ID
|
|
89
|
+
const message = await client.getMessage(channelId, messageId)
|
|
90
|
+
// → DiscordMessage
|
|
91
|
+
|
|
92
|
+
// Edit a message (bot can only edit its own messages)
|
|
93
|
+
const edited = await client.editMessage(channelId, messageId, 'Updated content')
|
|
94
|
+
// → DiscordMessage
|
|
95
|
+
|
|
96
|
+
// Delete a message (bot can delete its own messages or any with Manage Messages permission)
|
|
97
|
+
await client.deleteMessage(channelId, messageId)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Reactions
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
// Add a reaction (use a standard emoji or `name:id` for custom emojis)
|
|
104
|
+
await client.addReaction(channelId, messageId, '👍')
|
|
105
|
+
await client.addReaction(channelId, messageId, 'custom_emoji_name:123456789')
|
|
106
|
+
|
|
107
|
+
// Remove the bot's own reaction
|
|
108
|
+
await client.removeReaction(channelId, messageId, '👍')
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Users
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
// List members in a server (up to 1000 at a time)
|
|
115
|
+
const users = await client.listUsers(guildId)
|
|
116
|
+
// → DiscordUser[]
|
|
117
|
+
|
|
118
|
+
// Get a user by ID
|
|
119
|
+
const user = await client.getUser(userId)
|
|
120
|
+
// → DiscordUser { id, username, global_name?, avatar?, bot? }
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Files
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
// Upload a file to a channel (by file path)
|
|
127
|
+
const file = await client.uploadFile(channelId, '/path/to/report.pdf')
|
|
128
|
+
// → DiscordFile { id, filename, size, url, content_type?, height?, width? }
|
|
129
|
+
|
|
130
|
+
// List file attachments from recent messages in a channel
|
|
131
|
+
const files = await client.listFiles(channelId)
|
|
132
|
+
// → DiscordFile[]
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Threads
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
// Create a thread in a channel
|
|
139
|
+
const thread = await client.createThread(channelId, 'Bug Report: Login Issue')
|
|
140
|
+
const configured = await client.createThread(channelId, 'Design Review', {
|
|
141
|
+
auto_archive_duration: 1440, // minutes: 60, 1440, 4320, or 10080
|
|
142
|
+
rate_limit_per_user: 5, // seconds between messages (slow mode)
|
|
143
|
+
})
|
|
144
|
+
// → DiscordChannel (with thread_metadata)
|
|
145
|
+
|
|
146
|
+
// Archive (or unarchive) a thread
|
|
147
|
+
await client.archiveThread(threadId)
|
|
148
|
+
await client.archiveThread(threadId, false) // unarchive
|
|
149
|
+
// → DiscordChannel
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Real-Time Events
|
|
153
|
+
|
|
154
|
+
`DiscordBotListener` connects to Discord's [Gateway WebSocket](https://discord.com/developers/docs/topics/gateway) for instant event streaming — messages, reactions, slash command interactions, member changes, and more. No webhook server required.
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { DiscordBotClient, DiscordBotListener } from 'agent-messenger/discordbot'
|
|
158
|
+
|
|
159
|
+
const client = await new DiscordBotClient().login({ token })
|
|
160
|
+
const listener = new DiscordBotListener(client)
|
|
161
|
+
|
|
162
|
+
listener.on('connected', (info) => {
|
|
163
|
+
console.log(`Connected as ${info.user.username} (session ${info.sessionId})`)
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
listener.on('message_create', (event) => {
|
|
167
|
+
if (event.author.bot) return
|
|
168
|
+
console.log(`#${event.channel_id} <${event.author.username}>: ${event.content}`)
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
listener.on('interaction_create', (event) => {
|
|
172
|
+
console.log(`Slash command: ${(event.data as { name?: string } | undefined)?.name}`)
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
listener.on('error', (err) => console.error(err))
|
|
176
|
+
|
|
177
|
+
await listener.start() // connects via Gateway WebSocket
|
|
178
|
+
// listener.stop() // clean shutdown
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Intents
|
|
182
|
+
|
|
183
|
+
Discord Gateway requires [intents](https://discord.com/developers/docs/topics/gateway#gateway-intents) — a bitfield that opts the bot into specific event categories. The default set includes safe, non-privileged intents for messages, reactions, and typing in guilds and DMs.
|
|
184
|
+
|
|
185
|
+
To customize intents, pass `DiscordIntent` flags:
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import { DiscordIntent } from 'agent-messenger/discordbot'
|
|
189
|
+
|
|
190
|
+
const listener = new DiscordBotListener(client, {
|
|
191
|
+
intents:
|
|
192
|
+
DiscordIntent.Guilds |
|
|
193
|
+
DiscordIntent.GuildMessages |
|
|
194
|
+
DiscordIntent.GuildMessageReactions |
|
|
195
|
+
DiscordIntent.DirectMessages |
|
|
196
|
+
DiscordIntent.MessageContent, // privileged — must enable in Developer Portal
|
|
197
|
+
})
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
> **Privileged intents** (`MessageContent`, `GuildMembers`, `GuildPresences`) must be explicitly enabled in the [Discord Developer Portal](https://discord.com/developers/applications) under your bot's settings before they can be requested. Connecting with a privileged intent that is not enabled will close the Gateway with code `4014`.
|
|
201
|
+
>
|
|
202
|
+
> Without `MessageContent`, the `content` field on `message_create` events will be empty for messages that don't mention the bot or arrive in DMs.
|
|
203
|
+
|
|
204
|
+
### Available Events
|
|
205
|
+
|
|
206
|
+
| Event | Description |
|
|
207
|
+
| ------------------------------------------------------ | --------------------------------------------------- |
|
|
208
|
+
| `message_create` | New message in a guild channel or DM |
|
|
209
|
+
| `message_update` | Message content edited |
|
|
210
|
+
| `message_delete` | Message deleted |
|
|
211
|
+
| `message_reaction_add` / `message_reaction_remove` | Reaction added or removed |
|
|
212
|
+
| `guild_member_add` / `guild_member_remove` | Member joins or leaves a server |
|
|
213
|
+
| `presence_update` | User status changed (requires `GuildPresences`) |
|
|
214
|
+
| `typing_start` | Typing indicator |
|
|
215
|
+
| `channel_create` / `channel_update` / `channel_delete` | Channel lifecycle |
|
|
216
|
+
| `guild_create` / `guild_update` / `guild_delete` | Bot added to / updated in / removed from a server |
|
|
217
|
+
| `interaction_create` | Slash command, button, modal, or context menu fired |
|
|
218
|
+
| `discord_event` | Catch-all — fires for every Gateway dispatch |
|
|
219
|
+
| `connected` / `disconnected` | Connection lifecycle |
|
|
220
|
+
| `error` | Connection or protocol error |
|
|
221
|
+
|
|
222
|
+
### Lifecycle Features
|
|
223
|
+
|
|
224
|
+
- **Auto-reconnect** with exponential backoff (1s → 30s, capped) and jitter on heartbeats.
|
|
225
|
+
- **Session resume** — reconnects use Discord's `resume_gateway_url` to replay missed events without re-identifying.
|
|
226
|
+
- **Heartbeat keepalive** with zombie connection detection — if Discord doesn't acknowledge a heartbeat, the connection is closed and re-established.
|
|
227
|
+
- **Non-recoverable close detection** — connections close cleanly on close codes `4004` (invalid token), `4010`–`4014` (sharding/intents misconfiguration). The listener emits `error` and stops.
|
|
228
|
+
- **Session reset** on close codes `4007` (invalid sequence) and `4009` (session timed out) — clears local session state and reconnects fresh.
|
|
229
|
+
- **Stale-socket safety** — every async callback is generation-guarded so a stop+start cycle cannot leave the new connection in a broken state.
|
|
230
|
+
|
|
231
|
+
## DiscordBotCredentialManager
|
|
232
|
+
|
|
233
|
+
Manages bot credentials stored at `~/.config/agent-messenger/discordbot-credentials.json` with `0o600` permissions. Supports multiple bot identities (e.g., a deploy bot and an alerts bot in the same config). The environment variables `E2E_DISCORDBOT_TOKEN`, `E2E_DISCORDBOT_SERVER_ID`, and `E2E_DISCORDBOT_SERVER_NAME` take precedence over file-based credentials.
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
import { DiscordBotCredentialManager } from 'agent-messenger/discordbot'
|
|
237
|
+
|
|
238
|
+
const manager = new DiscordBotCredentialManager()
|
|
239
|
+
// Custom path: new DiscordBotCredentialManager('/custom/config/dir')
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
// Load full config from disk (returns defaults if file doesn't exist)
|
|
244
|
+
const config = await manager.load()
|
|
245
|
+
// → DiscordBotConfig { current, bots, current_server, servers }
|
|
246
|
+
|
|
247
|
+
// Save full config to disk
|
|
248
|
+
await manager.save(config)
|
|
249
|
+
|
|
250
|
+
// Get the credentials for the current bot (or a specific bot ID)
|
|
251
|
+
const creds = await manager.getCredentials()
|
|
252
|
+
const specific = await manager.getCredentials('deploy')
|
|
253
|
+
// → DiscordBotCredentials | null
|
|
254
|
+
|
|
255
|
+
// Store credentials for a bot (also marks it as current)
|
|
256
|
+
await manager.setCredentials({
|
|
257
|
+
token: 'YOUR_BOT_TOKEN',
|
|
258
|
+
bot_id: 'deploy',
|
|
259
|
+
bot_name: 'Deploy Bot',
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
// Switch the active bot
|
|
263
|
+
await manager.setCurrent('alerts')
|
|
264
|
+
|
|
265
|
+
// List all stored bots with current marker
|
|
266
|
+
const bots = await manager.listAll()
|
|
267
|
+
// → Array<DiscordBotCredentials & { is_current: boolean }>
|
|
268
|
+
|
|
269
|
+
// Remove a stored bot
|
|
270
|
+
await manager.removeBot('alerts')
|
|
271
|
+
|
|
272
|
+
// Clear all stored credentials
|
|
273
|
+
await manager.clearCredentials()
|
|
274
|
+
|
|
275
|
+
// Server preference helpers
|
|
276
|
+
const serverId = await manager.getCurrentServer()
|
|
277
|
+
await manager.setCurrentServer('1234567890123456789', 'My Server')
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## Types
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
import type {
|
|
284
|
+
DiscordBotConfig,
|
|
285
|
+
DiscordBotCredentials,
|
|
286
|
+
DiscordBotEntry,
|
|
287
|
+
DiscordBotListenerEventMap,
|
|
288
|
+
DiscordChannel,
|
|
289
|
+
DiscordFile,
|
|
290
|
+
DiscordGatewayChannelEvent,
|
|
291
|
+
DiscordGatewayEvent,
|
|
292
|
+
DiscordGatewayGenericEvent,
|
|
293
|
+
DiscordGatewayGuildEvent,
|
|
294
|
+
DiscordGatewayInteractionEvent,
|
|
295
|
+
DiscordGatewayMemberEvent,
|
|
296
|
+
DiscordGatewayMessageCreateEvent,
|
|
297
|
+
DiscordGatewayMessageDeleteEvent,
|
|
298
|
+
DiscordGatewayMessageUpdateEvent,
|
|
299
|
+
DiscordGatewayPresenceEvent,
|
|
300
|
+
DiscordGatewayReactionEvent,
|
|
301
|
+
DiscordGatewayTypingEvent,
|
|
302
|
+
DiscordGuild,
|
|
303
|
+
DiscordMessage,
|
|
304
|
+
DiscordReaction,
|
|
305
|
+
DiscordUser,
|
|
306
|
+
} from 'agent-messenger/discordbot'
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Zod Schemas
|
|
310
|
+
|
|
311
|
+
Runtime-validated schemas for parsing API responses:
|
|
312
|
+
|
|
313
|
+
```typescript
|
|
314
|
+
import {
|
|
315
|
+
DiscordBotConfigSchema,
|
|
316
|
+
DiscordBotCredentialsSchema,
|
|
317
|
+
DiscordBotEntrySchema,
|
|
318
|
+
DiscordChannelSchema,
|
|
319
|
+
DiscordFileSchema,
|
|
320
|
+
DiscordGuildSchema,
|
|
321
|
+
DiscordMessageSchema,
|
|
322
|
+
DiscordReactionSchema,
|
|
323
|
+
DiscordUserSchema,
|
|
324
|
+
} from 'agent-messenger/discordbot'
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Constants
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
import { DiscordGatewayOpcode, DiscordIntent } from 'agent-messenger/discordbot'
|
|
331
|
+
|
|
332
|
+
DiscordGatewayOpcode.Identify // 2
|
|
333
|
+
DiscordGatewayOpcode.Hello // 10
|
|
334
|
+
|
|
335
|
+
DiscordIntent.Guilds // 1
|
|
336
|
+
DiscordIntent.GuildMessages // 1 << 9
|
|
337
|
+
DiscordIntent.MessageContent // 1 << 15 (privileged)
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
## DiscordBotError
|
|
341
|
+
|
|
342
|
+
All client methods throw `DiscordBotError` on failure. The error includes a `code` field describing the failure category — useful for retry logic and structured error reporting.
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
import { DiscordBotClient, DiscordBotError } from 'agent-messenger/discordbot'
|
|
346
|
+
|
|
347
|
+
const client = await new DiscordBotClient().login({ token: 'YOUR_BOT_TOKEN' })
|
|
348
|
+
|
|
349
|
+
try {
|
|
350
|
+
await client.sendMessage('1234567890123456789', 'Hello!')
|
|
351
|
+
} catch (err) {
|
|
352
|
+
if (err instanceof DiscordBotError) {
|
|
353
|
+
console.error(`[${err.code}] ${err.message}`)
|
|
354
|
+
|
|
355
|
+
if (err.code === 'rate_limited') {
|
|
356
|
+
// Discord returned 429 — back off and retry
|
|
357
|
+
} else if (err.code === 'missing_token' || err.code === 'no_credentials') {
|
|
358
|
+
// Token is missing — re-run auth set
|
|
359
|
+
}
|
|
360
|
+
} else {
|
|
361
|
+
throw err
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
Error codes thrown by the client:
|
|
367
|
+
|
|
368
|
+
- `missing_token` — `login()` called with an empty token
|
|
369
|
+
- `no_credentials` — `login()` called without args and no stored bot token was found
|
|
370
|
+
- `not_authenticated` — Method called before `login()` resolved
|
|
371
|
+
- `rate_limited` — Discord 429 response; the client retries automatically with `Retry-After`, then surfaces this if retries are exhausted
|
|
372
|
+
- `network_error` — Fetch failed (DNS, connection refused, timeout)
|
|
373
|
+
- `channel_not_found` — `resolveChannel()` could not find the named channel in the current guild
|
|
374
|
+
- `no_attachments` — File upload returned 200 but the response had no attachments
|
|
375
|
+
- `http_<status>` — Discord returned an unexpected status (e.g., `http_500`) without a structured `code` in the error body
|
|
376
|
+
- Discord API error codes (numeric, as strings) — When Discord's response body includes a `code` field (e.g., `"50001"` for "Missing Access"), it is propagated as-is. See the [Discord JSON Error Codes reference](https://discord.com/developers/docs/topics/opcodes-and-status-codes#json-json-error-codes).
|
|
377
|
+
|
|
378
|
+
## Examples
|
|
379
|
+
|
|
380
|
+
### Auto-Reply Bot
|
|
381
|
+
|
|
382
|
+
Listen for messages mentioning the bot and reply with a help message.
|
|
383
|
+
|
|
384
|
+
```typescript
|
|
385
|
+
import { DiscordBotClient, DiscordBotListener, DiscordIntent } from 'agent-messenger/discordbot'
|
|
386
|
+
|
|
387
|
+
const client = await new DiscordBotClient().login({ token })
|
|
388
|
+
const me = await client.testAuth()
|
|
389
|
+
|
|
390
|
+
const listener = new DiscordBotListener(client, {
|
|
391
|
+
intents:
|
|
392
|
+
DiscordIntent.Guilds | DiscordIntent.GuildMessages | DiscordIntent.DirectMessages | DiscordIntent.MessageContent,
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
listener.on('message_create', async (event) => {
|
|
396
|
+
if (event.author.bot) return
|
|
397
|
+
|
|
398
|
+
const mentioned = event.content.includes(`<@${me.id}>`)
|
|
399
|
+
if (!mentioned) return
|
|
400
|
+
|
|
401
|
+
await client.sendMessage(event.channel_id, `👋 Hey <@${event.author.id}>! Try \`/help\` for a list of commands.`)
|
|
402
|
+
})
|
|
403
|
+
|
|
404
|
+
await listener.start()
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
### Reaction-Driven Approval Workflow
|
|
408
|
+
|
|
409
|
+
Post a request, then watch for ✅ or ❌ reactions to advance state.
|
|
410
|
+
|
|
411
|
+
```typescript
|
|
412
|
+
import { DiscordBotClient, DiscordBotListener } from 'agent-messenger/discordbot'
|
|
413
|
+
|
|
414
|
+
const client = await new DiscordBotClient().login({ token })
|
|
415
|
+
const listener = new DiscordBotListener(client)
|
|
416
|
+
|
|
417
|
+
const post = await client.sendMessage(channelId, '🚀 Deploy v2.1.0 to production?')
|
|
418
|
+
await client.addReaction(channelId, post.id, '✅')
|
|
419
|
+
await client.addReaction(channelId, post.id, '❌')
|
|
420
|
+
|
|
421
|
+
listener.on('message_reaction_add', async (event) => {
|
|
422
|
+
if (event.message_id !== post.id) return
|
|
423
|
+
if (event.user_id === me.id) return
|
|
424
|
+
|
|
425
|
+
if (event.emoji.name === '✅') {
|
|
426
|
+
await client.editMessage(channelId, post.id, '🚀 Deploy v2.1.0 — **approved**')
|
|
427
|
+
} else if (event.emoji.name === '❌') {
|
|
428
|
+
await client.editMessage(channelId, post.id, '🚀 Deploy v2.1.0 — **rejected**')
|
|
429
|
+
}
|
|
430
|
+
})
|
|
431
|
+
|
|
432
|
+
await listener.start()
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
### Slash Command Handler
|
|
436
|
+
|
|
437
|
+
React to slash command interactions in real time. (The bot must register slash commands separately via Discord's REST API.)
|
|
438
|
+
|
|
439
|
+
```typescript
|
|
440
|
+
import { DiscordBotClient, DiscordBotListener } from 'agent-messenger/discordbot'
|
|
441
|
+
|
|
442
|
+
const client = await new DiscordBotClient().login({ token })
|
|
443
|
+
const listener = new DiscordBotListener(client)
|
|
444
|
+
|
|
445
|
+
listener.on('interaction_create', async (event) => {
|
|
446
|
+
const name = (event.data as { name?: string } | undefined)?.name
|
|
447
|
+
if (name !== 'ping') return
|
|
448
|
+
|
|
449
|
+
if (event.channel_id) {
|
|
450
|
+
await client.sendMessage(event.channel_id, '🏓 Pong!')
|
|
451
|
+
}
|
|
452
|
+
})
|
|
453
|
+
|
|
454
|
+
await listener.start()
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
### CI Status Notifier
|
|
458
|
+
|
|
459
|
+
Post a status message at the start and finish of a CI job, with a reaction to indicate state.
|
|
460
|
+
|
|
461
|
+
```typescript
|
|
462
|
+
import { DiscordBotClient } from 'agent-messenger/discordbot'
|
|
463
|
+
|
|
464
|
+
const client = await new DiscordBotClient().login({ token })
|
|
465
|
+
|
|
466
|
+
const start = await client.sendMessage(channelId, `🛠️ Build #${runId} started`)
|
|
467
|
+
await client.addReaction(channelId, start.id, '⏳')
|
|
468
|
+
|
|
469
|
+
try {
|
|
470
|
+
await runBuild()
|
|
471
|
+
await client.removeReaction(channelId, start.id, '⏳')
|
|
472
|
+
await client.addReaction(channelId, start.id, '✅')
|
|
473
|
+
await client.sendMessage(channelId, `✅ Build #${runId} succeeded`)
|
|
474
|
+
} catch (err) {
|
|
475
|
+
await client.removeReaction(channelId, start.id, '⏳')
|
|
476
|
+
await client.addReaction(channelId, start.id, '❌')
|
|
477
|
+
await client.sendMessage(channelId, `❌ Build #${runId} failed: ${(err as Error).message}`)
|
|
478
|
+
throw err
|
|
479
|
+
}
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
### Multi-Bot Configuration
|
|
483
|
+
|
|
484
|
+
Use `DiscordBotCredentialManager` to switch between multiple bots stored in the same config (e.g., separate deploy and alerts bots).
|
|
485
|
+
|
|
486
|
+
```typescript
|
|
487
|
+
import { DiscordBotClient, DiscordBotCredentialManager } from 'agent-messenger/discordbot'
|
|
488
|
+
|
|
489
|
+
const manager = new DiscordBotCredentialManager()
|
|
490
|
+
|
|
491
|
+
// Store credentials for two bots
|
|
492
|
+
await manager.setCredentials({ token: 'TOKEN_A', bot_id: 'deploy', bot_name: 'Deploy Bot' })
|
|
493
|
+
await manager.setCredentials({ token: 'TOKEN_B', bot_id: 'alerts', bot_name: 'Alerts Bot' })
|
|
494
|
+
|
|
495
|
+
// Switch to the alerts bot and use it
|
|
496
|
+
await manager.setCurrent('alerts')
|
|
497
|
+
const creds = await manager.getCredentials()
|
|
498
|
+
const client = await new DiscordBotClient().login({ token: creds!.token })
|
|
499
|
+
|
|
500
|
+
await client.sendMessage(channelId, '🚨 Error rate above threshold')
|
|
501
|
+
```
|