agent-messenger 1.14.0 → 2.0.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 +94 -13
- package/.claude-plugin/marketplace.json +51 -12
- package/.claude-plugin/plugin.json +14 -3
- package/CONTRIBUTING.md +49 -3
- package/README.md +211 -54
- package/bun.lock +350 -2
- package/cubic.yaml +69 -0
- package/dist/package.json +118 -9
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +27 -6
- package/dist/src/cli.js.map +1 -1
- package/dist/src/platforms/channeltalk/client.d.ts +5 -1
- package/dist/src/platforms/channeltalk/client.d.ts.map +1 -1
- package/dist/src/platforms/channeltalk/client.js +23 -6
- package/dist/src/platforms/channeltalk/client.js.map +1 -1
- package/dist/src/platforms/channeltalk/commands/auth.d.ts +1 -1
- package/dist/src/platforms/channeltalk/commands/auth.d.ts.map +1 -1
- package/dist/src/platforms/channeltalk/commands/auth.js +4 -4
- package/dist/src/platforms/channeltalk/commands/auth.js.map +1 -1
- package/dist/src/platforms/channeltalk/commands/shared.js +1 -1
- package/dist/src/platforms/channeltalk/commands/shared.js.map +1 -1
- package/dist/src/platforms/channeltalk/ensure-auth.d.ts +2 -2
- package/dist/src/platforms/channeltalk/ensure-auth.d.ts.map +1 -1
- package/dist/src/platforms/channeltalk/ensure-auth.js +4 -4
- package/dist/src/platforms/channeltalk/ensure-auth.js.map +1 -1
- package/dist/src/platforms/channeltalk/index.d.ts +2 -2
- package/dist/src/platforms/channeltalk/index.d.ts.map +1 -1
- package/dist/src/platforms/channeltalk/index.js +1 -2
- package/dist/src/platforms/channeltalk/index.js.map +1 -1
- package/dist/src/platforms/channeltalk/token-extractor.d.ts +8 -0
- package/dist/src/platforms/channeltalk/token-extractor.d.ts.map +1 -1
- package/dist/src/platforms/channeltalk/token-extractor.js +127 -13
- package/dist/src/platforms/channeltalk/token-extractor.js.map +1 -1
- package/dist/src/platforms/channeltalk/types.d.ts +52 -949
- package/dist/src/platforms/channeltalk/types.d.ts.map +1 -1
- package/dist/src/platforms/channeltalk/types.js +1 -1
- package/dist/src/platforms/channeltalk/types.js.map +1 -1
- package/dist/src/platforms/channeltalkbot/client.d.ts +5 -1
- package/dist/src/platforms/channeltalkbot/client.d.ts.map +1 -1
- package/dist/src/platforms/channeltalkbot/client.js +24 -9
- package/dist/src/platforms/channeltalkbot/client.js.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/auth.js +2 -2
- package/dist/src/platforms/channeltalkbot/commands/auth.js.map +1 -1
- package/dist/src/platforms/channeltalkbot/commands/shared.js +1 -1
- package/dist/src/platforms/channeltalkbot/commands/shared.js.map +1 -1
- package/dist/src/platforms/channeltalkbot/index.d.ts +2 -1
- package/dist/src/platforms/channeltalkbot/index.d.ts.map +1 -1
- package/dist/src/platforms/channeltalkbot/index.js.map +1 -1
- package/dist/src/platforms/channeltalkbot/types.d.ts +24 -186
- package/dist/src/platforms/channeltalkbot/types.d.ts.map +1 -1
- package/dist/src/platforms/discord/client.d.ts +7 -1
- package/dist/src/platforms/discord/client.d.ts.map +1 -1
- package/dist/src/platforms/discord/client.js +27 -6
- package/dist/src/platforms/discord/client.js.map +1 -1
- package/dist/src/platforms/discord/commands/auth.js +2 -2
- package/dist/src/platforms/discord/commands/auth.js.map +1 -1
- package/dist/src/platforms/discord/commands/channel.js +3 -3
- package/dist/src/platforms/discord/commands/channel.js.map +1 -1
- package/dist/src/platforms/discord/commands/dm.js +2 -2
- package/dist/src/platforms/discord/commands/dm.js.map +1 -1
- package/dist/src/platforms/discord/commands/file.js +3 -3
- package/dist/src/platforms/discord/commands/file.js.map +1 -1
- package/dist/src/platforms/discord/commands/friend.js +1 -1
- package/dist/src/platforms/discord/commands/friend.js.map +1 -1
- package/dist/src/platforms/discord/commands/member.js +1 -1
- package/dist/src/platforms/discord/commands/member.js.map +1 -1
- package/dist/src/platforms/discord/commands/mention.js +1 -1
- package/dist/src/platforms/discord/commands/mention.js.map +1 -1
- package/dist/src/platforms/discord/commands/message.js +6 -6
- package/dist/src/platforms/discord/commands/message.js.map +1 -1
- package/dist/src/platforms/discord/commands/note.js +2 -2
- package/dist/src/platforms/discord/commands/note.js.map +1 -1
- package/dist/src/platforms/discord/commands/profile.js +1 -1
- package/dist/src/platforms/discord/commands/profile.js.map +1 -1
- package/dist/src/platforms/discord/commands/reaction.js +3 -3
- package/dist/src/platforms/discord/commands/reaction.js.map +1 -1
- package/dist/src/platforms/discord/commands/server.js +1 -1
- package/dist/src/platforms/discord/commands/server.js.map +1 -1
- package/dist/src/platforms/discord/commands/snapshot.js +1 -1
- package/dist/src/platforms/discord/commands/snapshot.js.map +1 -1
- package/dist/src/platforms/discord/commands/thread.js +2 -2
- package/dist/src/platforms/discord/commands/thread.js.map +1 -1
- package/dist/src/platforms/discord/commands/user.js +3 -3
- package/dist/src/platforms/discord/commands/user.js.map +1 -1
- package/dist/src/platforms/discord/ensure-auth.js +1 -1
- package/dist/src/platforms/discord/ensure-auth.js.map +1 -1
- package/dist/src/platforms/discord/index.d.ts +6 -0
- package/dist/src/platforms/discord/index.d.ts.map +1 -0
- package/dist/src/platforms/discord/index.js +5 -0
- package/dist/src/platforms/discord/index.js.map +1 -0
- package/dist/src/platforms/discord/listener.d.ts +41 -0
- package/dist/src/platforms/discord/listener.d.ts.map +1 -0
- package/dist/src/platforms/discord/listener.js +262 -0
- package/dist/src/platforms/discord/listener.js.map +1 -0
- package/dist/src/platforms/discord/types.d.ts +150 -352
- package/dist/src/platforms/discord/types.d.ts.map +1 -1
- package/dist/src/platforms/discord/types.js +28 -0
- package/dist/src/platforms/discord/types.js.map +1 -1
- package/dist/src/platforms/discordbot/client.d.ts +4 -1
- package/dist/src/platforms/discordbot/client.d.ts.map +1 -1
- package/dist/src/platforms/discordbot/client.js +23 -7
- package/dist/src/platforms/discordbot/client.js.map +1 -1
- package/dist/src/platforms/discordbot/commands/auth.js +2 -2
- package/dist/src/platforms/discordbot/commands/auth.js.map +1 -1
- package/dist/src/platforms/discordbot/commands/shared.js +1 -1
- package/dist/src/platforms/discordbot/commands/shared.js.map +1 -1
- package/dist/src/platforms/discordbot/types.d.ts +15 -203
- package/dist/src/platforms/discordbot/types.d.ts.map +1 -1
- package/dist/src/platforms/instagram/cli.d.ts +5 -0
- package/dist/src/platforms/instagram/cli.d.ts.map +1 -0
- package/dist/src/platforms/instagram/cli.js +30 -0
- package/dist/src/platforms/instagram/cli.js.map +1 -0
- package/dist/src/platforms/instagram/client.d.ts +65 -0
- package/dist/src/platforms/instagram/client.d.ts.map +1 -0
- package/dist/src/platforms/instagram/client.js +524 -0
- package/dist/src/platforms/instagram/client.js.map +1 -0
- package/dist/src/platforms/instagram/commands/auth.d.ts +3 -0
- package/dist/src/platforms/instagram/commands/auth.d.ts.map +1 -0
- package/dist/src/platforms/instagram/commands/auth.js +330 -0
- package/dist/src/platforms/instagram/commands/auth.js.map +1 -0
- package/dist/src/platforms/instagram/commands/chat.d.ts +3 -0
- package/dist/src/platforms/instagram/commands/chat.d.ts.map +1 -0
- package/dist/src/platforms/instagram/commands/chat.js +42 -0
- package/dist/src/platforms/instagram/commands/chat.js.map +1 -0
- package/dist/src/platforms/instagram/commands/index.d.ts +4 -0
- package/dist/src/platforms/instagram/commands/index.d.ts.map +1 -0
- package/dist/src/platforms/instagram/commands/index.js +4 -0
- package/dist/src/platforms/instagram/commands/index.js.map +1 -0
- package/dist/src/platforms/instagram/commands/message.d.ts +3 -0
- package/dist/src/platforms/instagram/commands/message.d.ts.map +1 -0
- package/dist/src/platforms/instagram/commands/message.js +102 -0
- package/dist/src/platforms/instagram/commands/message.js.map +1 -0
- package/dist/src/platforms/instagram/commands/shared.d.ts +8 -0
- package/dist/src/platforms/instagram/commands/shared.d.ts.map +1 -0
- package/dist/src/platforms/instagram/commands/shared.js +31 -0
- package/dist/src/platforms/instagram/commands/shared.js.map +1 -0
- package/dist/src/platforms/instagram/credential-manager.d.ts +20 -0
- package/dist/src/platforms/instagram/credential-manager.d.ts.map +1 -0
- package/dist/src/platforms/instagram/credential-manager.js +104 -0
- package/dist/src/platforms/instagram/credential-manager.js.map +1 -0
- package/dist/src/platforms/instagram/ensure-auth.d.ts +2 -0
- package/dist/src/platforms/instagram/ensure-auth.d.ts.map +1 -0
- package/dist/src/platforms/instagram/ensure-auth.js +21 -0
- package/dist/src/platforms/instagram/ensure-auth.js.map +1 -0
- package/dist/src/platforms/instagram/index.d.ts +5 -0
- package/dist/src/platforms/instagram/index.d.ts.map +1 -0
- package/dist/src/platforms/instagram/index.js +5 -0
- package/dist/src/platforms/instagram/index.js.map +1 -0
- package/dist/src/platforms/instagram/listener.d.ts +32 -0
- package/dist/src/platforms/instagram/listener.d.ts.map +1 -0
- package/dist/src/platforms/instagram/listener.js +87 -0
- package/dist/src/platforms/instagram/listener.js.map +1 -0
- package/dist/src/platforms/instagram/types.d.ts +61 -0
- package/dist/src/platforms/instagram/types.d.ts.map +1 -0
- package/dist/src/platforms/instagram/types.js +89 -0
- package/dist/src/platforms/instagram/types.js.map +1 -0
- package/dist/src/platforms/kakaotalk/auth/kakao-login.d.ts +27 -0
- package/dist/src/platforms/kakaotalk/auth/kakao-login.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/auth/kakao-login.js +213 -0
- package/dist/src/platforms/kakaotalk/auth/kakao-login.js.map +1 -0
- package/dist/src/platforms/kakaotalk/cli.d.ts +5 -0
- package/dist/src/platforms/kakaotalk/cli.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/cli.js +30 -0
- package/dist/src/platforms/kakaotalk/cli.js.map +1 -0
- package/dist/src/platforms/kakaotalk/client.d.ts +40 -0
- package/dist/src/platforms/kakaotalk/client.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/client.js +290 -0
- package/dist/src/platforms/kakaotalk/client.js.map +1 -0
- package/dist/src/platforms/kakaotalk/commands/auth.d.ts +3 -0
- package/dist/src/platforms/kakaotalk/commands/auth.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/commands/auth.js +515 -0
- package/dist/src/platforms/kakaotalk/commands/auth.js.map +1 -0
- package/dist/src/platforms/kakaotalk/commands/chat.d.ts +3 -0
- package/dist/src/platforms/kakaotalk/commands/chat.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/commands/chat.js +23 -0
- package/dist/src/platforms/kakaotalk/commands/chat.js.map +1 -0
- package/dist/src/platforms/kakaotalk/commands/index.d.ts +4 -0
- package/dist/src/platforms/kakaotalk/commands/index.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/commands/index.js +4 -0
- package/dist/src/platforms/kakaotalk/commands/index.js.map +1 -0
- package/dist/src/platforms/kakaotalk/commands/message.d.ts +3 -0
- package/dist/src/platforms/kakaotalk/commands/message.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/commands/message.js +41 -0
- package/dist/src/platforms/kakaotalk/commands/message.js.map +1 -0
- package/dist/src/platforms/kakaotalk/commands/shared.d.ts +7 -0
- package/dist/src/platforms/kakaotalk/commands/shared.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/commands/shared.js +24 -0
- package/dist/src/platforms/kakaotalk/commands/shared.js.map +1 -0
- package/dist/src/platforms/kakaotalk/credential-manager.d.ts +27 -0
- package/dist/src/platforms/kakaotalk/credential-manager.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/credential-manager.js +82 -0
- package/dist/src/platforms/kakaotalk/credential-manager.js.map +1 -0
- package/dist/src/platforms/kakaotalk/ensure-auth.d.ts +3 -0
- package/dist/src/platforms/kakaotalk/ensure-auth.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/ensure-auth.js +11 -0
- package/dist/src/platforms/kakaotalk/ensure-auth.js.map +1 -0
- package/dist/src/platforms/kakaotalk/index.d.ts +7 -0
- package/dist/src/platforms/kakaotalk/index.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/index.js +5 -0
- package/dist/src/platforms/kakaotalk/index.js.map +1 -0
- package/dist/src/platforms/kakaotalk/listener.d.ts +24 -0
- package/dist/src/platforms/kakaotalk/listener.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/listener.js +171 -0
- package/dist/src/platforms/kakaotalk/listener.js.map +1 -0
- package/dist/src/platforms/kakaotalk/protocol/config.d.ts +14 -0
- package/dist/src/platforms/kakaotalk/protocol/config.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/protocol/config.js +23 -0
- package/dist/src/platforms/kakaotalk/protocol/config.js.map +1 -0
- package/dist/src/platforms/kakaotalk/protocol/connection.d.ts +25 -0
- package/dist/src/platforms/kakaotalk/protocol/connection.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/protocol/connection.js +144 -0
- package/dist/src/platforms/kakaotalk/protocol/connection.js.map +1 -0
- package/dist/src/platforms/kakaotalk/protocol/crypto.d.ts +8 -0
- package/dist/src/platforms/kakaotalk/protocol/crypto.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/protocol/crypto.js +51 -0
- package/dist/src/platforms/kakaotalk/protocol/crypto.js.map +1 -0
- package/dist/src/platforms/kakaotalk/protocol/packet.d.ts +7 -0
- package/dist/src/platforms/kakaotalk/protocol/packet.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/protocol/packet.js +38 -0
- package/dist/src/platforms/kakaotalk/protocol/packet.js.map +1 -0
- package/dist/src/platforms/kakaotalk/protocol/session.d.ts +18 -0
- package/dist/src/platforms/kakaotalk/protocol/session.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/protocol/session.js +127 -0
- package/dist/src/platforms/kakaotalk/protocol/session.js.map +1 -0
- package/dist/src/platforms/kakaotalk/protocol/types.d.ts +41 -0
- package/dist/src/platforms/kakaotalk/protocol/types.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/protocol/types.js +8 -0
- package/dist/src/platforms/kakaotalk/protocol/types.js.map +1 -0
- package/dist/src/platforms/kakaotalk/token-extractor.d.ts +17 -0
- package/dist/src/platforms/kakaotalk/token-extractor.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/token-extractor.js +273 -0
- package/dist/src/platforms/kakaotalk/token-extractor.js.map +1 -0
- package/dist/src/platforms/kakaotalk/types.d.ts +198 -0
- package/dist/src/platforms/kakaotalk/types.d.ts.map +1 -0
- package/dist/src/platforms/kakaotalk/types.js +74 -0
- package/dist/src/platforms/kakaotalk/types.js.map +1 -0
- package/dist/src/platforms/line/cli.d.ts +5 -0
- package/dist/src/platforms/line/cli.d.ts.map +1 -0
- package/dist/src/platforms/line/cli.js +32 -0
- package/dist/src/platforms/line/cli.js.map +1 -0
- package/dist/src/platforms/line/client.d.ts +31 -0
- package/dist/src/platforms/line/client.d.ts.map +1 -0
- package/dist/src/platforms/line/client.js +296 -0
- package/dist/src/platforms/line/client.js.map +1 -0
- package/dist/src/platforms/line/commands/auth.d.ts +3 -0
- package/dist/src/platforms/line/commands/auth.d.ts.map +1 -0
- package/dist/src/platforms/line/commands/auth.js +199 -0
- package/dist/src/platforms/line/commands/auth.js.map +1 -0
- package/dist/src/platforms/line/commands/chat.d.ts +3 -0
- package/dist/src/platforms/line/commands/chat.d.ts.map +1 -0
- package/dist/src/platforms/line/commands/chat.js +28 -0
- package/dist/src/platforms/line/commands/chat.js.map +1 -0
- package/dist/src/platforms/line/commands/friend.d.ts +3 -0
- package/dist/src/platforms/line/commands/friend.d.ts.map +1 -0
- package/dist/src/platforms/line/commands/friend.js +25 -0
- package/dist/src/platforms/line/commands/friend.js.map +1 -0
- package/dist/src/platforms/line/commands/index.d.ts +6 -0
- package/dist/src/platforms/line/commands/index.d.ts.map +1 -0
- package/dist/src/platforms/line/commands/index.js +6 -0
- package/dist/src/platforms/line/commands/index.js.map +1 -0
- package/dist/src/platforms/line/commands/message.d.ts +3 -0
- package/dist/src/platforms/line/commands/message.d.ts.map +1 -0
- package/dist/src/platforms/line/commands/message.js +48 -0
- package/dist/src/platforms/line/commands/message.js.map +1 -0
- package/dist/src/platforms/line/commands/profile.d.ts +3 -0
- package/dist/src/platforms/line/commands/profile.d.ts.map +1 -0
- package/dist/src/platforms/line/commands/profile.js +23 -0
- package/dist/src/platforms/line/commands/profile.js.map +1 -0
- package/dist/src/platforms/line/credential-manager.d.ts +22 -0
- package/dist/src/platforms/line/credential-manager.d.ts.map +1 -0
- package/dist/src/platforms/line/credential-manager.js +71 -0
- package/dist/src/platforms/line/credential-manager.js.map +1 -0
- package/dist/src/platforms/line/ensure-auth.d.ts +3 -0
- package/dist/src/platforms/line/ensure-auth.d.ts.map +1 -0
- package/dist/src/platforms/line/ensure-auth.js +10 -0
- package/dist/src/platforms/line/ensure-auth.js.map +1 -0
- package/dist/src/platforms/line/index.d.ts +7 -0
- package/dist/src/platforms/line/index.d.ts.map +1 -0
- package/dist/src/platforms/line/index.js +6 -0
- package/dist/src/platforms/line/index.js.map +1 -0
- package/dist/src/platforms/line/listener.d.ts +22 -0
- package/dist/src/platforms/line/listener.d.ts.map +1 -0
- package/dist/src/platforms/line/listener.js +121 -0
- package/dist/src/platforms/line/listener.js.map +1 -0
- package/dist/src/platforms/line/types.d.ts +165 -0
- package/dist/src/platforms/line/types.d.ts.map +1 -0
- package/dist/src/platforms/line/types.js +79 -0
- package/dist/src/platforms/line/types.js.map +1 -0
- package/dist/src/platforms/slack/cli.d.ts.map +1 -1
- package/dist/src/platforms/slack/cli.js +6 -1
- package/dist/src/platforms/slack/cli.js.map +1 -1
- package/dist/src/platforms/slack/client.d.ts +85 -3
- package/dist/src/platforms/slack/client.d.ts.map +1 -1
- package/dist/src/platforms/slack/client.js +577 -40
- package/dist/src/platforms/slack/client.js.map +1 -1
- package/dist/src/platforms/slack/commands/activity.js +1 -1
- package/dist/src/platforms/slack/commands/activity.js.map +1 -1
- package/dist/src/platforms/slack/commands/auth.js +2 -2
- package/dist/src/platforms/slack/commands/auth.js.map +1 -1
- package/dist/src/platforms/slack/commands/bookmark.d.ts +3 -0
- package/dist/src/platforms/slack/commands/bookmark.d.ts.map +1 -0
- package/dist/src/platforms/slack/commands/bookmark.js +116 -0
- package/dist/src/platforms/slack/commands/bookmark.js.map +1 -0
- package/dist/src/platforms/slack/commands/channel.d.ts.map +1 -1
- package/dist/src/platforms/slack/commands/channel.js +198 -5
- package/dist/src/platforms/slack/commands/channel.js.map +1 -1
- package/dist/src/platforms/slack/commands/drafts.js +1 -1
- package/dist/src/platforms/slack/commands/drafts.js.map +1 -1
- package/dist/src/platforms/slack/commands/emoji.d.ts +3 -0
- package/dist/src/platforms/slack/commands/emoji.d.ts.map +1 -0
- package/dist/src/platforms/slack/commands/emoji.js +27 -0
- package/dist/src/platforms/slack/commands/emoji.js.map +1 -0
- package/dist/src/platforms/slack/commands/file.d.ts.map +1 -1
- package/dist/src/platforms/slack/commands/file.js +26 -5
- package/dist/src/platforms/slack/commands/file.js.map +1 -1
- package/dist/src/platforms/slack/commands/index.d.ts +5 -0
- package/dist/src/platforms/slack/commands/index.d.ts.map +1 -1
- package/dist/src/platforms/slack/commands/index.js +5 -0
- package/dist/src/platforms/slack/commands/index.js.map +1 -1
- package/dist/src/platforms/slack/commands/message.d.ts.map +1 -1
- package/dist/src/platforms/slack/commands/message.js +134 -8
- package/dist/src/platforms/slack/commands/message.js.map +1 -1
- package/dist/src/platforms/slack/commands/pin.d.ts +3 -0
- package/dist/src/platforms/slack/commands/pin.d.ts.map +1 -0
- package/dist/src/platforms/slack/commands/pin.js +76 -0
- package/dist/src/platforms/slack/commands/pin.js.map +1 -0
- package/dist/src/platforms/slack/commands/reaction.js +3 -3
- package/dist/src/platforms/slack/commands/reaction.js.map +1 -1
- package/dist/src/platforms/slack/commands/reminder.d.ts +3 -0
- package/dist/src/platforms/slack/commands/reminder.d.ts.map +1 -0
- package/dist/src/platforms/slack/commands/reminder.js +98 -0
- package/dist/src/platforms/slack/commands/reminder.js.map +1 -0
- package/dist/src/platforms/slack/commands/saved.js +1 -1
- package/dist/src/platforms/slack/commands/saved.js.map +1 -1
- package/dist/src/platforms/slack/commands/sections.js +1 -1
- package/dist/src/platforms/slack/commands/sections.js.map +1 -1
- package/dist/src/platforms/slack/commands/snapshot.d.ts.map +1 -1
- package/dist/src/platforms/slack/commands/snapshot.js +12 -1
- package/dist/src/platforms/slack/commands/snapshot.js.map +1 -1
- package/dist/src/platforms/slack/commands/unread.js +3 -3
- package/dist/src/platforms/slack/commands/unread.js.map +1 -1
- package/dist/src/platforms/slack/commands/user.d.ts.map +1 -1
- package/dist/src/platforms/slack/commands/user.js +78 -1
- package/dist/src/platforms/slack/commands/user.js.map +1 -1
- package/dist/src/platforms/slack/commands/usergroup.d.ts +3 -0
- package/dist/src/platforms/slack/commands/usergroup.d.ts.map +1 -0
- package/dist/src/platforms/slack/commands/usergroup.js +190 -0
- package/dist/src/platforms/slack/commands/usergroup.js.map +1 -0
- package/dist/src/platforms/slack/credential-manager.d.ts +2 -1
- package/dist/src/platforms/slack/credential-manager.d.ts.map +1 -1
- package/dist/src/platforms/slack/credential-manager.js +2 -1
- package/dist/src/platforms/slack/credential-manager.js.map +1 -1
- package/dist/src/platforms/slack/ensure-auth.js +4 -4
- package/dist/src/platforms/slack/ensure-auth.js.map +1 -1
- package/dist/src/platforms/slack/index.d.ts +4 -1
- package/dist/src/platforms/slack/index.d.ts.map +1 -1
- package/dist/src/platforms/slack/index.js +3 -1
- package/dist/src/platforms/slack/index.js.map +1 -1
- package/dist/src/platforms/slack/listener.d.ts +30 -0
- package/dist/src/platforms/slack/listener.d.ts.map +1 -0
- package/dist/src/platforms/slack/listener.js +157 -0
- package/dist/src/platforms/slack/listener.js.map +1 -0
- package/dist/src/platforms/slack/types.d.ts +198 -275
- package/dist/src/platforms/slack/types.d.ts.map +1 -1
- package/dist/src/platforms/slack/types.js +22 -0
- package/dist/src/platforms/slack/types.js.map +1 -1
- package/dist/src/platforms/slackbot/client.d.ts +4 -1
- package/dist/src/platforms/slackbot/client.d.ts.map +1 -1
- package/dist/src/platforms/slackbot/client.js +40 -21
- package/dist/src/platforms/slackbot/client.js.map +1 -1
- package/dist/src/platforms/slackbot/commands/auth.js +2 -2
- package/dist/src/platforms/slackbot/commands/auth.js.map +1 -1
- package/dist/src/platforms/slackbot/commands/shared.js +1 -1
- package/dist/src/platforms/slackbot/commands/shared.js.map +1 -1
- package/dist/src/platforms/slackbot/types.d.ts +20 -282
- package/dist/src/platforms/slackbot/types.d.ts.map +1 -1
- package/dist/src/platforms/teams/client.d.ts +5 -1
- package/dist/src/platforms/teams/client.d.ts.map +1 -1
- package/dist/src/platforms/teams/client.js +27 -9
- package/dist/src/platforms/teams/client.js.map +1 -1
- package/dist/src/platforms/teams/commands/auth.js +3 -3
- package/dist/src/platforms/teams/commands/auth.js.map +1 -1
- package/dist/src/platforms/teams/commands/channel.js +3 -3
- package/dist/src/platforms/teams/commands/channel.js.map +1 -1
- package/dist/src/platforms/teams/commands/file.js +3 -3
- package/dist/src/platforms/teams/commands/file.js.map +1 -1
- package/dist/src/platforms/teams/commands/message.js +4 -4
- package/dist/src/platforms/teams/commands/message.js.map +1 -1
- package/dist/src/platforms/teams/commands/reaction.js +2 -2
- package/dist/src/platforms/teams/commands/reaction.js.map +1 -1
- package/dist/src/platforms/teams/commands/snapshot.js +1 -1
- package/dist/src/platforms/teams/commands/snapshot.js.map +1 -1
- package/dist/src/platforms/teams/commands/team.js +1 -1
- package/dist/src/platforms/teams/commands/team.js.map +1 -1
- package/dist/src/platforms/teams/commands/user.js +3 -3
- package/dist/src/platforms/teams/commands/user.js.map +1 -1
- package/dist/src/platforms/teams/ensure-auth.js +1 -1
- package/dist/src/platforms/teams/ensure-auth.js.map +1 -1
- package/dist/src/platforms/teams/index.d.ts +6 -0
- package/dist/src/platforms/teams/index.d.ts.map +1 -0
- package/dist/src/platforms/teams/index.js +5 -0
- package/dist/src/platforms/teams/index.js.map +1 -0
- package/dist/src/platforms/teams/types.d.ts +26 -193
- package/dist/src/platforms/teams/types.d.ts.map +1 -1
- package/dist/src/platforms/telegram/app-config.d.ts +7 -0
- package/dist/src/platforms/telegram/app-config.d.ts.map +1 -0
- package/dist/src/platforms/telegram/app-config.js +39 -0
- package/dist/src/platforms/telegram/app-config.js.map +1 -0
- package/dist/src/platforms/telegram/chat-utils.d.ts +5 -0
- package/dist/src/platforms/telegram/chat-utils.d.ts.map +1 -0
- package/dist/src/platforms/telegram/chat-utils.js +33 -0
- package/dist/src/platforms/telegram/chat-utils.js.map +1 -0
- package/dist/src/platforms/telegram/cli.d.ts +5 -0
- package/dist/src/platforms/telegram/cli.d.ts.map +1 -0
- package/dist/src/platforms/telegram/cli.js +15 -0
- package/dist/src/platforms/telegram/cli.js.map +1 -0
- package/dist/src/platforms/telegram/client.d.ts +47 -0
- package/dist/src/platforms/telegram/client.d.ts.map +1 -0
- package/dist/src/platforms/telegram/client.js +481 -0
- package/dist/src/platforms/telegram/client.js.map +1 -0
- package/dist/src/platforms/telegram/commands/auth.d.ts +44 -0
- package/dist/src/platforms/telegram/commands/auth.d.ts.map +1 -0
- package/dist/src/platforms/telegram/commands/auth.js +522 -0
- package/dist/src/platforms/telegram/commands/auth.js.map +1 -0
- package/dist/src/platforms/telegram/commands/chat.d.ts +3 -0
- package/dist/src/platforms/telegram/commands/chat.d.ts.map +1 -0
- package/dist/src/platforms/telegram/commands/chat.js +55 -0
- package/dist/src/platforms/telegram/commands/chat.js.map +1 -0
- package/dist/src/platforms/telegram/commands/index.d.ts +4 -0
- package/dist/src/platforms/telegram/commands/index.d.ts.map +1 -0
- package/dist/src/platforms/telegram/commands/index.js +4 -0
- package/dist/src/platforms/telegram/commands/index.js.map +1 -0
- package/dist/src/platforms/telegram/commands/message.d.ts +3 -0
- package/dist/src/platforms/telegram/commands/message.d.ts.map +1 -0
- package/dist/src/platforms/telegram/commands/message.js +40 -0
- package/dist/src/platforms/telegram/commands/message.js.map +1 -0
- package/dist/src/platforms/telegram/commands/shared.d.ts +10 -0
- package/dist/src/platforms/telegram/commands/shared.d.ts.map +1 -0
- package/dist/src/platforms/telegram/commands/shared.js +32 -0
- package/dist/src/platforms/telegram/commands/shared.js.map +1 -0
- package/dist/src/platforms/telegram/credential-manager.d.ts +25 -0
- package/dist/src/platforms/telegram/credential-manager.d.ts.map +1 -0
- package/dist/src/platforms/telegram/credential-manager.js +159 -0
- package/dist/src/platforms/telegram/credential-manager.js.map +1 -0
- package/dist/src/platforms/telegram/my-telegram-org.d.ts +14 -0
- package/dist/src/platforms/telegram/my-telegram-org.d.ts.map +1 -0
- package/dist/src/platforms/telegram/my-telegram-org.js +164 -0
- package/dist/src/platforms/telegram/my-telegram-org.js.map +1 -0
- package/dist/src/platforms/telegram/tdlib.d.ts +11 -0
- package/dist/src/platforms/telegram/tdlib.d.ts.map +1 -0
- package/dist/src/platforms/telegram/tdlib.js +113 -0
- package/dist/src/platforms/telegram/tdlib.js.map +1 -0
- package/dist/src/platforms/telegram/types.d.ts +192 -0
- package/dist/src/platforms/telegram/types.d.ts.map +1 -0
- package/dist/src/platforms/telegram/types.js +183 -0
- package/dist/src/platforms/telegram/types.js.map +1 -0
- package/dist/src/platforms/whatsapp/cli.d.ts +6 -0
- package/dist/src/platforms/whatsapp/cli.d.ts.map +1 -0
- package/dist/src/platforms/whatsapp/cli.js +31 -0
- package/dist/src/platforms/whatsapp/cli.js.map +1 -0
- package/dist/src/platforms/whatsapp/client.d.ts +39 -0
- package/dist/src/platforms/whatsapp/client.d.ts.map +1 -0
- package/dist/src/platforms/whatsapp/client.js +436 -0
- package/dist/src/platforms/whatsapp/client.js.map +1 -0
- package/dist/src/platforms/whatsapp/commands/auth.d.ts +3 -0
- package/dist/src/platforms/whatsapp/commands/auth.d.ts.map +1 -0
- package/dist/src/platforms/whatsapp/commands/auth.js +170 -0
- package/dist/src/platforms/whatsapp/commands/auth.js.map +1 -0
- package/dist/src/platforms/whatsapp/commands/chat.d.ts +3 -0
- package/dist/src/platforms/whatsapp/commands/chat.d.ts.map +1 -0
- package/dist/src/platforms/whatsapp/commands/chat.js +42 -0
- package/dist/src/platforms/whatsapp/commands/chat.js.map +1 -0
- package/dist/src/platforms/whatsapp/commands/index.d.ts +4 -0
- package/dist/src/platforms/whatsapp/commands/index.d.ts.map +1 -0
- package/dist/src/platforms/whatsapp/commands/index.js +4 -0
- package/dist/src/platforms/whatsapp/commands/index.js.map +1 -0
- package/dist/src/platforms/whatsapp/commands/message.d.ts +3 -0
- package/dist/src/platforms/whatsapp/commands/message.d.ts.map +1 -0
- package/dist/src/platforms/whatsapp/commands/message.js +61 -0
- package/dist/src/platforms/whatsapp/commands/message.js.map +1 -0
- package/dist/src/platforms/whatsapp/commands/shared.d.ts +8 -0
- package/dist/src/platforms/whatsapp/commands/shared.d.ts.map +1 -0
- package/dist/src/platforms/whatsapp/commands/shared.js +37 -0
- package/dist/src/platforms/whatsapp/commands/shared.js.map +1 -0
- package/dist/src/platforms/whatsapp/credential-manager.d.ts +20 -0
- package/dist/src/platforms/whatsapp/credential-manager.d.ts.map +1 -0
- package/dist/src/platforms/whatsapp/credential-manager.js +104 -0
- package/dist/src/platforms/whatsapp/credential-manager.js.map +1 -0
- package/dist/src/platforms/whatsapp/ensure-auth.d.ts +2 -0
- package/dist/src/platforms/whatsapp/ensure-auth.d.ts.map +1 -0
- package/dist/src/platforms/whatsapp/ensure-auth.js +23 -0
- package/dist/src/platforms/whatsapp/ensure-auth.js.map +1 -0
- package/dist/src/platforms/whatsapp/index.d.ts +4 -0
- package/dist/src/platforms/whatsapp/index.d.ts.map +1 -0
- package/dist/src/platforms/whatsapp/index.js +4 -0
- package/dist/src/platforms/whatsapp/index.js.map +1 -0
- package/dist/src/platforms/whatsapp/suppress-ws-warnings.d.ts +11 -0
- package/dist/src/platforms/whatsapp/suppress-ws-warnings.d.ts.map +1 -0
- package/dist/src/platforms/whatsapp/suppress-ws-warnings.js +24 -0
- package/dist/src/platforms/whatsapp/suppress-ws-warnings.js.map +1 -0
- package/dist/src/platforms/whatsapp/types.d.ts +42 -0
- package/dist/src/platforms/whatsapp/types.d.ts.map +1 -0
- package/dist/src/platforms/whatsapp/types.js +75 -0
- package/dist/src/platforms/whatsapp/types.js.map +1 -0
- package/dist/src/platforms/whatsappbot/cli.d.ts +5 -0
- package/dist/src/platforms/whatsappbot/cli.d.ts.map +1 -0
- package/dist/src/platforms/whatsappbot/cli.js +17 -0
- package/dist/src/platforms/whatsappbot/cli.js.map +1 -0
- package/dist/src/platforms/whatsappbot/client.d.ts +31 -0
- package/dist/src/platforms/whatsappbot/client.d.ts.map +1 -0
- package/dist/src/platforms/whatsappbot/client.js +202 -0
- package/dist/src/platforms/whatsappbot/client.js.map +1 -0
- package/dist/src/platforms/whatsappbot/commands/auth.d.ts +28 -0
- package/dist/src/platforms/whatsappbot/commands/auth.d.ts.map +1 -0
- package/dist/src/platforms/whatsappbot/commands/auth.js +163 -0
- package/dist/src/platforms/whatsappbot/commands/auth.js.map +1 -0
- package/dist/src/platforms/whatsappbot/commands/index.d.ts +4 -0
- package/dist/src/platforms/whatsappbot/commands/index.d.ts.map +1 -0
- package/dist/src/platforms/whatsappbot/commands/index.js +4 -0
- package/dist/src/platforms/whatsappbot/commands/index.js.map +1 -0
- package/dist/src/platforms/whatsappbot/commands/message.d.ts +27 -0
- package/dist/src/platforms/whatsappbot/commands/message.d.ts.map +1 -0
- package/dist/src/platforms/whatsappbot/commands/message.js +122 -0
- package/dist/src/platforms/whatsappbot/commands/message.js.map +1 -0
- package/dist/src/platforms/whatsappbot/commands/shared.d.ts +9 -0
- package/dist/src/platforms/whatsappbot/commands/shared.d.ts.map +1 -0
- package/dist/src/platforms/whatsappbot/commands/shared.js +13 -0
- package/dist/src/platforms/whatsappbot/commands/shared.js.map +1 -0
- package/dist/src/platforms/whatsappbot/commands/template.d.ts +16 -0
- package/dist/src/platforms/whatsappbot/commands/template.d.ts.map +1 -0
- package/dist/src/platforms/whatsappbot/commands/template.js +51 -0
- package/dist/src/platforms/whatsappbot/commands/template.js.map +1 -0
- package/dist/src/platforms/whatsappbot/credential-manager.d.ts +17 -0
- package/dist/src/platforms/whatsappbot/credential-manager.d.ts.map +1 -0
- package/dist/src/platforms/whatsappbot/credential-manager.js +121 -0
- package/dist/src/platforms/whatsappbot/credential-manager.js.map +1 -0
- package/dist/src/platforms/whatsappbot/index.d.ts +5 -0
- package/dist/src/platforms/whatsappbot/index.d.ts.map +1 -0
- package/dist/src/platforms/whatsappbot/index.js +4 -0
- package/dist/src/platforms/whatsappbot/index.js.map +1 -0
- package/dist/src/platforms/whatsappbot/types.d.ts +66 -0
- package/dist/src/platforms/whatsappbot/types.d.ts.map +1 -0
- package/dist/src/platforms/whatsappbot/types.js +28 -0
- package/dist/src/platforms/whatsappbot/types.js.map +1 -0
- package/dist/src/tui/adapters/channeltalk-adapter.d.ts +19 -0
- package/dist/src/tui/adapters/channeltalk-adapter.d.ts.map +1 -0
- package/dist/src/tui/adapters/channeltalk-adapter.js +88 -0
- package/dist/src/tui/adapters/channeltalk-adapter.js.map +1 -0
- package/dist/src/tui/adapters/discord-adapter.d.ts +22 -0
- package/dist/src/tui/adapters/discord-adapter.d.ts.map +1 -0
- package/dist/src/tui/adapters/discord-adapter.js +100 -0
- package/dist/src/tui/adapters/discord-adapter.js.map +1 -0
- package/dist/src/tui/adapters/instagram-adapter.d.ts +18 -0
- package/dist/src/tui/adapters/instagram-adapter.d.ts.map +1 -0
- package/dist/src/tui/adapters/instagram-adapter.js +115 -0
- package/dist/src/tui/adapters/instagram-adapter.js.map +1 -0
- package/dist/src/tui/adapters/kakaotalk-adapter.d.ts +18 -0
- package/dist/src/tui/adapters/kakaotalk-adapter.d.ts.map +1 -0
- package/dist/src/tui/adapters/kakaotalk-adapter.js +146 -0
- package/dist/src/tui/adapters/kakaotalk-adapter.js.map +1 -0
- package/dist/src/tui/adapters/line-adapter.d.ts +18 -0
- package/dist/src/tui/adapters/line-adapter.d.ts.map +1 -0
- package/dist/src/tui/adapters/line-adapter.js +92 -0
- package/dist/src/tui/adapters/line-adapter.js.map +1 -0
- package/dist/src/tui/adapters/slack-adapter.d.ts +23 -0
- package/dist/src/tui/adapters/slack-adapter.d.ts.map +1 -0
- package/dist/src/tui/adapters/slack-adapter.js +111 -0
- package/dist/src/tui/adapters/slack-adapter.js.map +1 -0
- package/dist/src/tui/adapters/teams-adapter.d.ts +20 -0
- package/dist/src/tui/adapters/teams-adapter.d.ts.map +1 -0
- package/dist/src/tui/adapters/teams-adapter.js +85 -0
- package/dist/src/tui/adapters/teams-adapter.js.map +1 -0
- package/dist/src/tui/adapters/telegram-adapter.d.ts +18 -0
- package/dist/src/tui/adapters/telegram-adapter.d.ts.map +1 -0
- package/dist/src/tui/adapters/telegram-adapter.js +183 -0
- package/dist/src/tui/adapters/telegram-adapter.js.map +1 -0
- package/dist/src/tui/adapters/types.d.ts +41 -0
- package/dist/src/tui/adapters/types.d.ts.map +1 -0
- package/dist/src/tui/adapters/types.js +2 -0
- package/dist/src/tui/adapters/types.js.map +1 -0
- package/dist/src/tui/adapters/whatsapp-adapter.d.ts +18 -0
- package/dist/src/tui/adapters/whatsapp-adapter.d.ts.map +1 -0
- package/dist/src/tui/adapters/whatsapp-adapter.js +120 -0
- package/dist/src/tui/adapters/whatsapp-adapter.js.map +1 -0
- package/dist/src/tui/app.d.ts +2 -0
- package/dist/src/tui/app.d.ts.map +1 -0
- package/dist/src/tui/app.js +652 -0
- package/dist/src/tui/app.js.map +1 -0
- package/dist/src/tui/cli.d.ts +3 -0
- package/dist/src/tui/cli.d.ts.map +1 -0
- package/dist/src/tui/cli.js +14 -0
- package/dist/src/tui/cli.js.map +1 -0
- package/dist/src/tui/utils.d.ts +5 -0
- package/dist/src/tui/utils.d.ts.map +1 -0
- package/dist/src/tui/utils.js +54 -0
- package/dist/src/tui/utils.js.map +1 -0
- package/dist/src/tui/views/channel-picker.d.ts +18 -0
- package/dist/src/tui/views/channel-picker.d.ts.map +1 -0
- package/dist/src/tui/views/channel-picker.js +131 -0
- package/dist/src/tui/views/channel-picker.js.map +1 -0
- package/dist/src/tui/views/workspace-picker.d.ts +18 -0
- package/dist/src/tui/views/workspace-picker.d.ts.map +1 -0
- package/dist/src/tui/views/workspace-picker.js +131 -0
- package/dist/src/tui/views/workspace-picker.js.map +1 -0
- package/docs/bun.lock +2 -666
- package/docs/content/docs/agent-skills.mdx +1 -1
- package/docs/content/docs/cli/channeltalk.mdx +264 -0
- package/docs/content/docs/cli/channeltalkbot.mdx +261 -0
- package/docs/content/docs/cli/instagram.mdx +211 -0
- package/docs/content/docs/cli/kakaotalk.mdx +286 -0
- package/docs/content/docs/cli/line.mdx +306 -0
- package/docs/content/docs/cli/meta.json +18 -0
- package/docs/content/docs/cli/slack.mdx +395 -0
- package/docs/content/docs/{integrations → cli}/slackbot.mdx +1 -1
- package/docs/content/docs/{integrations → cli}/teams.mdx +2 -2
- package/docs/content/docs/cli/telegram.mdx +107 -0
- package/docs/content/docs/cli/whatsapp.mdx +163 -0
- package/docs/content/docs/cli/whatsappbot.mdx +169 -0
- package/docs/content/docs/index.mdx +21 -13
- package/docs/content/docs/meta.json +9 -1
- package/docs/content/docs/quick-start.mdx +29 -6
- package/docs/content/docs/sdk/channeltalk.mdx +384 -0
- package/docs/content/docs/sdk/channeltalkbot.mdx +395 -0
- package/docs/content/docs/sdk/discord.mdx +535 -0
- package/docs/content/docs/sdk/instagram.mdx +367 -0
- package/docs/content/docs/sdk/kakaotalk.mdx +290 -0
- package/docs/content/docs/sdk/line.mdx +347 -0
- package/docs/content/docs/sdk/meta.json +4 -0
- package/docs/content/docs/sdk/slack.mdx +671 -0
- package/docs/content/docs/sdk/teams.mdx +350 -0
- package/docs/content/docs/sdk/whatsapp.mdx +293 -0
- package/docs/content/docs/sdk/whatsappbot.mdx +266 -0
- package/docs/content/docs/tui.mdx +137 -0
- package/docs/public/tui.png +0 -0
- package/docs/src/app/page.tsx +885 -308
- package/e2e/discordbot.e2e.test.ts +1 -1
- package/examples/discord-listen.ts +56 -0
- package/examples/kakaotalk-listen.ts +49 -0
- package/examples/slack-listen.ts +60 -0
- package/package.json +118 -9
- package/scripts/postbuild.ts +1 -0
- package/scripts/prepublish.ts +21 -1
- package/skills/agent-channeltalk/SKILL.md +18 -6
- package/skills/agent-channeltalkbot/SKILL.md +1 -1
- package/skills/agent-discord/SKILL.md +77 -2
- package/skills/agent-discord/references/common-patterns.md +1 -1
- package/skills/agent-discordbot/SKILL.md +1 -1
- package/skills/agent-instagram/SKILL.md +383 -0
- package/skills/agent-instagram/references/authentication.md +256 -0
- package/skills/agent-instagram/references/common-patterns.md +362 -0
- package/skills/agent-instagram/templates/chat-summary.sh +124 -0
- package/skills/agent-instagram/templates/monitor-chat.sh +143 -0
- package/skills/agent-instagram/templates/post-message.sh +130 -0
- package/skills/agent-kakaotalk/SKILL.md +587 -0
- package/skills/agent-kakaotalk/references/authentication.md +343 -0
- package/skills/agent-kakaotalk/references/common-patterns.md +403 -0
- package/skills/agent-kakaotalk/templates/chat-summary.sh +121 -0
- package/skills/agent-kakaotalk/templates/monitor-chat.sh +160 -0
- package/skills/agent-kakaotalk/templates/post-message.sh +123 -0
- package/skills/agent-line/SKILL.md +490 -0
- package/skills/agent-line/references/authentication.md +297 -0
- package/skills/agent-line/references/common-patterns.md +355 -0
- package/skills/agent-line/templates/chat-summary.sh +63 -0
- package/skills/agent-line/templates/monitor-chat.sh +76 -0
- package/skills/agent-line/templates/post-message.sh +123 -0
- package/skills/agent-slack/SKILL.md +266 -7
- package/skills/agent-slack/references/common-patterns.md +105 -39
- package/skills/agent-slackbot/SKILL.md +1 -1
- package/skills/agent-slackbot/references/common-patterns.md +52 -0
- package/skills/agent-teams/SKILL.md +49 -1
- package/skills/agent-telegram/SKILL.md +123 -0
- package/skills/agent-whatsapp/SKILL.md +382 -0
- package/skills/agent-whatsapp/references/authentication.md +191 -0
- package/skills/agent-whatsapp/references/common-patterns.md +336 -0
- package/skills/agent-whatsapp/templates/chat-summary.sh +122 -0
- package/skills/agent-whatsapp/templates/monitor-chat.sh +157 -0
- package/skills/agent-whatsapp/templates/post-message.sh +120 -0
- package/skills/agent-whatsappbot/SKILL.md +371 -0
- package/skills/agent-whatsappbot/references/authentication.md +216 -0
- package/skills/agent-whatsappbot/references/common-patterns.md +331 -0
- package/skills/agent-whatsappbot/templates/account-summary.sh +127 -0
- package/skills/agent-whatsappbot/templates/post-message.sh +120 -0
- package/skills/agent-whatsappbot/templates/send-template.sh +153 -0
- package/src/cli.ts +34 -6
- package/src/platforms/channeltalk/client.test.ts +30 -28
- package/src/platforms/channeltalk/client.ts +29 -8
- package/src/platforms/channeltalk/commands/auth.ts +9 -7
- package/src/platforms/channeltalk/commands/shared.ts +1 -1
- package/src/platforms/channeltalk/ensure-auth.ts +10 -8
- package/src/platforms/channeltalk/index.test.ts +114 -0
- package/src/platforms/channeltalk/index.ts +27 -14
- package/src/platforms/channeltalk/token-extractor.test.ts +227 -65
- package/src/platforms/channeltalk/token-extractor.ts +146 -25
- package/src/platforms/channeltalk/types.ts +3 -1
- package/src/platforms/channeltalkbot/client.test.ts +12 -12
- package/src/platforms/channeltalkbot/client.ts +31 -11
- package/src/platforms/channeltalkbot/commands/auth.test.ts +1 -5
- package/src/platforms/channeltalkbot/commands/auth.ts +2 -2
- package/src/platforms/channeltalkbot/commands/shared.ts +1 -1
- package/src/platforms/channeltalkbot/index.test.ts +76 -0
- package/src/platforms/channeltalkbot/index.ts +14 -11
- package/src/platforms/discord/client.test.ts +30 -30
- package/src/platforms/discord/client.ts +33 -6
- package/src/platforms/discord/commands/auth.test.ts +2 -2
- package/src/platforms/discord/commands/auth.ts +2 -2
- package/src/platforms/discord/commands/channel.test.ts +6 -6
- package/src/platforms/discord/commands/channel.ts +3 -3
- package/src/platforms/discord/commands/dm.ts +2 -2
- package/src/platforms/discord/commands/file.ts +3 -3
- package/src/platforms/discord/commands/friend.test.ts +5 -5
- package/src/platforms/discord/commands/friend.ts +1 -1
- package/src/platforms/discord/commands/member.test.ts +4 -4
- package/src/platforms/discord/commands/member.ts +1 -1
- package/src/platforms/discord/commands/mention.test.ts +4 -4
- package/src/platforms/discord/commands/mention.ts +1 -1
- package/src/platforms/discord/commands/message.ts +6 -6
- package/src/platforms/discord/commands/note.ts +2 -2
- package/src/platforms/discord/commands/profile.ts +1 -1
- package/src/platforms/discord/commands/reaction.ts +3 -3
- package/src/platforms/discord/commands/server.test.ts +2 -2
- package/src/platforms/discord/commands/server.ts +1 -1
- package/src/platforms/discord/commands/snapshot.ts +1 -1
- package/src/platforms/discord/commands/thread.test.ts +5 -5
- package/src/platforms/discord/commands/thread.ts +2 -2
- package/src/platforms/discord/commands/user.ts +3 -3
- package/src/platforms/discord/ensure-auth.ts +1 -1
- package/src/platforms/discord/index.test.ts +84 -0
- package/src/platforms/discord/index.ts +51 -0
- package/src/platforms/discord/listener.test.ts +782 -0
- package/src/platforms/discord/listener.ts +297 -0
- package/src/platforms/discord/types.ts +133 -0
- package/src/platforms/discordbot/client.test.ts +33 -33
- package/src/platforms/discordbot/client.ts +28 -7
- package/src/platforms/discordbot/commands/auth.test.ts +1 -5
- package/src/platforms/discordbot/commands/auth.ts +2 -2
- package/src/platforms/discordbot/commands/channel.test.ts +1 -5
- package/src/platforms/discordbot/commands/message.test.ts +1 -3
- package/src/platforms/discordbot/commands/server.test.ts +1 -5
- package/src/platforms/discordbot/commands/shared.ts +1 -1
- package/src/platforms/discordbot/commands/snapshot.test.ts +1 -3
- package/src/platforms/discordbot/commands/thread.test.ts +1 -3
- package/src/platforms/discordbot/commands/user.test.ts +1 -5
- package/src/platforms/instagram/cli.ts +37 -0
- package/src/platforms/instagram/client.test.ts +396 -0
- package/src/platforms/instagram/client.ts +655 -0
- package/src/platforms/instagram/commands/auth.ts +401 -0
- package/src/platforms/instagram/commands/chat.ts +49 -0
- package/src/platforms/instagram/commands/index.ts +3 -0
- package/src/platforms/instagram/commands/message.ts +134 -0
- package/src/platforms/instagram/commands/shared.test.ts +51 -0
- package/src/platforms/instagram/commands/shared.ts +55 -0
- package/src/platforms/instagram/credential-manager.test.ts +277 -0
- package/src/platforms/instagram/credential-manager.ts +134 -0
- package/src/platforms/instagram/ensure-auth.test.ts +84 -0
- package/src/platforms/instagram/ensure-auth.ts +24 -0
- package/src/platforms/instagram/index.test.ts +44 -0
- package/src/platforms/instagram/index.ts +16 -0
- package/src/platforms/instagram/listener.test.ts +130 -0
- package/src/platforms/instagram/listener.ts +106 -0
- package/src/platforms/instagram/types.test.ts +228 -0
- package/src/platforms/instagram/types.ts +153 -0
- package/src/platforms/kakaotalk/auth/kakao-login.ts +296 -0
- package/src/platforms/kakaotalk/cli.ts +37 -0
- package/src/platforms/kakaotalk/client.test.ts +490 -0
- package/src/platforms/kakaotalk/client.ts +328 -0
- package/src/platforms/kakaotalk/commands/auth.ts +569 -0
- package/src/platforms/kakaotalk/commands/chat.ts +34 -0
- package/src/platforms/kakaotalk/commands/index.ts +3 -0
- package/src/platforms/kakaotalk/commands/message.ts +56 -0
- package/src/platforms/kakaotalk/commands/shared.ts +38 -0
- package/src/platforms/kakaotalk/credential-manager.test.ts +231 -0
- package/src/platforms/kakaotalk/credential-manager.ts +110 -0
- package/src/platforms/kakaotalk/ensure-auth.ts +16 -0
- package/src/platforms/kakaotalk/index.test.ts +68 -0
- package/src/platforms/kakaotalk/index.ts +30 -0
- package/src/platforms/kakaotalk/listener.test.ts +370 -0
- package/src/platforms/kakaotalk/listener.ts +203 -0
- package/src/platforms/kakaotalk/protocol/NOTICE.md +51 -0
- package/src/platforms/kakaotalk/protocol/config.ts +28 -0
- package/src/platforms/kakaotalk/protocol/connection.ts +159 -0
- package/src/platforms/kakaotalk/protocol/crypto.ts +71 -0
- package/src/platforms/kakaotalk/protocol/packet.ts +47 -0
- package/src/platforms/kakaotalk/protocol/session.ts +156 -0
- package/src/platforms/kakaotalk/protocol/types.ts +42 -0
- package/src/platforms/kakaotalk/token-extractor.ts +320 -0
- package/src/platforms/kakaotalk/types.ts +212 -0
- package/src/platforms/line/cli.ts +39 -0
- package/src/platforms/line/client.test.ts +162 -0
- package/src/platforms/line/client.ts +352 -0
- package/src/platforms/line/commands/auth.ts +219 -0
- package/src/platforms/line/commands/chat.ts +34 -0
- package/src/platforms/line/commands/friend.ts +28 -0
- package/src/platforms/line/commands/index.ts +5 -0
- package/src/platforms/line/commands/message.ts +59 -0
- package/src/platforms/line/commands/profile.ts +24 -0
- package/src/platforms/line/credential-manager.test.ts +163 -0
- package/src/platforms/line/credential-manager.ts +99 -0
- package/src/platforms/line/ensure-auth.ts +13 -0
- package/src/platforms/line/index.test.ts +48 -0
- package/src/platforms/line/index.ts +27 -0
- package/src/platforms/line/listener.test.ts +341 -0
- package/src/platforms/line/listener.ts +138 -0
- package/src/platforms/line/types.test.ts +157 -0
- package/src/platforms/line/types.ts +181 -0
- package/src/platforms/slack/cli.ts +10 -0
- package/src/platforms/slack/client.test.ts +703 -69
- package/src/platforms/slack/client.ts +664 -43
- package/src/platforms/slack/commands/activity.ts +1 -1
- package/src/platforms/slack/commands/auth.ts +2 -2
- package/src/platforms/slack/commands/bookmark.test.ts +91 -0
- package/src/platforms/slack/commands/bookmark.ts +148 -0
- package/src/platforms/slack/commands/channel.test.ts +47 -1
- package/src/platforms/slack/commands/channel.ts +255 -4
- package/src/platforms/slack/commands/drafts.ts +1 -1
- package/src/platforms/slack/commands/emoji.test.ts +32 -0
- package/src/platforms/slack/commands/emoji.ts +33 -0
- package/src/platforms/slack/commands/file.ts +30 -4
- package/src/platforms/slack/commands/index.ts +5 -0
- package/src/platforms/slack/commands/message.ts +173 -7
- package/src/platforms/slack/commands/pin.test.ts +72 -0
- package/src/platforms/slack/commands/pin.ts +93 -0
- package/src/platforms/slack/commands/reaction.ts +3 -3
- package/src/platforms/slack/commands/reminder.test.ts +86 -0
- package/src/platforms/slack/commands/reminder.ts +125 -0
- package/src/platforms/slack/commands/saved.ts +1 -1
- package/src/platforms/slack/commands/sections.ts +1 -1
- package/src/platforms/slack/commands/snapshot.test.ts +4 -4
- package/src/platforms/slack/commands/snapshot.ts +14 -1
- package/src/platforms/slack/commands/unread.test.ts +3 -3
- package/src/platforms/slack/commands/unread.ts +3 -3
- package/src/platforms/slack/commands/user.ts +90 -1
- package/src/platforms/slack/commands/usergroup.test.ts +157 -0
- package/src/platforms/slack/commands/usergroup.ts +242 -0
- package/src/platforms/slack/credential-manager.ts +3 -1
- package/src/platforms/slack/ensure-auth.ts +4 -4
- package/src/platforms/slack/index.test.ts +59 -0
- package/src/platforms/slack/index.ts +46 -1
- package/src/platforms/slack/listener.test.ts +370 -0
- package/src/platforms/slack/listener.ts +181 -0
- package/src/platforms/slack/types.ts +187 -0
- package/src/platforms/slackbot/client.test.ts +26 -26
- package/src/platforms/slackbot/client.ts +40 -22
- package/src/platforms/slackbot/commands/auth.test.ts +1 -5
- package/src/platforms/slackbot/commands/auth.ts +2 -2
- package/src/platforms/slackbot/commands/shared.ts +1 -1
- package/src/platforms/teams/client.test.ts +34 -34
- package/src/platforms/teams/client.ts +32 -9
- package/src/platforms/teams/commands/auth.test.ts +2 -2
- package/src/platforms/teams/commands/auth.ts +3 -3
- package/src/platforms/teams/commands/channel.test.ts +6 -6
- package/src/platforms/teams/commands/channel.ts +3 -3
- package/src/platforms/teams/commands/file.ts +3 -3
- package/src/platforms/teams/commands/message.ts +4 -4
- package/src/platforms/teams/commands/reaction.ts +2 -2
- package/src/platforms/teams/commands/snapshot.ts +1 -1
- package/src/platforms/teams/commands/team.test.ts +2 -2
- package/src/platforms/teams/commands/team.ts +1 -1
- package/src/platforms/teams/commands/user.ts +3 -3
- package/src/platforms/teams/ensure-auth.ts +1 -1
- package/src/platforms/teams/index.test.ts +74 -0
- package/src/platforms/teams/index.ts +30 -0
- package/src/platforms/telegram/app-config.test.ts +44 -0
- package/src/platforms/telegram/app-config.ts +53 -0
- package/src/platforms/telegram/chat-utils.test.ts +71 -0
- package/src/platforms/telegram/chat-utils.ts +39 -0
- package/src/platforms/telegram/cli.ts +20 -0
- package/src/platforms/telegram/client.test.ts +90 -0
- package/src/platforms/telegram/client.ts +623 -0
- package/src/platforms/telegram/commands/auth.test.ts +113 -0
- package/src/platforms/telegram/commands/auth.ts +662 -0
- package/src/platforms/telegram/commands/chat.ts +65 -0
- package/src/platforms/telegram/commands/index.ts +3 -0
- package/src/platforms/telegram/commands/message.ts +51 -0
- package/src/platforms/telegram/commands/shared.test.ts +15 -0
- package/src/platforms/telegram/commands/shared.ts +50 -0
- package/src/platforms/telegram/credential-manager.test.ts +152 -0
- package/src/platforms/telegram/credential-manager.ts +203 -0
- package/src/platforms/telegram/my-telegram-org.ts +206 -0
- package/src/platforms/telegram/tdlib.ts +159 -0
- package/src/platforms/telegram/types.test.ts +74 -0
- package/src/platforms/telegram/types.ts +417 -0
- package/src/platforms/whatsapp/cli.ts +38 -0
- package/src/platforms/whatsapp/client.ts +526 -0
- package/src/platforms/whatsapp/commands/auth.ts +205 -0
- package/src/platforms/whatsapp/commands/chat.ts +49 -0
- package/src/platforms/whatsapp/commands/index.ts +3 -0
- package/src/platforms/whatsapp/commands/message.ts +79 -0
- package/src/platforms/whatsapp/commands/shared.ts +61 -0
- package/src/platforms/whatsapp/credential-manager.test.ts +278 -0
- package/src/platforms/whatsapp/credential-manager.ts +134 -0
- package/src/platforms/whatsapp/ensure-auth.test.ts +85 -0
- package/src/platforms/whatsapp/ensure-auth.ts +26 -0
- package/src/platforms/whatsapp/index.test.ts +39 -0
- package/src/platforms/whatsapp/index.ts +16 -0
- package/src/platforms/whatsapp/suppress-ws-warnings.ts +21 -0
- package/src/platforms/whatsapp/types.test.ts +190 -0
- package/src/platforms/whatsapp/types.ts +95 -0
- package/src/platforms/whatsappbot/cli.ts +23 -0
- package/src/platforms/whatsappbot/client.test.ts +411 -0
- package/src/platforms/whatsappbot/client.ts +256 -0
- package/src/platforms/whatsappbot/commands/auth.ts +206 -0
- package/src/platforms/whatsappbot/commands/index.ts +3 -0
- package/src/platforms/whatsappbot/commands/message.ts +148 -0
- package/src/platforms/whatsappbot/commands/shared.ts +22 -0
- package/src/platforms/whatsappbot/commands/template.ts +69 -0
- package/src/platforms/whatsappbot/credential-manager.test.ts +303 -0
- package/src/platforms/whatsappbot/credential-manager.ts +148 -0
- package/src/platforms/whatsappbot/index.test.ts +34 -0
- package/src/platforms/whatsappbot/index.ts +18 -0
- package/src/platforms/whatsappbot/types.test.ts +141 -0
- package/src/platforms/whatsappbot/types.ts +71 -0
- package/src/tui/adapters/channeltalk-adapter.ts +102 -0
- package/src/tui/adapters/discord-adapter.ts +112 -0
- package/src/tui/adapters/instagram-adapter.ts +132 -0
- package/src/tui/adapters/kakaotalk-adapter.ts +163 -0
- package/src/tui/adapters/line-adapter.ts +109 -0
- package/src/tui/adapters/slack-adapter.ts +128 -0
- package/src/tui/adapters/teams-adapter.ts +95 -0
- package/src/tui/adapters/telegram-adapter.ts +203 -0
- package/src/tui/adapters/types.ts +43 -0
- package/src/tui/adapters/whatsapp-adapter.ts +138 -0
- package/src/tui/app.ts +689 -0
- package/src/tui/cli.ts +18 -0
- package/src/tui/utils.test.ts +149 -0
- package/src/tui/utils.ts +58 -0
- package/src/tui/views/channel-picker.ts +146 -0
- package/src/tui/views/workspace-picker.ts +146 -0
- package/docs/content/docs/integrations/meta.json +0 -5
- package/docs/content/docs/integrations/slack.mdx +0 -218
- package/docs/content/docs/{integrations → cli}/discord.mdx +19 -19
- package/docs/content/docs/{integrations → cli}/discordbot.mdx +8 -8
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
|
|
2
|
+
|
|
3
|
+
import { WhatsAppBotClient } from '@/platforms/whatsappbot/client'
|
|
4
|
+
import { WhatsAppBotError } from '@/platforms/whatsappbot/types'
|
|
5
|
+
|
|
6
|
+
describe('WhatsAppBotClient', () => {
|
|
7
|
+
const originalFetch = globalThis.fetch
|
|
8
|
+
let fetchCalls: Array<{ url: string; options?: RequestInit }> = []
|
|
9
|
+
let fetchResponses: Response[] = []
|
|
10
|
+
let fetchIndex = 0
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
fetchCalls = []
|
|
14
|
+
fetchResponses = []
|
|
15
|
+
fetchIndex = 0
|
|
16
|
+
Object.defineProperty(globalThis, 'fetch', {
|
|
17
|
+
value: async (url: string | URL | Request, options?: RequestInit): Promise<Response> => {
|
|
18
|
+
fetchCalls.push({ url: url.toString(), options })
|
|
19
|
+
const response = fetchResponses[fetchIndex]
|
|
20
|
+
fetchIndex++
|
|
21
|
+
if (!response) {
|
|
22
|
+
throw new Error('No mock response configured')
|
|
23
|
+
}
|
|
24
|
+
return response
|
|
25
|
+
},
|
|
26
|
+
writable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
Object.defineProperty(globalThis, 'fetch', {
|
|
33
|
+
value: originalFetch,
|
|
34
|
+
writable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const mockResponse = (body: unknown, status = 200, headers: Record<string, string> = {}) => {
|
|
40
|
+
const defaultHeaders: Record<string, string> = {
|
|
41
|
+
'Content-Type': 'application/json',
|
|
42
|
+
...headers,
|
|
43
|
+
}
|
|
44
|
+
fetchResponses.push(
|
|
45
|
+
new Response(body === null ? null : JSON.stringify(body), {
|
|
46
|
+
status,
|
|
47
|
+
headers: defaultHeaders,
|
|
48
|
+
}),
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
describe('login', () => {
|
|
53
|
+
test('throws on empty phoneNumberId', async () => {
|
|
54
|
+
await expect(new WhatsAppBotClient().login({ phoneNumberId: '', accessToken: 'access-token' })).rejects.toThrow(WhatsAppBotError)
|
|
55
|
+
await expect(new WhatsAppBotClient().login({ phoneNumberId: '', accessToken: 'access-token' })).rejects.toThrow('Phone number ID is required')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('throws on empty accessToken', async () => {
|
|
59
|
+
await expect(new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: '' })).rejects.toThrow(WhatsAppBotError)
|
|
60
|
+
await expect(new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: '' })).rejects.toThrow('Access token is required')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('accepts valid phoneNumberId and accessToken', async () => {
|
|
64
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'access-token' })
|
|
65
|
+
expect(client).toBeInstanceOf(WhatsAppBotClient)
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
describe('verifyToken', () => {
|
|
70
|
+
test('sends GET request with correct URL and auth header', async () => {
|
|
71
|
+
mockResponse({ verified_name: 'Test Business' })
|
|
72
|
+
|
|
73
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
74
|
+
const result = await client.verifyToken()
|
|
75
|
+
|
|
76
|
+
expect(result.verified_name).toBe('Test Business')
|
|
77
|
+
expect(fetchCalls.length).toBe(1)
|
|
78
|
+
expect(fetchCalls[0].url).toBe('https://graph.facebook.com/v23.0/phone-123?fields=verified_name')
|
|
79
|
+
expect(fetchCalls[0].options?.headers).toMatchObject({
|
|
80
|
+
Authorization: 'Bearer my-token',
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test('throws WhatsAppBotError on API error', async () => {
|
|
85
|
+
mockResponse({ error: { message: 'Invalid token', code: 190 } }, 401)
|
|
86
|
+
|
|
87
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'bad-token' })
|
|
88
|
+
await expect(client.verifyToken()).rejects.toThrow(WhatsAppBotError)
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
describe('sendTextMessage', () => {
|
|
93
|
+
test('sends POST request with correct body shape', async () => {
|
|
94
|
+
mockResponse({
|
|
95
|
+
messaging_product: 'whatsapp',
|
|
96
|
+
contacts: [{ input: '+15551234567', wa_id: '15551234567' }],
|
|
97
|
+
messages: [{ id: 'wamid.abc123' }],
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
101
|
+
const result = await client.sendTextMessage('+15551234567', 'Hello world')
|
|
102
|
+
|
|
103
|
+
expect(result.messages[0].id).toBe('wamid.abc123')
|
|
104
|
+
expect(fetchCalls[0].url).toBe('https://graph.facebook.com/v23.0/phone-123/messages')
|
|
105
|
+
expect(fetchCalls[0].options?.method).toBe('POST')
|
|
106
|
+
|
|
107
|
+
const body = JSON.parse(fetchCalls[0].options?.body as string)
|
|
108
|
+
expect(body).toMatchObject({
|
|
109
|
+
messaging_product: 'whatsapp',
|
|
110
|
+
to: '+15551234567',
|
|
111
|
+
type: 'text',
|
|
112
|
+
text: { body: 'Hello world', preview_url: false },
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
test('sends correct Authorization header', async () => {
|
|
117
|
+
mockResponse({
|
|
118
|
+
messaging_product: 'whatsapp',
|
|
119
|
+
contacts: [],
|
|
120
|
+
messages: [{ id: 'wamid.test' }],
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'secret-token' })
|
|
124
|
+
await client.sendTextMessage('+15551234567', 'Hello')
|
|
125
|
+
|
|
126
|
+
expect(fetchCalls[0].options?.headers).toMatchObject({
|
|
127
|
+
Authorization: 'Bearer secret-token',
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
test('returns WhatsAppBotMessageResponse', async () => {
|
|
132
|
+
mockResponse({
|
|
133
|
+
messaging_product: 'whatsapp',
|
|
134
|
+
contacts: [{ input: '+15551234567', wa_id: '15551234567' }],
|
|
135
|
+
messages: [{ id: 'wamid.abc123' }],
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
139
|
+
const result = await client.sendTextMessage('+15551234567', 'Hello')
|
|
140
|
+
|
|
141
|
+
expect(result.messaging_product).toBe('whatsapp')
|
|
142
|
+
expect(result.contacts).toHaveLength(1)
|
|
143
|
+
expect(result.messages).toHaveLength(1)
|
|
144
|
+
})
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
describe('sendTemplateMessage', () => {
|
|
148
|
+
test('sends POST with template payload', async () => {
|
|
149
|
+
mockResponse({
|
|
150
|
+
messaging_product: 'whatsapp',
|
|
151
|
+
contacts: [{ input: '+15551234567', wa_id: '15551234567' }],
|
|
152
|
+
messages: [{ id: 'wamid.template1' }],
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
156
|
+
await client.sendTemplateMessage('+15551234567', 'hello_world', 'en_US')
|
|
157
|
+
|
|
158
|
+
const body = JSON.parse(fetchCalls[0].options?.body as string)
|
|
159
|
+
expect(body).toMatchObject({
|
|
160
|
+
messaging_product: 'whatsapp',
|
|
161
|
+
to: '+15551234567',
|
|
162
|
+
type: 'template',
|
|
163
|
+
template: { name: 'hello_world', language: { code: 'en_US' } },
|
|
164
|
+
})
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
test('includes components when provided', async () => {
|
|
168
|
+
mockResponse({
|
|
169
|
+
messaging_product: 'whatsapp',
|
|
170
|
+
contacts: [],
|
|
171
|
+
messages: [{ id: 'wamid.template2' }],
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
const components = [{ type: 'body', parameters: [{ type: 'text', text: 'World' }] }]
|
|
175
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
176
|
+
await client.sendTemplateMessage('+15551234567', 'greeting', 'en_US', components)
|
|
177
|
+
|
|
178
|
+
const body = JSON.parse(fetchCalls[0].options?.body as string)
|
|
179
|
+
expect(body.template.components).toEqual(components)
|
|
180
|
+
})
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
describe('sendReaction', () => {
|
|
184
|
+
test('sends POST with reaction payload', async () => {
|
|
185
|
+
mockResponse({
|
|
186
|
+
messaging_product: 'whatsapp',
|
|
187
|
+
contacts: [],
|
|
188
|
+
messages: [{ id: 'wamid.reaction1' }],
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
192
|
+
await client.sendReaction('+15551234567', 'wamid.orig123', '👍')
|
|
193
|
+
|
|
194
|
+
const body = JSON.parse(fetchCalls[0].options?.body as string)
|
|
195
|
+
expect(body).toMatchObject({
|
|
196
|
+
messaging_product: 'whatsapp',
|
|
197
|
+
to: '+15551234567',
|
|
198
|
+
type: 'reaction',
|
|
199
|
+
reaction: { message_id: 'wamid.orig123', emoji: '👍' },
|
|
200
|
+
})
|
|
201
|
+
})
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
describe('sendImageMessage', () => {
|
|
205
|
+
test('sends POST with image payload', async () => {
|
|
206
|
+
mockResponse({
|
|
207
|
+
messaging_product: 'whatsapp',
|
|
208
|
+
contacts: [],
|
|
209
|
+
messages: [{ id: 'wamid.image1' }],
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
213
|
+
await client.sendImageMessage('+15551234567', 'https://example.com/photo.jpg', 'My photo')
|
|
214
|
+
|
|
215
|
+
const body = JSON.parse(fetchCalls[0].options?.body as string)
|
|
216
|
+
expect(body).toMatchObject({
|
|
217
|
+
messaging_product: 'whatsapp',
|
|
218
|
+
to: '+15551234567',
|
|
219
|
+
type: 'image',
|
|
220
|
+
image: { link: 'https://example.com/photo.jpg', caption: 'My photo' },
|
|
221
|
+
})
|
|
222
|
+
})
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
describe('sendDocumentMessage', () => {
|
|
226
|
+
test('sends POST with document payload', async () => {
|
|
227
|
+
mockResponse({
|
|
228
|
+
messaging_product: 'whatsapp',
|
|
229
|
+
contacts: [],
|
|
230
|
+
messages: [{ id: 'wamid.doc1' }],
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
234
|
+
await client.sendDocumentMessage('+15551234567', 'https://example.com/report.pdf', 'report.pdf', 'Q4 Report')
|
|
235
|
+
|
|
236
|
+
const body = JSON.parse(fetchCalls[0].options?.body as string)
|
|
237
|
+
expect(body).toMatchObject({
|
|
238
|
+
messaging_product: 'whatsapp',
|
|
239
|
+
to: '+15551234567',
|
|
240
|
+
type: 'document',
|
|
241
|
+
document: { link: 'https://example.com/report.pdf', filename: 'report.pdf', caption: 'Q4 Report' },
|
|
242
|
+
})
|
|
243
|
+
})
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
describe('listTemplates', () => {
|
|
247
|
+
test('sends GET and unwraps data key from response', async () => {
|
|
248
|
+
mockResponse({
|
|
249
|
+
data: [
|
|
250
|
+
{ name: 'hello_world', status: 'APPROVED', category: 'UTILITY', language: 'en_US', components: [] },
|
|
251
|
+
{ name: 'order_update', status: 'APPROVED', category: 'UTILITY', language: 'en_US', components: [] },
|
|
252
|
+
],
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
256
|
+
const templates = await client.listTemplates()
|
|
257
|
+
|
|
258
|
+
expect(templates).toHaveLength(2)
|
|
259
|
+
expect(templates[0].name).toBe('hello_world')
|
|
260
|
+
expect(templates[1].name).toBe('order_update')
|
|
261
|
+
expect(fetchCalls[0].url).toContain('/phone-123/message_templates')
|
|
262
|
+
expect(fetchCalls[0].options?.method).toBe('GET')
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
test('passes limit parameter in URL', async () => {
|
|
266
|
+
mockResponse({ data: [] })
|
|
267
|
+
|
|
268
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
269
|
+
await client.listTemplates({ limit: 10 })
|
|
270
|
+
|
|
271
|
+
expect(fetchCalls[0].url).toContain('limit=10')
|
|
272
|
+
})
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
describe('getTemplate', () => {
|
|
276
|
+
test('sends GET with name filter and returns first match', async () => {
|
|
277
|
+
mockResponse({
|
|
278
|
+
data: [
|
|
279
|
+
{ name: 'hello_world', status: 'APPROVED', category: 'UTILITY', language: 'en_US', components: [] },
|
|
280
|
+
],
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
284
|
+
const template = await client.getTemplate('hello_world')
|
|
285
|
+
|
|
286
|
+
expect(template.name).toBe('hello_world')
|
|
287
|
+
expect(fetchCalls[0].url).toContain('name=hello_world')
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
test('throws WhatsAppBotError with not_found code when template not found', async () => {
|
|
291
|
+
mockResponse({ data: [] })
|
|
292
|
+
|
|
293
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
294
|
+
|
|
295
|
+
try {
|
|
296
|
+
await client.getTemplate('nonexistent')
|
|
297
|
+
expect.unreachable('should have thrown')
|
|
298
|
+
} catch (err) {
|
|
299
|
+
expect(err).toBeInstanceOf(WhatsAppBotError)
|
|
300
|
+
expect((err as WhatsAppBotError).code).toBe('not_found')
|
|
301
|
+
}
|
|
302
|
+
})
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
describe('rate limiting', () => {
|
|
306
|
+
test('waits when x-business-use-case-usage indicates throttle', async () => {
|
|
307
|
+
const usageHeader = JSON.stringify({
|
|
308
|
+
'123456789': [
|
|
309
|
+
{
|
|
310
|
+
call_count: 100,
|
|
311
|
+
total_cputime: 50,
|
|
312
|
+
total_time: 100,
|
|
313
|
+
type: 'UPLOAD_MEDIA',
|
|
314
|
+
estimated_time_to_regain_access: 0.1,
|
|
315
|
+
},
|
|
316
|
+
],
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
mockResponse({ verified_name: 'Test Business' }, 200, { 'x-business-use-case-usage': usageHeader })
|
|
320
|
+
mockResponse({ verified_name: 'Test Business' })
|
|
321
|
+
|
|
322
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
323
|
+
await client.verifyToken()
|
|
324
|
+
|
|
325
|
+
const startTime = Date.now()
|
|
326
|
+
await client.verifyToken()
|
|
327
|
+
const elapsed = Date.now() - startTime
|
|
328
|
+
|
|
329
|
+
expect(elapsed).toBeGreaterThanOrEqual(80)
|
|
330
|
+
expect(fetchCalls.length).toBe(2)
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
test('retries on 429 with Retry-After header', async () => {
|
|
334
|
+
mockResponse({ error: { message: 'Rate limited', code: 613 } }, 429, { 'Retry-After': '0.1' })
|
|
335
|
+
mockResponse({ verified_name: 'Test Business' })
|
|
336
|
+
|
|
337
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
338
|
+
const result = await client.verifyToken()
|
|
339
|
+
|
|
340
|
+
expect(result.verified_name).toBe('Test Business')
|
|
341
|
+
expect(fetchCalls.length).toBe(2)
|
|
342
|
+
})
|
|
343
|
+
|
|
344
|
+
test('throws after max retries exceeded', async () => {
|
|
345
|
+
for (let i = 0; i <= 3; i++) {
|
|
346
|
+
mockResponse({ error: { message: 'Rate limited', code: 613 } }, 429, { 'Retry-After': '0.01' })
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
350
|
+
await expect(client.verifyToken()).rejects.toThrow(WhatsAppBotError)
|
|
351
|
+
expect(fetchCalls.length).toBe(4)
|
|
352
|
+
})
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
describe('retry logic', () => {
|
|
356
|
+
test('retries on 500 server error for GET requests', async () => {
|
|
357
|
+
mockResponse({ error: { message: 'Internal Server Error' } }, 500)
|
|
358
|
+
mockResponse({ verified_name: 'Test Business' })
|
|
359
|
+
|
|
360
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
361
|
+
const result = await client.verifyToken()
|
|
362
|
+
|
|
363
|
+
expect(result.verified_name).toBe('Test Business')
|
|
364
|
+
expect(fetchCalls.length).toBe(2)
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
test('does not retry on 500 for POST requests', async () => {
|
|
368
|
+
mockResponse({ error: { message: 'Internal Server Error' } }, 500)
|
|
369
|
+
|
|
370
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
371
|
+
await expect(client.sendTextMessage('+15551234567', 'Hello')).rejects.toThrow(WhatsAppBotError)
|
|
372
|
+
expect(fetchCalls.length).toBe(1)
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
test('does not retry on 4xx client errors (except 429)', async () => {
|
|
376
|
+
mockResponse({ error: { message: 'Not Found', code: 100 } }, 404)
|
|
377
|
+
|
|
378
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
379
|
+
await expect(client.verifyToken()).rejects.toThrow(WhatsAppBotError)
|
|
380
|
+
expect(fetchCalls.length).toBe(1)
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
test('does not retry on 403 forbidden', async () => {
|
|
384
|
+
mockResponse({ error: { message: 'Forbidden', code: 200 } }, 403)
|
|
385
|
+
|
|
386
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
387
|
+
await expect(client.verifyToken()).rejects.toThrow(WhatsAppBotError)
|
|
388
|
+
expect(fetchCalls.length).toBe(1)
|
|
389
|
+
})
|
|
390
|
+
})
|
|
391
|
+
|
|
392
|
+
describe('request URL construction', () => {
|
|
393
|
+
test('all requests go to https://graph.facebook.com/v23.0/...', async () => {
|
|
394
|
+
mockResponse({ verified_name: 'Test' })
|
|
395
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'my-phone', accessToken: 'my-token' })
|
|
396
|
+
await client.verifyToken()
|
|
397
|
+
|
|
398
|
+
expect(fetchCalls[0].url.startsWith('https://graph.facebook.com/v23.0/')).toBe(true)
|
|
399
|
+
})
|
|
400
|
+
|
|
401
|
+
test('Authorization header is Bearer <token>', async () => {
|
|
402
|
+
mockResponse({ verified_name: 'Test' })
|
|
403
|
+
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-secret-token' })
|
|
404
|
+
await client.verifyToken()
|
|
405
|
+
|
|
406
|
+
expect(fetchCalls[0].options?.headers).toMatchObject({
|
|
407
|
+
Authorization: 'Bearer my-secret-token',
|
|
408
|
+
})
|
|
409
|
+
})
|
|
410
|
+
})
|
|
411
|
+
})
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import type { WhatsAppBotMessageResponse, WhatsAppBotTemplate } from './types'
|
|
2
|
+
import { WhatsAppBotError } from './types'
|
|
3
|
+
|
|
4
|
+
const BASE_URL = 'https://graph.facebook.com/v23.0'
|
|
5
|
+
const MAX_RETRIES = 3
|
|
6
|
+
const BASE_BACKOFF_MS = 100
|
|
7
|
+
|
|
8
|
+
export class WhatsAppBotClient {
|
|
9
|
+
private phoneNumberId: string | null = null
|
|
10
|
+
private accessToken: string | null = null
|
|
11
|
+
private rateLimitRemaining: number | null = null
|
|
12
|
+
private rateLimitResetAt: number = 0
|
|
13
|
+
|
|
14
|
+
async login(credentials?: { phoneNumberId: string; accessToken: string }): Promise<this> {
|
|
15
|
+
if (credentials) {
|
|
16
|
+
if (!credentials.phoneNumberId) {
|
|
17
|
+
throw new WhatsAppBotError('Phone number ID is required', 'missing_phone_number_id')
|
|
18
|
+
}
|
|
19
|
+
if (!credentials.accessToken) {
|
|
20
|
+
throw new WhatsAppBotError('Access token is required', 'missing_access_token')
|
|
21
|
+
}
|
|
22
|
+
this.phoneNumberId = credentials.phoneNumberId
|
|
23
|
+
this.accessToken = credentials.accessToken
|
|
24
|
+
return this
|
|
25
|
+
}
|
|
26
|
+
const { WhatsAppBotCredentialManager } = await import('./credential-manager')
|
|
27
|
+
const credManager = new WhatsAppBotCredentialManager()
|
|
28
|
+
const creds = await credManager.getCredentials()
|
|
29
|
+
if (!creds) {
|
|
30
|
+
throw new WhatsAppBotError(
|
|
31
|
+
'No WhatsApp Bot credentials found. Run "agent-whatsappbot auth set" first.',
|
|
32
|
+
'no_credentials',
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
return this.login({ phoneNumberId: creds.phone_number_id, accessToken: creds.access_token })
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private ensureAuth(): void {
|
|
39
|
+
if (this.phoneNumberId === null) {
|
|
40
|
+
throw new WhatsAppBotError('Not authenticated. Call .login() first.', 'not_authenticated')
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async verifyToken(): Promise<{ verified_name: string }> {
|
|
45
|
+
return this.request<{ verified_name: string }>('GET', `/${this.phoneNumberId!}?fields=verified_name`)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async sendTextMessage(to: string, text: string, previewUrl?: boolean): Promise<WhatsAppBotMessageResponse> {
|
|
49
|
+
return this.request<WhatsAppBotMessageResponse>('POST', `/${this.phoneNumberId!}/messages`, {
|
|
50
|
+
messaging_product: 'whatsapp',
|
|
51
|
+
to,
|
|
52
|
+
type: 'text',
|
|
53
|
+
text: { body: text, preview_url: previewUrl ?? false },
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async sendTemplateMessage(
|
|
58
|
+
to: string,
|
|
59
|
+
templateName: string,
|
|
60
|
+
languageCode: string,
|
|
61
|
+
components?: unknown[],
|
|
62
|
+
): Promise<WhatsAppBotMessageResponse> {
|
|
63
|
+
return this.request<WhatsAppBotMessageResponse>('POST', `/${this.phoneNumberId}/messages`, {
|
|
64
|
+
messaging_product: 'whatsapp',
|
|
65
|
+
to,
|
|
66
|
+
type: 'template',
|
|
67
|
+
template: { name: templateName, language: { code: languageCode }, components },
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async sendReaction(to: string, messageId: string, emoji: string): Promise<WhatsAppBotMessageResponse> {
|
|
72
|
+
return this.request<WhatsAppBotMessageResponse>('POST', `/${this.phoneNumberId}/messages`, {
|
|
73
|
+
messaging_product: 'whatsapp',
|
|
74
|
+
to,
|
|
75
|
+
type: 'reaction',
|
|
76
|
+
reaction: { message_id: messageId, emoji },
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async sendImageMessage(to: string, imageUrl: string, caption?: string): Promise<WhatsAppBotMessageResponse> {
|
|
81
|
+
return this.request<WhatsAppBotMessageResponse>('POST', `/${this.phoneNumberId}/messages`, {
|
|
82
|
+
messaging_product: 'whatsapp',
|
|
83
|
+
to,
|
|
84
|
+
type: 'image',
|
|
85
|
+
image: { link: imageUrl, caption },
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async sendDocumentMessage(
|
|
90
|
+
to: string,
|
|
91
|
+
documentUrl: string,
|
|
92
|
+
filename?: string,
|
|
93
|
+
caption?: string,
|
|
94
|
+
): Promise<WhatsAppBotMessageResponse> {
|
|
95
|
+
return this.request<WhatsAppBotMessageResponse>('POST', `/${this.phoneNumberId}/messages`, {
|
|
96
|
+
messaging_product: 'whatsapp',
|
|
97
|
+
to,
|
|
98
|
+
type: 'document',
|
|
99
|
+
document: { link: documentUrl, filename, caption },
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async listTemplates(params?: { limit?: number }): Promise<WhatsAppBotTemplate[]> {
|
|
104
|
+
return this.request<WhatsAppBotTemplate[]>('GET', this.buildPath(`/${this.phoneNumberId}/message_templates`, params), undefined, 'data')
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async getTemplate(templateName: string): Promise<WhatsAppBotTemplate> {
|
|
108
|
+
const templates = await this.request<WhatsAppBotTemplate[]>(
|
|
109
|
+
'GET',
|
|
110
|
+
`/${this.phoneNumberId}/message_templates?name=${encodeURIComponent(templateName)}`,
|
|
111
|
+
undefined,
|
|
112
|
+
'data',
|
|
113
|
+
)
|
|
114
|
+
const template = templates[0]
|
|
115
|
+
if (!template) {
|
|
116
|
+
throw new WhatsAppBotError(`Template "${templateName}" not found`, 'not_found')
|
|
117
|
+
}
|
|
118
|
+
return template
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private getHeaders(): Record<string, string> {
|
|
122
|
+
return {
|
|
123
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
124
|
+
'Content-Type': 'application/json',
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private async waitForRateLimit(): Promise<void> {
|
|
129
|
+
const now = Date.now()
|
|
130
|
+
if (this.rateLimitRemaining === 0 && this.rateLimitResetAt > now) {
|
|
131
|
+
await this.sleep(this.rateLimitResetAt - now)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private updateRateLimit(response: Response): void {
|
|
136
|
+
const usageHeader = response.headers.get('x-business-use-case-usage')
|
|
137
|
+
if (usageHeader) {
|
|
138
|
+
try {
|
|
139
|
+
const usage = JSON.parse(usageHeader) as Record<string, Array<{ call_count: number; total_cputime: number; total_time: number; type: string; estimated_time_to_regain_access: number }>>
|
|
140
|
+
for (const entries of Object.values(usage)) {
|
|
141
|
+
for (const entry of entries) {
|
|
142
|
+
if (entry.call_count >= 100) {
|
|
143
|
+
this.rateLimitRemaining = 0
|
|
144
|
+
this.rateLimitResetAt = Date.now() + (entry.estimated_time_to_regain_access ?? 60) * 1000
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
} catch {
|
|
149
|
+
// ignore parse errors
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private async request<T>(method: string, path: string, body?: unknown, unwrapKey?: string): Promise<T> {
|
|
155
|
+
this.ensureAuth()
|
|
156
|
+
const url = `${BASE_URL}${path}`
|
|
157
|
+
let lastError: Error | undefined
|
|
158
|
+
|
|
159
|
+
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
160
|
+
await this.waitForRateLimit()
|
|
161
|
+
|
|
162
|
+
const options: RequestInit = {
|
|
163
|
+
method,
|
|
164
|
+
headers: this.getHeaders(),
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (body !== undefined) {
|
|
168
|
+
options.body = JSON.stringify(body)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
let response: Response
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
response = await fetch(url, options)
|
|
175
|
+
} catch (error) {
|
|
176
|
+
lastError = error instanceof Error ? error : new Error(String(error))
|
|
177
|
+
if (attempt < MAX_RETRIES && method === 'GET') {
|
|
178
|
+
await this.sleep(BASE_BACKOFF_MS * 2 ** attempt)
|
|
179
|
+
continue
|
|
180
|
+
}
|
|
181
|
+
throw new WhatsAppBotError(`Network error: ${lastError.message}`, 'network_error')
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
this.updateRateLimit(response)
|
|
185
|
+
|
|
186
|
+
if (response.status === 429) {
|
|
187
|
+
if (attempt < MAX_RETRIES) {
|
|
188
|
+
const retryAfter = Number.parseFloat(response.headers.get('Retry-After') || '1')
|
|
189
|
+
const retryAfterMs = (Number.isNaN(retryAfter) ? 1 : retryAfter) * 1000
|
|
190
|
+
await this.sleep(retryAfterMs)
|
|
191
|
+
continue
|
|
192
|
+
}
|
|
193
|
+
throw new WhatsAppBotError('Rate limited', 'rate_limited')
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (response.status >= 500 && response.status <= 599) {
|
|
197
|
+
if (attempt < MAX_RETRIES && method === 'GET') {
|
|
198
|
+
await this.sleep(BASE_BACKOFF_MS * 2 ** attempt)
|
|
199
|
+
continue
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const errorBody = await response.json().catch(() => ({})) as {
|
|
203
|
+
error?: { message?: string; code?: number }
|
|
204
|
+
}
|
|
205
|
+
const msg = errorBody.error?.message || `HTTP ${response.status}`
|
|
206
|
+
const code = errorBody.error?.code ? String(errorBody.error.code) : `http_${response.status}`
|
|
207
|
+
throw new WhatsAppBotError(msg, code)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (!response.ok) {
|
|
211
|
+
const errorBody = await response.json().catch(() => ({})) as {
|
|
212
|
+
error?: { message?: string; code?: number }
|
|
213
|
+
}
|
|
214
|
+
const msg = errorBody.error?.message || `HTTP ${response.status}`
|
|
215
|
+
const code = errorBody.error?.code ? String(errorBody.error.code) : `http_${response.status}`
|
|
216
|
+
throw new WhatsAppBotError(msg, code)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (response.status === 204) {
|
|
220
|
+
return undefined as T
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const data = await response.json()
|
|
224
|
+
if (unwrapKey && data != null && typeof data === 'object' && unwrapKey in data) {
|
|
225
|
+
return (data as Record<string, unknown>)[unwrapKey] as T
|
|
226
|
+
}
|
|
227
|
+
return data as T
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
throw lastError || new WhatsAppBotError('Request failed after retries', 'max_retries')
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private buildPath(path: string, params?: Record<string, string | number | undefined>): string {
|
|
234
|
+
if (!params) {
|
|
235
|
+
return path
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const searchParams = new URLSearchParams()
|
|
239
|
+
for (const [key, value] of Object.entries(params)) {
|
|
240
|
+
if (value !== undefined) {
|
|
241
|
+
searchParams.set(key, String(value))
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const query = searchParams.toString()
|
|
246
|
+
if (!query) {
|
|
247
|
+
return path
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return `${path}?${query}`
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
private sleep(ms: number): Promise<void> {
|
|
254
|
+
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
255
|
+
}
|
|
256
|
+
}
|