agent-messenger 2.3.0 → 2.5.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/README.md +16 -16
- package/.claude-plugin/marketplace.json +29 -29
- package/.claude-plugin/plugin.json +5 -5
- package/.github/workflows/release.yml +0 -12
- package/CONTRIBUTING.md +1 -1
- package/README.md +11 -8
- package/bun.lock +70 -110
- package/bunfig.toml +3 -0
- package/dist/package.json +11 -3
- package/dist/src/platforms/channeltalk/cli.d.ts.map +1 -1
- package/dist/src/platforms/channeltalk/cli.js +2 -1
- package/dist/src/platforms/channeltalk/cli.js.map +1 -1
- package/dist/src/platforms/channeltalk/commands/index.d.ts +1 -0
- package/dist/src/platforms/channeltalk/commands/index.d.ts.map +1 -1
- package/dist/src/platforms/channeltalk/commands/index.js +1 -0
- package/dist/src/platforms/channeltalk/commands/index.js.map +1 -1
- package/dist/src/platforms/channeltalk/commands/whoami.d.ts +22 -0
- package/dist/src/platforms/channeltalk/commands/whoami.d.ts.map +1 -0
- package/dist/src/platforms/channeltalk/commands/whoami.js +40 -0
- package/dist/src/platforms/channeltalk/commands/whoami.js.map +1 -0
- package/dist/src/platforms/channeltalkbot/cli.d.ts.map +1 -1
- package/dist/src/platforms/channeltalkbot/cli.js +2 -1
- package/dist/src/platforms/channeltalkbot/cli.js.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/index.d.ts +1 -0
- package/dist/src/platforms/channeltalkbot/commands/index.d.ts.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/index.js +1 -0
- package/dist/src/platforms/channeltalkbot/commands/index.js.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/whoami.d.ts +13 -0
- package/dist/src/platforms/channeltalkbot/commands/whoami.d.ts.map +1 -0
- package/dist/src/platforms/channeltalkbot/commands/whoami.js +31 -0
- package/dist/src/platforms/channeltalkbot/commands/whoami.js.map +1 -0
- package/dist/src/platforms/discord/cli.d.ts.map +1 -1
- package/dist/src/platforms/discord/cli.js +2 -1
- package/dist/src/platforms/discord/cli.js.map +1 -1
- package/dist/src/platforms/discord/commands/index.d.ts +1 -0
- package/dist/src/platforms/discord/commands/index.d.ts.map +1 -1
- package/dist/src/platforms/discord/commands/index.js +1 -0
- package/dist/src/platforms/discord/commands/index.js.map +1 -1
- package/dist/src/platforms/discord/commands/whoami.d.ts +6 -0
- package/dist/src/platforms/discord/commands/whoami.d.ts.map +1 -0
- package/dist/src/platforms/discord/commands/whoami.js +33 -0
- package/dist/src/platforms/discord/commands/whoami.js.map +1 -0
- package/dist/src/platforms/discordbot/cli.d.ts.map +1 -1
- package/dist/src/platforms/discordbot/cli.js +2 -1
- package/dist/src/platforms/discordbot/cli.js.map +1 -1
- package/dist/src/platforms/discordbot/client.js +2 -2
- package/dist/src/platforms/discordbot/client.js.map +1 -1
- package/dist/src/platforms/discordbot/commands/index.d.ts +1 -0
- package/dist/src/platforms/discordbot/commands/index.d.ts.map +1 -1
- package/dist/src/platforms/discordbot/commands/index.js +1 -0
- package/dist/src/platforms/discordbot/commands/index.js.map +1 -1
- package/dist/src/platforms/discordbot/commands/whoami.d.ts +14 -0
- package/dist/src/platforms/discordbot/commands/whoami.d.ts.map +1 -0
- package/dist/src/platforms/discordbot/commands/whoami.js +32 -0
- package/dist/src/platforms/discordbot/commands/whoami.js.map +1 -0
- package/dist/src/platforms/instagram/cli.d.ts.map +1 -1
- package/dist/src/platforms/instagram/cli.js +2 -1
- package/dist/src/platforms/instagram/cli.js.map +1 -1
- package/dist/src/platforms/instagram/client.d.ts +6 -0
- package/dist/src/platforms/instagram/client.d.ts.map +1 -1
- package/dist/src/platforms/instagram/client.js +12 -0
- package/dist/src/platforms/instagram/client.js.map +1 -1
- package/dist/src/platforms/instagram/commands/index.d.ts +1 -0
- package/dist/src/platforms/instagram/commands/index.d.ts.map +1 -1
- package/dist/src/platforms/instagram/commands/index.js +1 -0
- package/dist/src/platforms/instagram/commands/index.js.map +1 -1
- package/dist/src/platforms/instagram/commands/whoami.d.ts +7 -0
- package/dist/src/platforms/instagram/commands/whoami.d.ts.map +1 -0
- package/dist/src/platforms/instagram/commands/whoami.js +19 -0
- package/dist/src/platforms/instagram/commands/whoami.js.map +1 -0
- package/dist/src/platforms/kakaotalk/cli.d.ts.map +1 -1
- package/dist/src/platforms/kakaotalk/cli.js +2 -1
- package/dist/src/platforms/kakaotalk/cli.js.map +1 -1
- package/dist/src/platforms/kakaotalk/client.d.ts +2 -1
- package/dist/src/platforms/kakaotalk/client.d.ts.map +1 -1
- package/dist/src/platforms/kakaotalk/client.js +225 -23
- package/dist/src/platforms/kakaotalk/client.js.map +1 -1
- package/dist/src/platforms/kakaotalk/commands/index.d.ts +1 -0
- package/dist/src/platforms/kakaotalk/commands/index.d.ts.map +1 -1
- package/dist/src/platforms/kakaotalk/commands/index.js +1 -0
- package/dist/src/platforms/kakaotalk/commands/index.js.map +1 -1
- package/dist/src/platforms/kakaotalk/commands/whoami.d.ts +3 -0
- package/dist/src/platforms/kakaotalk/commands/whoami.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/commands/whoami.js +19 -0
- package/dist/src/platforms/kakaotalk/commands/whoami.js.map +1 -0
- package/dist/src/platforms/kakaotalk/index.d.ts +2 -2
- package/dist/src/platforms/kakaotalk/index.d.ts.map +1 -1
- package/dist/src/platforms/kakaotalk/index.js +1 -1
- package/dist/src/platforms/kakaotalk/index.js.map +1 -1
- package/dist/src/platforms/kakaotalk/protocol/session.d.ts +4 -2
- package/dist/src/platforms/kakaotalk/protocol/session.d.ts.map +1 -1
- package/dist/src/platforms/kakaotalk/protocol/session.js +27 -7
- package/dist/src/platforms/kakaotalk/protocol/session.js.map +1 -1
- package/dist/src/platforms/kakaotalk/protocol/types.d.ts +17 -0
- package/dist/src/platforms/kakaotalk/protocol/types.d.ts.map +1 -1
- package/dist/src/platforms/kakaotalk/protocol/types.js.map +1 -1
- package/dist/src/platforms/kakaotalk/types.d.ts +28 -0
- package/dist/src/platforms/kakaotalk/types.d.ts.map +1 -1
- package/dist/src/platforms/kakaotalk/types.js +14 -0
- package/dist/src/platforms/kakaotalk/types.js.map +1 -1
- package/dist/src/platforms/line/cli.js +2 -2
- package/dist/src/platforms/line/cli.js.map +1 -1
- package/dist/src/platforms/line/client.d.ts.map +1 -1
- package/dist/src/platforms/line/client.js +9 -36
- package/dist/src/platforms/line/client.js.map +1 -1
- package/dist/src/platforms/line/commands/auth.d.ts.map +1 -1
- package/dist/src/platforms/line/commands/auth.js +9 -47
- package/dist/src/platforms/line/commands/auth.js.map +1 -1
- package/dist/src/platforms/line/commands/index.d.ts +1 -1
- package/dist/src/platforms/line/commands/index.d.ts.map +1 -1
- package/dist/src/platforms/line/commands/index.js +1 -1
- package/dist/src/platforms/line/commands/index.js.map +1 -1
- package/dist/src/platforms/line/commands/whoami.d.ts +3 -0
- package/dist/src/platforms/line/commands/whoami.d.ts.map +1 -0
- package/dist/src/platforms/line/commands/{profile.js → whoami.js} +5 -5
- package/dist/src/platforms/line/commands/whoami.js.map +1 -0
- package/dist/src/platforms/slack/cli.d.ts.map +1 -1
- package/dist/src/platforms/slack/cli.js +2 -1
- package/dist/src/platforms/slack/cli.js.map +1 -1
- package/dist/src/platforms/slack/commands/index.d.ts +1 -0
- package/dist/src/platforms/slack/commands/index.d.ts.map +1 -1
- package/dist/src/platforms/slack/commands/index.js +1 -0
- package/dist/src/platforms/slack/commands/index.js.map +1 -1
- package/dist/src/platforms/slack/commands/whoami.d.ts +6 -0
- package/dist/src/platforms/slack/commands/whoami.d.ts.map +1 -0
- package/dist/src/platforms/slack/commands/whoami.js +39 -0
- package/dist/src/platforms/slack/commands/whoami.js.map +1 -0
- package/dist/src/platforms/slackbot/cli.d.ts.map +1 -1
- package/dist/src/platforms/slackbot/cli.js +2 -1
- package/dist/src/platforms/slackbot/cli.js.map +1 -1
- 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/whoami.d.ts +14 -0
- package/dist/src/platforms/slackbot/commands/whoami.d.ts.map +1 -0
- package/dist/src/platforms/slackbot/commands/whoami.js +32 -0
- package/dist/src/platforms/slackbot/commands/whoami.js.map +1 -0
- package/dist/src/platforms/teams/cli.d.ts.map +1 -1
- package/dist/src/platforms/teams/cli.js +2 -1
- package/dist/src/platforms/teams/cli.js.map +1 -1
- package/dist/src/platforms/teams/commands/index.d.ts +1 -0
- package/dist/src/platforms/teams/commands/index.d.ts.map +1 -1
- package/dist/src/platforms/teams/commands/index.js +1 -0
- package/dist/src/platforms/teams/commands/index.js.map +1 -1
- package/dist/src/platforms/teams/commands/reaction.d.ts.map +1 -1
- package/dist/src/platforms/teams/commands/reaction.js +2 -0
- package/dist/src/platforms/teams/commands/reaction.js.map +1 -1
- package/dist/src/platforms/teams/commands/whoami.d.ts +6 -0
- package/dist/src/platforms/teams/commands/whoami.d.ts.map +1 -0
- package/dist/src/platforms/teams/commands/whoami.js +30 -0
- package/dist/src/platforms/teams/commands/whoami.js.map +1 -0
- package/dist/src/platforms/telegram/cli.d.ts.map +1 -1
- package/dist/src/platforms/telegram/cli.js +2 -1
- package/dist/src/platforms/telegram/cli.js.map +1 -1
- package/dist/src/platforms/telegram/commands/index.d.ts +1 -0
- package/dist/src/platforms/telegram/commands/index.d.ts.map +1 -1
- package/dist/src/platforms/telegram/commands/index.js +1 -0
- package/dist/src/platforms/telegram/commands/index.js.map +1 -1
- package/dist/src/platforms/telegram/commands/whoami.d.ts +7 -0
- package/dist/src/platforms/telegram/commands/whoami.d.ts.map +1 -0
- package/dist/src/platforms/telegram/commands/whoami.js +27 -0
- package/dist/src/platforms/telegram/commands/whoami.js.map +1 -0
- package/dist/src/platforms/webex/cli.d.ts.map +1 -1
- package/dist/src/platforms/webex/cli.js +2 -1
- package/dist/src/platforms/webex/cli.js.map +1 -1
- package/dist/src/platforms/webex/commands/index.d.ts +1 -0
- package/dist/src/platforms/webex/commands/index.d.ts.map +1 -1
- package/dist/src/platforms/webex/commands/index.js +1 -0
- package/dist/src/platforms/webex/commands/index.js.map +1 -1
- package/dist/src/platforms/webex/commands/message.js +1 -1
- package/dist/src/platforms/webex/commands/message.js.map +1 -1
- package/dist/src/platforms/webex/commands/whoami.d.ts +6 -0
- package/dist/src/platforms/webex/commands/whoami.d.ts.map +1 -0
- package/dist/src/platforms/webex/commands/whoami.js +30 -0
- package/dist/src/platforms/webex/commands/whoami.js.map +1 -0
- package/dist/src/platforms/wechatbot/cli.d.ts +5 -0
- package/dist/src/platforms/wechatbot/cli.d.ts.map +1 -0
- package/dist/src/platforms/wechatbot/cli.js +19 -0
- package/dist/src/platforms/wechatbot/cli.js.map +1 -0
- package/dist/src/platforms/wechatbot/client.d.ts +36 -0
- package/dist/src/platforms/wechatbot/client.d.ts.map +1 -0
- package/dist/src/platforms/wechatbot/client.js +208 -0
- package/dist/src/platforms/wechatbot/client.js.map +1 -0
- package/dist/src/platforms/wechatbot/commands/auth.d.ts +28 -0
- package/dist/src/platforms/wechatbot/commands/auth.d.ts.map +1 -0
- package/dist/src/platforms/wechatbot/commands/auth.js +164 -0
- package/dist/src/platforms/wechatbot/commands/auth.js.map +1 -0
- package/dist/src/platforms/wechatbot/commands/index.d.ts +6 -0
- package/dist/src/platforms/wechatbot/commands/index.d.ts.map +1 -0
- package/dist/src/platforms/wechatbot/commands/index.js +6 -0
- package/dist/src/platforms/wechatbot/commands/index.js.map +1 -0
- package/dist/src/platforms/wechatbot/commands/message.d.ts +18 -0
- package/dist/src/platforms/wechatbot/commands/message.d.ts.map +1 -0
- package/dist/src/platforms/wechatbot/commands/message.js +80 -0
- package/dist/src/platforms/wechatbot/commands/message.js.map +1 -0
- package/dist/src/platforms/wechatbot/commands/shared.d.ts +9 -0
- package/dist/src/platforms/wechatbot/commands/shared.d.ts.map +1 -0
- package/dist/src/platforms/wechatbot/commands/shared.js +13 -0
- package/dist/src/platforms/wechatbot/commands/shared.js.map +1 -0
- package/dist/src/platforms/wechatbot/commands/template.d.ts +19 -0
- package/dist/src/platforms/wechatbot/commands/template.d.ts.map +1 -0
- package/dist/src/platforms/wechatbot/commands/template.js +76 -0
- package/dist/src/platforms/wechatbot/commands/template.js.map +1 -0
- package/dist/src/platforms/wechatbot/commands/user.d.ts +20 -0
- package/dist/src/platforms/wechatbot/commands/user.d.ts.map +1 -0
- package/dist/src/platforms/wechatbot/commands/user.js +53 -0
- package/dist/src/platforms/wechatbot/commands/user.js.map +1 -0
- package/dist/src/platforms/wechatbot/commands/whoami.d.ts +12 -0
- package/dist/src/platforms/wechatbot/commands/whoami.d.ts.map +1 -0
- package/dist/src/platforms/wechatbot/commands/whoami.js +33 -0
- package/dist/src/platforms/wechatbot/commands/whoami.js.map +1 -0
- package/dist/src/platforms/wechatbot/credential-manager.d.ts +17 -0
- package/dist/src/platforms/wechatbot/credential-manager.d.ts.map +1 -0
- package/dist/src/platforms/wechatbot/credential-manager.js +121 -0
- package/dist/src/platforms/wechatbot/credential-manager.js.map +1 -0
- package/dist/src/platforms/wechatbot/index.d.ts +5 -0
- package/dist/src/platforms/wechatbot/index.d.ts.map +1 -0
- package/dist/src/platforms/wechatbot/index.js +4 -0
- package/dist/src/platforms/wechatbot/index.js.map +1 -0
- package/dist/src/platforms/wechatbot/types.d.ts +94 -0
- package/dist/src/platforms/wechatbot/types.d.ts.map +1 -0
- package/dist/src/platforms/wechatbot/types.js +54 -0
- package/dist/src/platforms/wechatbot/types.js.map +1 -0
- package/dist/src/platforms/whatsapp/cli.d.ts.map +1 -1
- package/dist/src/platforms/whatsapp/cli.js +2 -1
- package/dist/src/platforms/whatsapp/cli.js.map +1 -1
- package/dist/src/platforms/whatsapp/client.d.ts +9 -0
- package/dist/src/platforms/whatsapp/client.d.ts.map +1 -1
- package/dist/src/platforms/whatsapp/client.js +143 -21
- package/dist/src/platforms/whatsapp/client.js.map +1 -1
- package/dist/src/platforms/whatsapp/commands/auth.d.ts.map +1 -1
- package/dist/src/platforms/whatsapp/commands/auth.js +133 -60
- package/dist/src/platforms/whatsapp/commands/auth.js.map +1 -1
- package/dist/src/platforms/whatsapp/commands/index.d.ts +1 -0
- package/dist/src/platforms/whatsapp/commands/index.d.ts.map +1 -1
- package/dist/src/platforms/whatsapp/commands/index.js +1 -0
- package/dist/src/platforms/whatsapp/commands/index.js.map +1 -1
- package/dist/src/platforms/whatsapp/commands/shared.js +2 -2
- package/dist/src/platforms/whatsapp/commands/shared.js.map +1 -1
- package/dist/src/platforms/whatsapp/commands/whoami.d.ts +7 -0
- package/dist/src/platforms/whatsapp/commands/whoami.d.ts.map +1 -0
- package/dist/src/platforms/whatsapp/commands/whoami.js +19 -0
- package/dist/src/platforms/whatsapp/commands/whoami.js.map +1 -0
- package/dist/src/platforms/whatsapp/credential-manager.d.ts.map +1 -1
- package/dist/src/platforms/whatsapp/credential-manager.js +14 -8
- package/dist/src/platforms/whatsapp/credential-manager.js.map +1 -1
- package/dist/src/platforms/whatsapp/ensure-auth.js +2 -2
- package/dist/src/platforms/whatsapp/ensure-auth.js.map +1 -1
- package/dist/src/platforms/whatsappbot/cli.d.ts.map +1 -1
- package/dist/src/platforms/whatsappbot/cli.js +2 -1
- package/dist/src/platforms/whatsappbot/cli.js.map +1 -1
- package/dist/src/platforms/whatsappbot/commands/index.d.ts +1 -0
- package/dist/src/platforms/whatsappbot/commands/index.d.ts.map +1 -1
- package/dist/src/platforms/whatsappbot/commands/index.js +1 -0
- package/dist/src/platforms/whatsappbot/commands/index.js.map +1 -1
- package/dist/src/platforms/whatsappbot/commands/whoami.d.ts +17 -0
- package/dist/src/platforms/whatsappbot/commands/whoami.d.ts.map +1 -0
- package/dist/src/platforms/whatsappbot/commands/whoami.js +39 -0
- package/dist/src/platforms/whatsappbot/commands/whoami.js.map +1 -0
- package/dist/src/shared/utils/qr.d.ts +15 -0
- package/dist/src/shared/utils/qr.d.ts.map +1 -0
- package/dist/src/shared/utils/qr.js +74 -0
- package/dist/src/shared/utils/qr.js.map +1 -0
- package/dist/src/tui/adapters/whatsapp-adapter.d.ts.map +1 -1
- package/dist/src/tui/adapters/whatsapp-adapter.js +20 -15
- package/dist/src/tui/adapters/whatsapp-adapter.js.map +1 -1
- package/docs/content/docs/agent-skills.mdx +4 -4
- package/docs/content/docs/cli/channeltalk.mdx +12 -1
- package/docs/content/docs/cli/channeltalkbot.mdx +10 -1
- package/docs/content/docs/cli/discord.mdx +11 -1
- package/docs/content/docs/cli/discordbot.mdx +10 -1
- package/docs/content/docs/cli/instagram.mdx +12 -1
- package/docs/content/docs/cli/kakaotalk.mdx +25 -1
- package/docs/content/docs/cli/line.mdx +5 -5
- package/docs/content/docs/cli/meta.json +1 -0
- package/docs/content/docs/cli/slack.mdx +11 -1
- package/docs/content/docs/cli/slackbot.mdx +10 -1
- package/docs/content/docs/cli/teams.mdx +11 -1
- package/docs/content/docs/cli/telegram.mdx +11 -0
- package/docs/content/docs/cli/webex.mdx +11 -1
- package/docs/content/docs/cli/wechatbot.mdx +188 -0
- package/docs/content/docs/cli/whatsapp.mdx +37 -8
- package/docs/content/docs/cli/whatsappbot.mdx +10 -1
- package/docs/content/docs/sdk/meta.json +1 -1
- package/docs/content/docs/sdk/wechatbot.mdx +282 -0
- package/docs/content/docs/tui.mdx +1 -1
- package/docs/src/app/page.tsx +5 -5
- package/package.json +11 -3
- package/skills/agent-channeltalk/SKILL.md +12 -1
- package/skills/agent-channeltalkbot/SKILL.md +10 -1
- package/skills/agent-discord/SKILL.md +11 -1
- package/skills/agent-discordbot/SKILL.md +10 -1
- package/skills/agent-instagram/SKILL.md +12 -1
- package/skills/agent-kakaotalk/SKILL.md +30 -1
- package/skills/agent-kakaotalk/references/common-patterns.md +1 -1
- package/skills/agent-line/SKILL.md +11 -15
- package/skills/agent-line/references/authentication.md +13 -4
- package/skills/agent-slack/SKILL.md +11 -1
- package/skills/agent-slackbot/SKILL.md +10 -1
- package/skills/agent-teams/SKILL.md +11 -1
- package/skills/agent-telegram/SKILL.md +6 -1
- package/skills/agent-webex/SKILL.md +11 -1
- package/skills/agent-wechatbot/SKILL.md +394 -0
- package/skills/agent-whatsapp/SKILL.md +63 -15
- package/skills/agent-whatsapp/references/authentication.md +36 -6
- package/skills/agent-whatsappbot/SKILL.md +10 -1
- package/src/platforms/channeltalk/cli.ts +2 -0
- package/src/platforms/channeltalk/commands/index.ts +1 -0
- package/src/platforms/channeltalk/commands/whoami.test.ts +64 -0
- package/src/platforms/channeltalk/commands/whoami.ts +62 -0
- package/src/platforms/channeltalkbot/cli.ts +2 -0
- package/src/platforms/channeltalkbot/commands/index.ts +1 -0
- package/src/platforms/channeltalkbot/commands/whoami.test.ts +104 -0
- package/src/platforms/channeltalkbot/commands/whoami.ts +42 -0
- package/src/platforms/discord/cli.ts +2 -0
- package/src/platforms/discord/commands/index.ts +1 -0
- package/src/platforms/discord/commands/whoami.test.ts +91 -0
- package/src/platforms/discord/commands/whoami.ts +36 -0
- package/src/platforms/discord/credential-manager.test.ts +18 -1
- package/src/platforms/discordbot/cli.ts +2 -0
- package/src/platforms/discordbot/client.ts +2 -2
- package/src/platforms/discordbot/commands/index.ts +1 -0
- package/src/platforms/discordbot/commands/whoami.test.ts +96 -0
- package/src/platforms/discordbot/commands/whoami.ts +44 -0
- package/src/platforms/instagram/cli.ts +2 -1
- package/src/platforms/instagram/client.ts +13 -0
- package/src/platforms/instagram/commands/auth.test.ts +216 -0
- package/src/platforms/instagram/commands/chat.test.ts +123 -0
- package/src/platforms/instagram/commands/index.ts +1 -0
- package/src/platforms/instagram/commands/message.test.ts +174 -0
- package/src/platforms/instagram/commands/whoami.test.ts +60 -0
- package/src/platforms/instagram/commands/whoami.ts +21 -0
- package/src/platforms/kakaotalk/cli.ts +2 -1
- package/src/platforms/kakaotalk/client.test.ts +182 -14
- package/src/platforms/kakaotalk/client.ts +261 -27
- package/src/platforms/kakaotalk/commands/auth.test.ts +299 -0
- package/src/platforms/kakaotalk/commands/chat.test.ts +97 -0
- package/src/platforms/kakaotalk/commands/index.ts +1 -0
- package/src/platforms/kakaotalk/commands/message.test.ts +113 -0
- package/src/platforms/kakaotalk/commands/whoami.test.ts +116 -0
- package/src/platforms/kakaotalk/commands/whoami.ts +21 -0
- package/src/platforms/kakaotalk/index.test.ts +5 -0
- package/src/platforms/kakaotalk/index.ts +2 -0
- package/src/platforms/kakaotalk/protocol/session.ts +29 -7
- package/src/platforms/kakaotalk/protocol/types.ts +9 -0
- package/src/platforms/kakaotalk/types.ts +30 -0
- package/src/platforms/line/cli.ts +2 -2
- package/src/platforms/line/client.ts +14 -39
- package/src/platforms/line/commands/auth.test.ts +141 -0
- package/src/platforms/line/commands/auth.ts +37 -61
- package/src/platforms/line/commands/chat.test.ts +110 -0
- package/src/platforms/line/commands/friend.test.ts +98 -0
- package/src/platforms/line/commands/index.ts +1 -1
- package/src/platforms/line/commands/message.test.ts +119 -0
- package/src/platforms/line/commands/whoami.test.ts +85 -0
- package/src/platforms/line/commands/{profile.ts → whoami.ts} +4 -4
- package/src/platforms/slack/cli.ts +2 -0
- package/src/platforms/slack/commands/index.ts +1 -0
- package/src/platforms/slack/commands/whoami.test.ts +126 -0
- package/src/platforms/slack/commands/whoami.ts +40 -0
- package/src/platforms/slackbot/cli.ts +2 -1
- package/src/platforms/slackbot/commands/channel.test.ts +139 -0
- package/src/platforms/slackbot/commands/index.ts +1 -0
- package/src/platforms/slackbot/commands/message.test.ts +226 -0
- package/src/platforms/slackbot/commands/reaction.test.ts +90 -0
- package/src/platforms/slackbot/commands/user.test.ts +143 -0
- package/src/platforms/slackbot/commands/whoami.test.ts +102 -0
- package/src/platforms/slackbot/commands/whoami.ts +44 -0
- package/src/platforms/teams/cli.ts +2 -0
- package/src/platforms/teams/commands/index.ts +1 -0
- package/src/platforms/teams/commands/reaction.test.ts +45 -61
- package/src/platforms/teams/commands/reaction.ts +2 -0
- package/src/platforms/teams/commands/whoami.test.ts +83 -0
- package/src/platforms/teams/commands/whoami.ts +33 -0
- package/src/platforms/telegram/cli.ts +2 -1
- package/src/platforms/telegram/commands/chat.test.ts +125 -0
- package/src/platforms/telegram/commands/index.ts +1 -0
- package/src/platforms/telegram/commands/message.test.ts +92 -0
- package/src/platforms/telegram/commands/whoami.test.ts +75 -0
- package/src/platforms/telegram/commands/whoami.ts +29 -0
- package/src/platforms/webex/cli.ts +2 -1
- package/src/platforms/webex/commands/auth.test.ts +58 -46
- package/src/platforms/webex/commands/index.ts +1 -0
- package/src/platforms/webex/commands/member.test.ts +60 -57
- package/src/platforms/webex/commands/message.test.ts +74 -121
- package/src/platforms/webex/commands/message.ts +1 -1
- package/src/platforms/webex/commands/snapshot.test.ts +54 -45
- package/src/platforms/webex/commands/space.test.ts +46 -49
- package/src/platforms/webex/commands/whoami.test.ts +113 -0
- package/src/platforms/webex/commands/whoami.ts +31 -0
- package/src/platforms/webex/credential-manager.test.ts +0 -1
- package/src/platforms/wechatbot/cli.ts +25 -0
- package/src/platforms/wechatbot/client.test.ts +497 -0
- package/src/platforms/wechatbot/client.ts +268 -0
- package/src/platforms/wechatbot/commands/auth.test.ts +211 -0
- package/src/platforms/wechatbot/commands/auth.ts +203 -0
- package/src/platforms/wechatbot/commands/index.ts +5 -0
- package/src/platforms/wechatbot/commands/message.test.ts +155 -0
- package/src/platforms/wechatbot/commands/message.ts +104 -0
- package/src/platforms/wechatbot/commands/shared.ts +22 -0
- package/src/platforms/wechatbot/commands/template.test.ts +199 -0
- package/src/platforms/wechatbot/commands/template.ts +102 -0
- package/src/platforms/wechatbot/commands/user.test.ts +165 -0
- package/src/platforms/wechatbot/commands/user.ts +75 -0
- package/src/platforms/wechatbot/commands/whoami.test.ts +109 -0
- package/src/platforms/wechatbot/commands/whoami.ts +43 -0
- package/src/platforms/wechatbot/credential-manager.test.ts +255 -0
- package/src/platforms/wechatbot/credential-manager.ts +148 -0
- package/src/platforms/wechatbot/index.test.ts +49 -0
- package/src/platforms/wechatbot/index.ts +19 -0
- package/src/platforms/wechatbot/types.test.ts +223 -0
- package/src/platforms/wechatbot/types.ts +107 -0
- package/src/platforms/whatsapp/cli.ts +2 -1
- package/src/platforms/whatsapp/client.ts +180 -37
- package/src/platforms/whatsapp/commands/auth.test.ts +311 -0
- package/src/platforms/whatsapp/commands/auth.ts +194 -84
- package/src/platforms/whatsapp/commands/chat.test.ts +198 -0
- package/src/platforms/whatsapp/commands/index.ts +1 -0
- package/src/platforms/whatsapp/commands/message.test.ts +231 -0
- package/src/platforms/whatsapp/commands/shared.ts +2 -2
- package/src/platforms/whatsapp/commands/whoami.test.ts +59 -0
- package/src/platforms/whatsapp/commands/whoami.ts +21 -0
- package/src/platforms/whatsapp/credential-manager.test.ts +20 -0
- package/src/platforms/whatsapp/credential-manager.ts +17 -8
- package/src/platforms/whatsapp/ensure-auth.ts +2 -2
- package/src/platforms/whatsappbot/cli.ts +2 -1
- package/src/platforms/whatsappbot/commands/auth.test.ts +217 -0
- package/src/platforms/whatsappbot/commands/index.ts +1 -0
- package/src/platforms/whatsappbot/commands/message.test.ts +198 -0
- package/src/platforms/whatsappbot/commands/template.test.ts +112 -0
- package/src/platforms/whatsappbot/commands/whoami.test.ts +100 -0
- package/src/platforms/whatsappbot/commands/whoami.ts +57 -0
- package/src/shared/utils/qr.ts +92 -0
- package/src/tui/adapters/whatsapp-adapter.ts +19 -16
- package/dist/src/platforms/line/commands/profile.d.ts +0 -3
- package/dist/src/platforms/line/commands/profile.d.ts.map +0 -1
- package/dist/src/platforms/line/commands/profile.js.map +0 -1
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
import { rm } from 'node:fs/promises'
|
|
2
|
+
|
|
1
3
|
import { Command } from 'commander'
|
|
4
|
+
|
|
2
5
|
import { handleError } from '@/shared/utils/error-handler'
|
|
3
6
|
import { formatOutput } from '@/shared/utils/output'
|
|
7
|
+
import { displayQR } from '@/shared/utils/qr'
|
|
8
|
+
import { info } from '@/shared/utils/stderr'
|
|
9
|
+
|
|
4
10
|
import { WhatsAppClient } from '../client'
|
|
5
11
|
import { WhatsAppCredentialManager } from '../credential-manager'
|
|
6
12
|
import { createAccountId } from '../types'
|
|
7
13
|
|
|
8
14
|
interface LoginOptions {
|
|
9
|
-
phone
|
|
15
|
+
phone?: string
|
|
16
|
+
qr?: boolean
|
|
10
17
|
pretty?: boolean
|
|
11
18
|
}
|
|
12
19
|
|
|
@@ -15,55 +22,145 @@ interface StatusOptions {
|
|
|
15
22
|
pretty?: boolean
|
|
16
23
|
}
|
|
17
24
|
|
|
18
|
-
|
|
25
|
+
function isInteractiveSession(): boolean {
|
|
26
|
+
return Boolean(process.stdin.isTTY && process.stdout.isTTY)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function loginWithPairingCode(options: LoginOptions & { phone: string }): Promise<void> {
|
|
30
|
+
const manager = new WhatsAppCredentialManager()
|
|
31
|
+
const accountId = createAccountId(options.phone)
|
|
32
|
+
const existingPaths = manager.getAccountPaths(accountId)
|
|
33
|
+
await rm(existingPaths.auth_dir, { recursive: true, force: true })
|
|
34
|
+
const paths = await manager.ensureAccountPaths(accountId)
|
|
35
|
+
const client = await new WhatsAppClient().login({ authDir: paths.auth_dir })
|
|
36
|
+
|
|
37
|
+
let code: string
|
|
38
|
+
let waitForAuth: () => Promise<void>
|
|
39
|
+
|
|
19
40
|
try {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
const result = await client.connectForPairing(options.phone)
|
|
30
|
-
code = result.code
|
|
31
|
-
waitForAuth = result.waitForAuth
|
|
32
|
-
} catch (err) {
|
|
33
|
-
await client.close()
|
|
34
|
-
throw err
|
|
35
|
-
}
|
|
41
|
+
const result = await client.connectForPairing(options.phone)
|
|
42
|
+
code = result.code
|
|
43
|
+
waitForAuth = result.waitForAuth
|
|
44
|
+
} catch (err) {
|
|
45
|
+
await client.close()
|
|
46
|
+
throw err
|
|
47
|
+
}
|
|
36
48
|
|
|
37
|
-
|
|
49
|
+
const formatted = code.length === 8 ? `${code.slice(0, 4)}-${code.slice(4)}` : code
|
|
38
50
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
console.log(
|
|
52
|
+
formatOutput(
|
|
53
|
+
{
|
|
54
|
+
pairing_code: formatted,
|
|
55
|
+
message: 'Enter this code in WhatsApp > Linked Devices > Link with phone number',
|
|
56
|
+
},
|
|
57
|
+
options.pretty,
|
|
58
|
+
),
|
|
59
|
+
)
|
|
43
60
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
61
|
+
try {
|
|
62
|
+
await waitForAuth()
|
|
63
|
+
} catch (err) {
|
|
64
|
+
await client.close()
|
|
65
|
+
throw err
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const now = new Date().toISOString()
|
|
69
|
+
await manager.setAccount({
|
|
70
|
+
account_id: accountId,
|
|
71
|
+
phone_number: options.phone,
|
|
72
|
+
created_at: now,
|
|
73
|
+
updated_at: now,
|
|
74
|
+
})
|
|
75
|
+
await manager.setCurrent(accountId)
|
|
76
|
+
await client.close()
|
|
77
|
+
|
|
78
|
+
console.log(
|
|
79
|
+
formatOutput(
|
|
80
|
+
{
|
|
81
|
+
authenticated: true,
|
|
82
|
+
account_id: accountId,
|
|
83
|
+
phone_number: options.phone,
|
|
84
|
+
},
|
|
85
|
+
options.pretty,
|
|
86
|
+
),
|
|
87
|
+
)
|
|
88
|
+
process.exit(0)
|
|
89
|
+
}
|
|
50
90
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
91
|
+
async function loginWithQR(options: LoginOptions): Promise<void> {
|
|
92
|
+
const manager = new WhatsAppCredentialManager()
|
|
93
|
+
const accountId = 'qr-default'
|
|
94
|
+
const existingPaths = manager.getAccountPaths(accountId)
|
|
95
|
+
await rm(existingPaths.auth_dir, { recursive: true, force: true })
|
|
96
|
+
const paths = await manager.ensureAccountPaths(accountId)
|
|
97
|
+
const client = await new WhatsAppClient().login({ authDir: paths.auth_dir })
|
|
98
|
+
const interactive = isInteractiveSession()
|
|
99
|
+
|
|
100
|
+
let waitForAuth: () => Promise<void>
|
|
101
|
+
let browserOpened = false
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
const result = await client.connectForQR(async (qr) => {
|
|
105
|
+
await displayQR(qr, {
|
|
106
|
+
platform: 'WhatsApp',
|
|
107
|
+
brandColor: '#25D366',
|
|
108
|
+
scanInstruction: 'Scan with WhatsApp on your phone',
|
|
109
|
+
interactive,
|
|
110
|
+
openBrowser: interactive && !browserOpened,
|
|
111
|
+
formatOutput,
|
|
112
|
+
pretty: options.pretty,
|
|
113
|
+
})
|
|
114
|
+
browserOpened = true
|
|
57
115
|
})
|
|
58
|
-
|
|
116
|
+
waitForAuth = result.waitForAuth
|
|
117
|
+
} catch (err) {
|
|
59
118
|
await client.close()
|
|
119
|
+
throw err
|
|
120
|
+
}
|
|
60
121
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
122
|
+
if (interactive) {
|
|
123
|
+
info('\nWaiting for QR code scan...')
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
await waitForAuth()
|
|
128
|
+
} catch (err) {
|
|
129
|
+
await client.close()
|
|
130
|
+
throw err
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const now = new Date().toISOString()
|
|
134
|
+
await manager.setAccount({
|
|
135
|
+
account_id: accountId,
|
|
136
|
+
created_at: now,
|
|
137
|
+
updated_at: now,
|
|
138
|
+
})
|
|
139
|
+
await manager.setCurrent(accountId)
|
|
140
|
+
await client.close()
|
|
141
|
+
|
|
142
|
+
console.log(
|
|
143
|
+
formatOutput(
|
|
144
|
+
{
|
|
145
|
+
authenticated: true,
|
|
146
|
+
account_id: accountId,
|
|
147
|
+
},
|
|
148
|
+
options.pretty,
|
|
149
|
+
),
|
|
150
|
+
)
|
|
151
|
+
process.exit(0)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function loginAction(options: LoginOptions): Promise<void> {
|
|
155
|
+
try {
|
|
156
|
+
if (options.qr) {
|
|
157
|
+
await loginWithQR(options)
|
|
158
|
+
} else if (options.phone) {
|
|
159
|
+
await loginWithPairingCode(options as LoginOptions & { phone: string })
|
|
160
|
+
} else {
|
|
161
|
+
console.error('Error: Either --phone or --qr is required')
|
|
162
|
+
process.exit(1)
|
|
163
|
+
}
|
|
67
164
|
} catch (error) {
|
|
68
165
|
handleError(error as Error)
|
|
69
166
|
}
|
|
@@ -75,21 +172,31 @@ async function statusAction(options: StatusOptions): Promise<void> {
|
|
|
75
172
|
const account = await manager.getAccount(options.account)
|
|
76
173
|
|
|
77
174
|
if (!account) {
|
|
78
|
-
console.log(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
175
|
+
console.log(
|
|
176
|
+
formatOutput(
|
|
177
|
+
{
|
|
178
|
+
error: options.account
|
|
179
|
+
? `WhatsApp account "${options.account}" not found.`
|
|
180
|
+
: 'No WhatsApp account configured. Run "auth login --qr" or "auth login --phone <phone-number>" first.',
|
|
181
|
+
},
|
|
182
|
+
options.pretty,
|
|
183
|
+
),
|
|
184
|
+
)
|
|
83
185
|
process.exit(1)
|
|
84
186
|
}
|
|
85
187
|
|
|
86
|
-
console.log(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
188
|
+
console.log(
|
|
189
|
+
formatOutput(
|
|
190
|
+
{
|
|
191
|
+
account_id: account.account_id,
|
|
192
|
+
phone_number: account.phone_number,
|
|
193
|
+
name: account.name,
|
|
194
|
+
created_at: account.created_at,
|
|
195
|
+
updated_at: account.updated_at,
|
|
196
|
+
},
|
|
197
|
+
options.pretty,
|
|
198
|
+
),
|
|
199
|
+
)
|
|
93
200
|
} catch (error) {
|
|
94
201
|
handleError(error as Error)
|
|
95
202
|
}
|
|
@@ -100,17 +207,19 @@ async function listAction(options: { pretty?: boolean }): Promise<void> {
|
|
|
100
207
|
const manager = new WhatsAppCredentialManager()
|
|
101
208
|
const accounts = await manager.listAccounts()
|
|
102
209
|
|
|
103
|
-
console.log(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
210
|
+
console.log(
|
|
211
|
+
formatOutput(
|
|
212
|
+
accounts.map((account) => ({
|
|
213
|
+
account_id: account.account_id,
|
|
214
|
+
phone_number: account.phone_number,
|
|
215
|
+
name: account.name,
|
|
216
|
+
created_at: account.created_at,
|
|
217
|
+
updated_at: account.updated_at,
|
|
218
|
+
is_current: account.is_current,
|
|
219
|
+
})),
|
|
220
|
+
options.pretty,
|
|
221
|
+
),
|
|
222
|
+
)
|
|
114
223
|
} catch (error) {
|
|
115
224
|
handleError(error as Error)
|
|
116
225
|
}
|
|
@@ -138,29 +247,29 @@ async function logoutAction(options: { account?: string; pretty?: boolean }): Pr
|
|
|
138
247
|
const manager = new WhatsAppCredentialManager()
|
|
139
248
|
const account = await manager.getAccount(options.account)
|
|
140
249
|
|
|
141
|
-
if (!account) {
|
|
142
|
-
console.log(formatOutput({
|
|
143
|
-
error: options.account
|
|
144
|
-
? `WhatsApp account "${options.account}" not found.`
|
|
145
|
-
: 'No WhatsApp account configured.',
|
|
146
|
-
}, options.pretty))
|
|
250
|
+
if (!account && !options.account) {
|
|
251
|
+
console.log(formatOutput({ error: 'No WhatsApp account configured.' }, options.pretty))
|
|
147
252
|
process.exit(1)
|
|
148
253
|
}
|
|
149
254
|
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
await
|
|
255
|
+
const accountId = account?.account_id ?? options.account!
|
|
256
|
+
|
|
257
|
+
if (account) {
|
|
258
|
+
const paths = manager.getAccountPaths(account.account_id)
|
|
259
|
+
try {
|
|
260
|
+
const client = await new WhatsAppClient().login({ authDir: paths.auth_dir })
|
|
261
|
+
await client.connect()
|
|
262
|
+
if (client.getSocket()) {
|
|
263
|
+
await client.getSocket()!.logout('Logged out via agent-whatsapp CLI')
|
|
264
|
+
}
|
|
265
|
+
await client.close()
|
|
266
|
+
} catch {
|
|
267
|
+
// Server-side deregister failed — proceed with local cleanup
|
|
156
268
|
}
|
|
157
|
-
await client.close()
|
|
158
|
-
} catch {
|
|
159
|
-
// Server-side deregister failed — proceed with local cleanup
|
|
160
269
|
}
|
|
161
270
|
|
|
162
|
-
await manager.removeAccount(
|
|
163
|
-
console.log(formatOutput({ success: true, account_id:
|
|
271
|
+
await manager.removeAccount(accountId)
|
|
272
|
+
console.log(formatOutput({ success: true, account_id: accountId, logged_out: true }, options.pretty))
|
|
164
273
|
process.exit(0)
|
|
165
274
|
} catch (error) {
|
|
166
275
|
handleError(error as Error)
|
|
@@ -171,8 +280,9 @@ export const authCommand = new Command('auth')
|
|
|
171
280
|
.description('WhatsApp authentication commands')
|
|
172
281
|
.addCommand(
|
|
173
282
|
new Command('login')
|
|
174
|
-
.description('Link as a companion device
|
|
175
|
-
.
|
|
283
|
+
.description('Link as a companion device via pairing code (--phone) or QR code (--qr)')
|
|
284
|
+
.option('--phone <number>', 'Phone number in international format (e.g. +12025551234)')
|
|
285
|
+
.option('--qr', 'Link by scanning a QR code instead of entering a pairing code')
|
|
176
286
|
.option('--pretty', 'Pretty print JSON output')
|
|
177
287
|
.action(loginAction),
|
|
178
288
|
)
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, mock, spyOn, test } from 'bun:test'
|
|
2
|
+
|
|
3
|
+
const originalConsoleLog = console.log
|
|
4
|
+
|
|
5
|
+
mock.module('@/shared/utils/error-handler', () => ({
|
|
6
|
+
handleError: (err: Error) => { throw err },
|
|
7
|
+
}))
|
|
8
|
+
|
|
9
|
+
const mockGetAccount = mock(() =>
|
|
10
|
+
Promise.resolve({
|
|
11
|
+
account_id: 'plus-12025551234',
|
|
12
|
+
phone_number: '+12025551234',
|
|
13
|
+
name: 'Test User',
|
|
14
|
+
created_at: '2024-01-01T00:00:00.000Z',
|
|
15
|
+
updated_at: '2024-01-01T00:00:00.000Z',
|
|
16
|
+
}),
|
|
17
|
+
)
|
|
18
|
+
const mockEnsureAccountPaths = mock(() =>
|
|
19
|
+
Promise.resolve({ account_dir: '/tmp/test', auth_dir: '/tmp/test/auth' }),
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
mock.module('../credential-manager', () => ({
|
|
23
|
+
WhatsAppCredentialManager: class {
|
|
24
|
+
getAccount = mockGetAccount
|
|
25
|
+
ensureAccountPaths = mockEnsureAccountPaths
|
|
26
|
+
},
|
|
27
|
+
}))
|
|
28
|
+
|
|
29
|
+
const mockListChats = mock(() =>
|
|
30
|
+
Promise.resolve([
|
|
31
|
+
{
|
|
32
|
+
id: 'chat-1',
|
|
33
|
+
name: 'Alice',
|
|
34
|
+
lastMessage: 'Hello',
|
|
35
|
+
unreadCount: 2,
|
|
36
|
+
timestamp: 1000,
|
|
37
|
+
},
|
|
38
|
+
]),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
const mockSearchChats = mock(() =>
|
|
42
|
+
Promise.resolve([
|
|
43
|
+
{
|
|
44
|
+
id: 'chat-2',
|
|
45
|
+
name: 'Bob',
|
|
46
|
+
lastMessage: 'Hey',
|
|
47
|
+
unreadCount: 0,
|
|
48
|
+
timestamp: 2000,
|
|
49
|
+
},
|
|
50
|
+
]),
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
const mockConnect = mock(() => Promise.resolve())
|
|
54
|
+
const mockClose = mock(() => Promise.resolve())
|
|
55
|
+
|
|
56
|
+
mock.module('../client', () => ({
|
|
57
|
+
WhatsAppClient: class {
|
|
58
|
+
login = mock(function (this: unknown) { return Promise.resolve(this) })
|
|
59
|
+
connect = mockConnect
|
|
60
|
+
close = mockClose
|
|
61
|
+
listChats = mockListChats
|
|
62
|
+
searchChats = mockSearchChats
|
|
63
|
+
},
|
|
64
|
+
}))
|
|
65
|
+
|
|
66
|
+
import { chatCommand } from './chat'
|
|
67
|
+
|
|
68
|
+
describe('chat commands', () => {
|
|
69
|
+
let consoleLogSpy: ReturnType<typeof mock>
|
|
70
|
+
let processExitSpy: ReturnType<typeof spyOn>
|
|
71
|
+
|
|
72
|
+
beforeEach(() => {
|
|
73
|
+
mockGetAccount.mockReset()
|
|
74
|
+
mockEnsureAccountPaths.mockReset()
|
|
75
|
+
mockListChats.mockReset()
|
|
76
|
+
mockSearchChats.mockReset()
|
|
77
|
+
mockConnect.mockReset()
|
|
78
|
+
mockClose.mockReset()
|
|
79
|
+
|
|
80
|
+
mockGetAccount.mockImplementation(() =>
|
|
81
|
+
Promise.resolve({
|
|
82
|
+
account_id: 'plus-12025551234',
|
|
83
|
+
phone_number: '+12025551234',
|
|
84
|
+
name: 'Test User',
|
|
85
|
+
created_at: '2024-01-01T00:00:00.000Z',
|
|
86
|
+
updated_at: '2024-01-01T00:00:00.000Z',
|
|
87
|
+
}),
|
|
88
|
+
)
|
|
89
|
+
mockEnsureAccountPaths.mockImplementation(() =>
|
|
90
|
+
Promise.resolve({ account_dir: '/tmp/test', auth_dir: '/tmp/test/auth' }),
|
|
91
|
+
)
|
|
92
|
+
mockListChats.mockImplementation(() =>
|
|
93
|
+
Promise.resolve([
|
|
94
|
+
{
|
|
95
|
+
id: 'chat-1',
|
|
96
|
+
name: 'Alice',
|
|
97
|
+
lastMessage: 'Hello',
|
|
98
|
+
unreadCount: 2,
|
|
99
|
+
timestamp: 1000,
|
|
100
|
+
},
|
|
101
|
+
]),
|
|
102
|
+
)
|
|
103
|
+
mockSearchChats.mockImplementation(() =>
|
|
104
|
+
Promise.resolve([
|
|
105
|
+
{
|
|
106
|
+
id: 'chat-2',
|
|
107
|
+
name: 'Bob',
|
|
108
|
+
lastMessage: 'Hey',
|
|
109
|
+
unreadCount: 0,
|
|
110
|
+
timestamp: 2000,
|
|
111
|
+
},
|
|
112
|
+
]),
|
|
113
|
+
)
|
|
114
|
+
mockConnect.mockImplementation(() => Promise.resolve())
|
|
115
|
+
mockClose.mockImplementation(() => Promise.resolve())
|
|
116
|
+
|
|
117
|
+
consoleLogSpy = mock((..._args: unknown[]) => {}); console.log = consoleLogSpy
|
|
118
|
+
processExitSpy = spyOn(process, 'exit').mockImplementation((_code?: number) => {
|
|
119
|
+
throw new Error(`process.exit(${_code})`)
|
|
120
|
+
})
|
|
121
|
+
processExitSpy.mockClear()
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
afterEach(() => {
|
|
125
|
+
console.log = originalConsoleLog
|
|
126
|
+
processExitSpy.mockRestore()
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
describe('list', () => {
|
|
130
|
+
test('lists chats with default limit', async () => {
|
|
131
|
+
await expect(
|
|
132
|
+
chatCommand.parseAsync(['list'], { from: 'user' }),
|
|
133
|
+
).rejects.toThrow('process.exit(0)')
|
|
134
|
+
|
|
135
|
+
expect(mockListChats).toHaveBeenCalledWith(20)
|
|
136
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0])
|
|
137
|
+
expect(output).toHaveLength(1)
|
|
138
|
+
expect(output[0].id).toBe('chat-1')
|
|
139
|
+
expect(output[0].name).toBe('Alice')
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
test('respects --limit option', async () => {
|
|
143
|
+
await expect(
|
|
144
|
+
chatCommand.parseAsync(['list', '--limit', '5'], { from: 'user' }),
|
|
145
|
+
).rejects.toThrow('process.exit(0)')
|
|
146
|
+
|
|
147
|
+
expect(mockListChats).toHaveBeenCalledWith(5)
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
test('passes account option to credential manager', async () => {
|
|
151
|
+
await expect(
|
|
152
|
+
chatCommand.parseAsync(['list', '--account', 'my-account'], { from: 'user' }),
|
|
153
|
+
).rejects.toThrow('process.exit(0)')
|
|
154
|
+
|
|
155
|
+
expect(mockGetAccount).toHaveBeenCalledWith('my-account')
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
test('exits with error when no account configured', async () => {
|
|
159
|
+
mockGetAccount.mockImplementation(() => Promise.resolve(null))
|
|
160
|
+
|
|
161
|
+
await expect(
|
|
162
|
+
chatCommand.parseAsync(['list'], { from: 'user' }),
|
|
163
|
+
).rejects.toThrow('process.exit(1)')
|
|
164
|
+
|
|
165
|
+
expect(processExitSpy).toHaveBeenCalledWith(1)
|
|
166
|
+
})
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
describe('search', () => {
|
|
170
|
+
test('searches chats by query', async () => {
|
|
171
|
+
await expect(
|
|
172
|
+
chatCommand.parseAsync(['search', 'Bob'], { from: 'user' }),
|
|
173
|
+
).rejects.toThrow('process.exit(0)')
|
|
174
|
+
|
|
175
|
+
expect(mockSearchChats).toHaveBeenCalledWith('Bob', 20)
|
|
176
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0])
|
|
177
|
+
expect(output).toHaveLength(1)
|
|
178
|
+
expect(output[0].id).toBe('chat-2')
|
|
179
|
+
expect(output[0].name).toBe('Bob')
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
test('respects --limit option', async () => {
|
|
183
|
+
await expect(
|
|
184
|
+
chatCommand.parseAsync(['search', 'Alice', '--limit', '3'], { from: 'user' }),
|
|
185
|
+
).rejects.toThrow('process.exit(0)')
|
|
186
|
+
|
|
187
|
+
expect(mockSearchChats).toHaveBeenCalledWith('Alice', 3)
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
test('passes account option to credential manager', async () => {
|
|
191
|
+
await expect(
|
|
192
|
+
chatCommand.parseAsync(['search', 'test', '--account', 'my-account'], { from: 'user' }),
|
|
193
|
+
).rejects.toThrow('process.exit(0)')
|
|
194
|
+
|
|
195
|
+
expect(mockGetAccount).toHaveBeenCalledWith('my-account')
|
|
196
|
+
})
|
|
197
|
+
})
|
|
198
|
+
})
|