agent-messenger 2.10.1 → 2.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/dist/package.json +1 -1
- package/dist/src/platforms/teams/token-extractor.d.ts.map +1 -1
- package/dist/src/platforms/teams/token-extractor.js +9 -2
- package/dist/src/platforms/teams/token-extractor.js.map +1 -1
- package/dist/src/shared/chromium/decryptor.d.ts +6 -0
- package/dist/src/shared/chromium/decryptor.d.ts.map +1 -1
- package/dist/src/shared/chromium/decryptor.js +26 -6
- package/dist/src/shared/chromium/decryptor.js.map +1 -1
- package/e2e/channeltalk.e2e.test.ts +13 -13
- package/e2e/channeltalkbot.e2e.test.ts +13 -13
- package/e2e/discord.e2e.test.ts +24 -24
- package/e2e/discordbot.e2e.test.ts +16 -16
- package/e2e/instagram.e2e.test.ts +10 -10
- package/e2e/kakaotalk.e2e.test.ts +7 -7
- package/e2e/line.e2e.test.ts +8 -8
- package/e2e/slack.e2e.test.ts +34 -34
- package/e2e/slackbot.e2e.test.ts +14 -14
- package/e2e/teams.e2e.test.ts +23 -23
- package/e2e/telegram.e2e.test.ts +8 -8
- package/e2e/webex.e2e.test.ts +14 -14
- package/e2e/whatsapp.e2e.test.ts +8 -8
- package/e2e/whatsappbot.e2e.test.ts +6 -6
- package/package.json +1 -1
- package/skills/agent-channeltalk/SKILL.md +1 -1
- package/skills/agent-channeltalkbot/SKILL.md +1 -1
- package/skills/agent-discord/SKILL.md +1 -1
- package/skills/agent-discordbot/SKILL.md +1 -1
- package/skills/agent-instagram/SKILL.md +1 -1
- package/skills/agent-kakaotalk/SKILL.md +1 -1
- package/skills/agent-line/SKILL.md +1 -1
- package/skills/agent-slack/SKILL.md +1 -1
- package/skills/agent-slackbot/SKILL.md +1 -1
- package/skills/agent-teams/SKILL.md +1 -1
- package/skills/agent-telegram/SKILL.md +1 -1
- package/skills/agent-webex/SKILL.md +1 -1
- package/skills/agent-wechatbot/SKILL.md +1 -1
- package/skills/agent-whatsapp/SKILL.md +1 -1
- package/skills/agent-whatsappbot/SKILL.md +1 -1
- package/src/platforms/channeltalk/client.test.ts +26 -26
- package/src/platforms/channeltalk/commands/auth.test.ts +16 -16
- package/src/platforms/channeltalk/commands/bot.test.ts +2 -2
- package/src/platforms/channeltalk/commands/chat.test.ts +3 -3
- package/src/platforms/channeltalk/commands/group.test.ts +4 -4
- package/src/platforms/channeltalk/commands/manager.test.ts +2 -2
- package/src/platforms/channeltalk/commands/message.test.ts +17 -17
- package/src/platforms/channeltalk/commands/snapshot.test.ts +7 -7
- package/src/platforms/channeltalk/commands/whoami.test.ts +3 -3
- package/src/platforms/channeltalk/credential-manager.test.ts +18 -18
- package/src/platforms/channeltalk/ensure-auth.test.ts +5 -5
- package/src/platforms/channeltalk/index.test.ts +23 -23
- package/src/platforms/channeltalk/token-extractor.test.ts +21 -21
- package/src/platforms/channeltalk/types.test.ts +12 -12
- package/src/platforms/channeltalkbot/client.test.ts +14 -14
- package/src/platforms/channeltalkbot/commands/auth.test.ts +16 -16
- package/src/platforms/channeltalkbot/commands/bot.test.ts +6 -6
- package/src/platforms/channeltalkbot/commands/chat.test.ts +9 -9
- package/src/platforms/channeltalkbot/commands/group.test.ts +6 -6
- package/src/platforms/channeltalkbot/commands/manager.test.ts +3 -3
- package/src/platforms/channeltalkbot/commands/message.test.ts +10 -10
- package/src/platforms/channeltalkbot/commands/snapshot.test.ts +7 -7
- package/src/platforms/channeltalkbot/commands/whoami.test.ts +4 -4
- package/src/platforms/channeltalkbot/credential-manager.test.ts +27 -27
- package/src/platforms/channeltalkbot/index.test.ts +15 -15
- package/src/platforms/discord/client.test.ts +28 -28
- package/src/platforms/discord/commands/auth.test.ts +7 -7
- package/src/platforms/discord/commands/channel.test.ts +7 -7
- package/src/platforms/discord/commands/dm.test.ts +4 -4
- package/src/platforms/discord/commands/file.test.ts +4 -4
- package/src/platforms/discord/commands/friend.test.ts +6 -6
- package/src/platforms/discord/commands/member.test.ts +5 -5
- package/src/platforms/discord/commands/mention.test.ts +5 -5
- package/src/platforms/discord/commands/message.test.ts +9 -9
- package/src/platforms/discord/commands/note.test.ts +6 -6
- package/src/platforms/discord/commands/profile.test.ts +4 -4
- package/src/platforms/discord/commands/reaction.test.ts +5 -5
- package/src/platforms/discord/commands/server.test.ts +7 -7
- package/src/platforms/discord/commands/snapshot.test.ts +6 -6
- package/src/platforms/discord/commands/thread.test.ts +6 -6
- package/src/platforms/discord/commands/user.test.ts +5 -5
- package/src/platforms/discord/commands/whoami.test.ts +6 -6
- package/src/platforms/discord/credential-manager.test.ts +16 -16
- package/src/platforms/discord/ensure-auth.test.ts +8 -8
- package/src/platforms/discord/index.test.ts +17 -17
- package/src/platforms/discord/listener.test.ts +33 -33
- package/src/platforms/discord/token-extractor.test.ts +53 -53
- package/src/platforms/discord/types.test.ts +26 -26
- package/src/platforms/discordbot/client.test.ts +31 -31
- package/src/platforms/discordbot/commands/auth.test.ts +18 -18
- package/src/platforms/discordbot/commands/channel.test.ts +11 -11
- package/src/platforms/discordbot/commands/file.test.ts +7 -7
- package/src/platforms/discordbot/commands/message.test.ts +25 -25
- package/src/platforms/discordbot/commands/reaction.test.ts +6 -6
- package/src/platforms/discordbot/commands/server.test.ts +12 -12
- package/src/platforms/discordbot/commands/snapshot.test.ts +13 -13
- package/src/platforms/discordbot/commands/thread.test.ts +10 -10
- package/src/platforms/discordbot/commands/user.test.ts +9 -9
- package/src/platforms/discordbot/commands/whoami.test.ts +4 -4
- package/src/platforms/discordbot/credential-manager.test.ts +28 -28
- package/src/platforms/instagram/client.test.ts +18 -18
- package/src/platforms/instagram/commands/auth.test.ts +11 -11
- package/src/platforms/instagram/commands/chat.test.ts +6 -6
- package/src/platforms/instagram/commands/message.test.ts +11 -11
- package/src/platforms/instagram/commands/shared.test.ts +12 -12
- package/src/platforms/instagram/commands/whoami.test.ts +3 -3
- package/src/platforms/instagram/credential-manager.test.ts +21 -21
- package/src/platforms/instagram/ensure-auth.test.ts +4 -4
- package/src/platforms/instagram/index.test.ts +9 -9
- package/src/platforms/instagram/listener.test.ts +8 -8
- package/src/platforms/instagram/token-extractor.test.ts +35 -35
- package/src/platforms/kakaotalk/client.test.ts +33 -33
- package/src/platforms/kakaotalk/commands/auth.test.ts +11 -11
- package/src/platforms/kakaotalk/commands/chat.test.ts +6 -6
- package/src/platforms/kakaotalk/commands/message.test.ts +7 -7
- package/src/platforms/kakaotalk/commands/whoami.test.ts +5 -5
- package/src/platforms/kakaotalk/credential-manager.test.ts +15 -15
- package/src/platforms/kakaotalk/index.test.ts +15 -15
- package/src/platforms/kakaotalk/listener.test.ts +17 -17
- package/src/platforms/line/client.test.ts +17 -17
- package/src/platforms/line/commands/auth.test.ts +8 -8
- package/src/platforms/line/commands/chat.test.ts +7 -7
- package/src/platforms/line/commands/friend.test.ts +6 -6
- package/src/platforms/line/commands/message.test.ts +7 -7
- package/src/platforms/line/commands/whoami.test.ts +6 -6
- package/src/platforms/line/credential-manager.test.ts +17 -17
- package/src/platforms/line/index.test.ts +10 -10
- package/src/platforms/line/listener.test.ts +15 -15
- package/src/platforms/line/types.test.ts +14 -14
- package/src/platforms/slack/cli.test.ts +8 -8
- package/src/platforms/slack/client.test.ts +151 -151
- package/src/platforms/slack/commands/activity.test.ts +13 -13
- package/src/platforms/slack/commands/auth.test.ts +34 -34
- package/src/platforms/slack/commands/bookmark.test.ts +9 -9
- package/src/platforms/slack/commands/channel.test.ts +17 -17
- package/src/platforms/slack/commands/drafts.test.ts +7 -7
- package/src/platforms/slack/commands/emoji.test.ts +3 -3
- package/src/platforms/slack/commands/file.test.ts +12 -12
- package/src/platforms/slack/commands/message.test.ts +19 -19
- package/src/platforms/slack/commands/pin.test.ts +7 -7
- package/src/platforms/slack/commands/reaction.test.ts +10 -10
- package/src/platforms/slack/commands/reminder.test.ts +9 -9
- package/src/platforms/slack/commands/saved.test.ts +7 -7
- package/src/platforms/slack/commands/sections.test.ts +5 -5
- package/src/platforms/slack/commands/snapshot.test.ts +13 -13
- package/src/platforms/slack/commands/unread.test.ts +6 -6
- package/src/platforms/slack/commands/user.test.ts +10 -10
- package/src/platforms/slack/commands/usergroup.test.ts +15 -15
- package/src/platforms/slack/commands/whoami.test.ts +6 -6
- package/src/platforms/slack/commands/workspace.test.ts +26 -26
- package/src/platforms/slack/credential-manager.test.ts +14 -14
- package/src/platforms/slack/ensure-auth.test.ts +21 -21
- package/src/platforms/slack/index.test.ts +12 -12
- package/src/platforms/slack/listener.test.ts +17 -17
- package/src/platforms/slack/token-extractor-node.test.ts +2 -2
- package/src/platforms/slack/token-extractor.test.ts +37 -37
- package/src/platforms/slack/types.test.ts +21 -21
- package/src/platforms/slackbot/client.test.ts +22 -22
- package/src/platforms/slackbot/commands/auth.test.ts +14 -14
- package/src/platforms/slackbot/commands/channel.test.ts +7 -7
- package/src/platforms/slackbot/commands/message.test.ts +13 -13
- package/src/platforms/slackbot/commands/reaction.test.ts +6 -6
- package/src/platforms/slackbot/commands/user.test.ts +7 -7
- package/src/platforms/slackbot/commands/whoami.test.ts +4 -4
- package/src/platforms/slackbot/credential-manager.test.ts +22 -22
- package/src/platforms/slackbot/types.test.ts +7 -7
- package/src/platforms/teams/client.test.ts +30 -30
- package/src/platforms/teams/commands/auth.test.ts +8 -8
- package/src/platforms/teams/commands/channel.test.ts +7 -7
- package/src/platforms/teams/commands/file.test.ts +4 -4
- package/src/platforms/teams/commands/message.test.ts +5 -5
- package/src/platforms/teams/commands/reaction.test.ts +4 -4
- package/src/platforms/teams/commands/snapshot.test.ts +7 -7
- package/src/platforms/teams/commands/team.test.ts +8 -8
- package/src/platforms/teams/commands/user.test.ts +4 -4
- package/src/platforms/teams/commands/whoami.test.ts +6 -6
- package/src/platforms/teams/credential-manager.test.ts +17 -17
- package/src/platforms/teams/ensure-auth.test.ts +13 -13
- package/src/platforms/teams/index.test.ts +15 -15
- package/src/platforms/teams/token-extractor.test.ts +109 -49
- package/src/platforms/teams/token-extractor.ts +7 -2
- package/src/platforms/teams/types.test.ts +26 -26
- package/src/platforms/telegram/app-config.test.ts +4 -4
- package/src/platforms/telegram/chat-utils.test.ts +12 -12
- package/src/platforms/telegram/client.test.ts +4 -4
- package/src/platforms/telegram/commands/auth.test.ts +16 -16
- package/src/platforms/telegram/commands/chat.test.ts +9 -9
- package/src/platforms/telegram/commands/message.test.ts +6 -6
- package/src/platforms/telegram/commands/shared.test.ts +3 -3
- package/src/platforms/telegram/commands/whoami.test.ts +3 -3
- package/src/platforms/telegram/credential-manager.test.ts +10 -10
- package/src/platforms/telegram/types.test.ts +6 -6
- package/src/platforms/webex/app-config.test.ts +8 -8
- package/src/platforms/webex/cli.test.ts +5 -5
- package/src/platforms/webex/client.test.ts +65 -65
- package/src/platforms/webex/commands/auth.test.ts +18 -18
- package/src/platforms/webex/commands/member.test.ts +5 -5
- package/src/platforms/webex/commands/message.test.ts +12 -12
- package/src/platforms/webex/commands/snapshot.test.ts +5 -5
- package/src/platforms/webex/commands/space.test.ts +10 -10
- package/src/platforms/webex/commands/whoami.test.ts +6 -6
- package/src/platforms/webex/credential-manager.test.ts +22 -22
- package/src/platforms/webex/encryption.test.ts +4 -4
- package/src/platforms/webex/ensure-auth.test.ts +5 -5
- package/src/platforms/webex/index.test.ts +5 -5
- package/src/platforms/webex/markdown-to-html.test.ts +33 -33
- package/src/platforms/webex/token-extractor.test.ts +23 -23
- package/src/platforms/webex/types.test.ts +27 -27
- package/src/platforms/wechatbot/client.test.ts +27 -27
- package/src/platforms/wechatbot/commands/auth.test.ts +15 -15
- package/src/platforms/wechatbot/commands/message.test.ts +8 -8
- package/src/platforms/wechatbot/commands/template.test.ts +9 -9
- package/src/platforms/wechatbot/commands/user.test.ts +7 -7
- package/src/platforms/wechatbot/commands/whoami.test.ts +5 -5
- package/src/platforms/wechatbot/credential-manager.test.ts +18 -18
- package/src/platforms/wechatbot/index.test.ts +10 -10
- package/src/platforms/wechatbot/types.test.ts +25 -25
- package/src/platforms/whatsapp/commands/auth.test.ts +13 -13
- package/src/platforms/whatsapp/commands/chat.test.ts +8 -8
- package/src/platforms/whatsapp/commands/message.test.ts +10 -10
- package/src/platforms/whatsapp/commands/whoami.test.ts +3 -3
- package/src/platforms/whatsapp/credential-manager.test.ts +23 -23
- package/src/platforms/whatsapp/ensure-auth.test.ts +4 -4
- package/src/platforms/whatsapp/index.test.ts +8 -8
- package/src/platforms/whatsapp/types.test.ts +42 -42
- package/src/platforms/whatsappbot/client.test.ts +27 -27
- package/src/platforms/whatsappbot/commands/auth.test.ts +14 -14
- package/src/platforms/whatsappbot/commands/message.test.ts +16 -16
- package/src/platforms/whatsappbot/commands/template.test.ts +9 -9
- package/src/platforms/whatsappbot/commands/whoami.test.ts +5 -5
- package/src/platforms/whatsappbot/credential-manager.test.ts +18 -18
- package/src/platforms/whatsappbot/index.test.ts +7 -7
- package/src/platforms/whatsappbot/types.test.ts +18 -18
- package/src/shared/chromium/browsers.test.ts +22 -22
- package/src/shared/chromium/cookie-reader.test.ts +13 -13
- package/src/shared/chromium/decryptor.test.ts +97 -32
- package/src/shared/chromium/decryptor.ts +27 -6
- package/src/shared/utils/concurrency.test.ts +6 -6
- package/src/shared/utils/derived-key-cache.test.ts +11 -11
- package/src/tui/utils.test.ts +31 -31
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, expect,
|
|
1
|
+
import { describe, expect, it } from 'bun:test'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
createAccountId,
|
|
@@ -9,182 +9,182 @@ import {
|
|
|
9
9
|
} from '@/platforms/whatsapp/types'
|
|
10
10
|
|
|
11
11
|
describe('WhatsAppError', () => {
|
|
12
|
-
|
|
12
|
+
it('has name WhatsAppError', () => {
|
|
13
13
|
const err = new WhatsAppError('test message')
|
|
14
14
|
expect(err.name).toBe('WhatsAppError')
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
it('sets message correctly', () => {
|
|
18
18
|
const err = new WhatsAppError('something went wrong')
|
|
19
19
|
expect(err.message).toBe('something went wrong')
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
it('defaults code to whatsapp_error', () => {
|
|
23
23
|
const err = new WhatsAppError('test')
|
|
24
24
|
expect(err.code).toBe('whatsapp_error')
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
it('preserves custom string code', () => {
|
|
28
28
|
const err = new WhatsAppError('test', 'auth_failed')
|
|
29
29
|
expect(err.code).toBe('auth_failed')
|
|
30
30
|
})
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
it('preserves numeric code', () => {
|
|
33
33
|
const err = new WhatsAppError('test', 404)
|
|
34
34
|
expect(err.code).toBe(404)
|
|
35
35
|
})
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
it('is instanceof Error', () => {
|
|
38
38
|
const err = new WhatsAppError('test')
|
|
39
39
|
expect(err instanceof Error).toBe(true)
|
|
40
40
|
})
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
it('is instanceof WhatsAppError', () => {
|
|
43
43
|
const err = new WhatsAppError('test')
|
|
44
44
|
expect(err instanceof WhatsAppError).toBe(true)
|
|
45
45
|
})
|
|
46
46
|
})
|
|
47
47
|
|
|
48
48
|
describe('createAccountId', () => {
|
|
49
|
-
|
|
49
|
+
it('converts phone with leading + to plus- prefix', () => {
|
|
50
50
|
expect(createAccountId('+12025551234')).toBe('plus-12025551234')
|
|
51
51
|
})
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
it('trims and lowercases with spaces becoming dashes', () => {
|
|
54
54
|
expect(createAccountId(' My Account ')).toBe('my-account')
|
|
55
55
|
})
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
it('replaces special chars like @ with dashes', () => {
|
|
58
58
|
expect(createAccountId('hello@world')).toBe('hello-world')
|
|
59
59
|
})
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
it('returns default for empty string', () => {
|
|
62
62
|
expect(createAccountId('')).toBe('default')
|
|
63
63
|
})
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
it('returns default for whitespace-only string', () => {
|
|
66
66
|
expect(createAccountId(' ')).toBe('default')
|
|
67
67
|
})
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
it('returns already normalized input unchanged', () => {
|
|
70
70
|
expect(createAccountId('my-account')).toBe('my-account')
|
|
71
71
|
})
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
it('collapses multiple special chars into single dash', () => {
|
|
74
74
|
expect(createAccountId('foo!!bar')).toBe('foo-bar')
|
|
75
75
|
})
|
|
76
76
|
})
|
|
77
77
|
|
|
78
78
|
describe('jidToType', () => {
|
|
79
|
-
|
|
79
|
+
it('returns individual for individual JID', () => {
|
|
80
80
|
expect(jidToType('1234@s.whatsapp.net')).toBe('individual')
|
|
81
81
|
})
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
it('returns group for group JID', () => {
|
|
84
84
|
expect(jidToType('1234-5678@g.us')).toBe('group')
|
|
85
85
|
})
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
it('returns status for status@broadcast JID', () => {
|
|
88
88
|
expect(jidToType('status@broadcast')).toBe('status')
|
|
89
89
|
})
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
it('returns broadcast for other @broadcast JID', () => {
|
|
92
92
|
expect(jidToType('1234@broadcast')).toBe('broadcast')
|
|
93
93
|
})
|
|
94
94
|
})
|
|
95
95
|
|
|
96
96
|
describe('extractMessageText', () => {
|
|
97
|
-
|
|
97
|
+
it('returns undefined for null', () => {
|
|
98
98
|
expect(extractMessageText(null)).toBeUndefined()
|
|
99
99
|
})
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
it('returns undefined for undefined input', () => {
|
|
102
102
|
expect(extractMessageText(undefined)).toBeUndefined()
|
|
103
103
|
})
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
it('returns conversation text for conversation message', () => {
|
|
106
106
|
expect(extractMessageText({ conversation: 'hello' })).toBe('hello')
|
|
107
107
|
})
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
it('returns text for extendedTextMessage', () => {
|
|
110
110
|
expect(extractMessageText({ extendedTextMessage: { text: 'hello' } })).toBe('hello')
|
|
111
111
|
})
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
it('returns caption for imageMessage', () => {
|
|
114
114
|
expect(extractMessageText({ imageMessage: { caption: 'photo' } })).toBe('photo')
|
|
115
115
|
})
|
|
116
116
|
|
|
117
|
-
|
|
117
|
+
it('returns caption for videoMessage', () => {
|
|
118
118
|
expect(extractMessageText({ videoMessage: { caption: 'vid' } })).toBe('vid')
|
|
119
119
|
})
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
it('returns text for reactionMessage', () => {
|
|
122
122
|
expect(extractMessageText({ reactionMessage: { text: '👍' } })).toBe('👍')
|
|
123
123
|
})
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
it('returns undefined for empty message', () => {
|
|
126
126
|
expect(extractMessageText({})).toBeUndefined()
|
|
127
127
|
})
|
|
128
128
|
})
|
|
129
129
|
|
|
130
130
|
describe('getMessageType', () => {
|
|
131
|
-
|
|
131
|
+
it('returns unknown for null', () => {
|
|
132
132
|
expect(getMessageType(null)).toBe('unknown')
|
|
133
133
|
})
|
|
134
134
|
|
|
135
|
-
|
|
135
|
+
it('returns unknown for undefined input', () => {
|
|
136
136
|
expect(getMessageType(undefined)).toBe('unknown')
|
|
137
137
|
})
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
it('returns text for conversation message', () => {
|
|
140
140
|
expect(getMessageType({ conversation: 'hi' })).toBe('text')
|
|
141
141
|
})
|
|
142
142
|
|
|
143
|
-
|
|
143
|
+
it('returns text for extendedTextMessage', () => {
|
|
144
144
|
expect(getMessageType({ extendedTextMessage: { text: 'hi' } })).toBe('text')
|
|
145
145
|
})
|
|
146
146
|
|
|
147
|
-
|
|
147
|
+
it('returns image for imageMessage', () => {
|
|
148
148
|
expect(getMessageType({ imageMessage: {} })).toBe('image')
|
|
149
149
|
})
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
it('returns video for videoMessage', () => {
|
|
152
152
|
expect(getMessageType({ videoMessage: {} })).toBe('video')
|
|
153
153
|
})
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
it('returns gif for videoMessage with gifPlayback', () => {
|
|
156
156
|
expect(getMessageType({ videoMessage: { gifPlayback: true } })).toBe('gif')
|
|
157
157
|
})
|
|
158
158
|
|
|
159
|
-
|
|
159
|
+
it('returns audio for audioMessage', () => {
|
|
160
160
|
expect(getMessageType({ audioMessage: {} })).toBe('audio')
|
|
161
161
|
})
|
|
162
162
|
|
|
163
|
-
|
|
163
|
+
it('returns document for documentMessage', () => {
|
|
164
164
|
expect(getMessageType({ documentMessage: {} })).toBe('document')
|
|
165
165
|
})
|
|
166
166
|
|
|
167
|
-
|
|
167
|
+
it('returns sticker for stickerMessage', () => {
|
|
168
168
|
expect(getMessageType({ stickerMessage: {} })).toBe('sticker')
|
|
169
169
|
})
|
|
170
170
|
|
|
171
|
-
|
|
171
|
+
it('returns location for locationMessage', () => {
|
|
172
172
|
expect(getMessageType({ locationMessage: {} })).toBe('location')
|
|
173
173
|
})
|
|
174
174
|
|
|
175
|
-
|
|
175
|
+
it('returns contact for contactMessage', () => {
|
|
176
176
|
expect(getMessageType({ contactMessage: {} })).toBe('contact')
|
|
177
177
|
})
|
|
178
178
|
|
|
179
|
-
|
|
179
|
+
it('returns reaction for reactionMessage', () => {
|
|
180
180
|
expect(getMessageType({ reactionMessage: {} })).toBe('reaction')
|
|
181
181
|
})
|
|
182
182
|
|
|
183
|
-
|
|
183
|
+
it('returns poll for pollCreationMessage', () => {
|
|
184
184
|
expect(getMessageType({ pollCreationMessage: {} })).toBe('poll')
|
|
185
185
|
})
|
|
186
186
|
|
|
187
|
-
|
|
187
|
+
it('returns unknown for empty object', () => {
|
|
188
188
|
expect(getMessageType({})).toBe('unknown')
|
|
189
189
|
})
|
|
190
190
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect,
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from 'bun:test'
|
|
2
2
|
|
|
3
3
|
import { WhatsAppBotClient } from '@/platforms/whatsappbot/client'
|
|
4
4
|
import { WhatsAppBotError } from '@/platforms/whatsappbot/types'
|
|
@@ -50,7 +50,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
describe('login', () => {
|
|
53
|
-
|
|
53
|
+
it('throws on empty phoneNumberId', async () => {
|
|
54
54
|
await expect(new WhatsAppBotClient().login({ phoneNumberId: '', accessToken: 'access-token' })).rejects.toThrow(
|
|
55
55
|
WhatsAppBotError,
|
|
56
56
|
)
|
|
@@ -59,7 +59,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
59
59
|
)
|
|
60
60
|
})
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
it('throws on empty accessToken', async () => {
|
|
63
63
|
await expect(new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: '' })).rejects.toThrow(
|
|
64
64
|
WhatsAppBotError,
|
|
65
65
|
)
|
|
@@ -68,14 +68,14 @@ describe('WhatsAppBotClient', () => {
|
|
|
68
68
|
)
|
|
69
69
|
})
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
it('accepts valid phoneNumberId and accessToken', async () => {
|
|
72
72
|
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'access-token' })
|
|
73
73
|
expect(client).toBeInstanceOf(WhatsAppBotClient)
|
|
74
74
|
})
|
|
75
75
|
})
|
|
76
76
|
|
|
77
77
|
describe('verifyToken', () => {
|
|
78
|
-
|
|
78
|
+
it('sends GET request with correct URL and auth header', async () => {
|
|
79
79
|
mockResponse({ verified_name: 'Test Business' })
|
|
80
80
|
|
|
81
81
|
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
@@ -89,7 +89,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
89
89
|
})
|
|
90
90
|
})
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
it('throws WhatsAppBotError on API error', async () => {
|
|
93
93
|
mockResponse({ error: { message: 'Invalid token', code: 190 } }, 401)
|
|
94
94
|
|
|
95
95
|
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'bad-token' })
|
|
@@ -98,7 +98,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
98
98
|
})
|
|
99
99
|
|
|
100
100
|
describe('sendTextMessage', () => {
|
|
101
|
-
|
|
101
|
+
it('sends POST request with correct body shape', async () => {
|
|
102
102
|
mockResponse({
|
|
103
103
|
messaging_product: 'whatsapp',
|
|
104
104
|
contacts: [{ input: '+15551234567', wa_id: '15551234567' }],
|
|
@@ -121,7 +121,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
121
121
|
})
|
|
122
122
|
})
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
it('sends correct Authorization header', async () => {
|
|
125
125
|
mockResponse({
|
|
126
126
|
messaging_product: 'whatsapp',
|
|
127
127
|
contacts: [],
|
|
@@ -136,7 +136,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
136
136
|
})
|
|
137
137
|
})
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
it('returns WhatsAppBotMessageResponse', async () => {
|
|
140
140
|
mockResponse({
|
|
141
141
|
messaging_product: 'whatsapp',
|
|
142
142
|
contacts: [{ input: '+15551234567', wa_id: '15551234567' }],
|
|
@@ -153,7 +153,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
153
153
|
})
|
|
154
154
|
|
|
155
155
|
describe('sendTemplateMessage', () => {
|
|
156
|
-
|
|
156
|
+
it('sends POST with template payload', async () => {
|
|
157
157
|
mockResponse({
|
|
158
158
|
messaging_product: 'whatsapp',
|
|
159
159
|
contacts: [{ input: '+15551234567', wa_id: '15551234567' }],
|
|
@@ -172,7 +172,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
172
172
|
})
|
|
173
173
|
})
|
|
174
174
|
|
|
175
|
-
|
|
175
|
+
it('includes components when provided', async () => {
|
|
176
176
|
mockResponse({
|
|
177
177
|
messaging_product: 'whatsapp',
|
|
178
178
|
contacts: [],
|
|
@@ -189,7 +189,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
189
189
|
})
|
|
190
190
|
|
|
191
191
|
describe('sendReaction', () => {
|
|
192
|
-
|
|
192
|
+
it('sends POST with reaction payload', async () => {
|
|
193
193
|
mockResponse({
|
|
194
194
|
messaging_product: 'whatsapp',
|
|
195
195
|
contacts: [],
|
|
@@ -210,7 +210,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
210
210
|
})
|
|
211
211
|
|
|
212
212
|
describe('sendImageMessage', () => {
|
|
213
|
-
|
|
213
|
+
it('sends POST with image payload', async () => {
|
|
214
214
|
mockResponse({
|
|
215
215
|
messaging_product: 'whatsapp',
|
|
216
216
|
contacts: [],
|
|
@@ -231,7 +231,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
231
231
|
})
|
|
232
232
|
|
|
233
233
|
describe('sendDocumentMessage', () => {
|
|
234
|
-
|
|
234
|
+
it('sends POST with document payload', async () => {
|
|
235
235
|
mockResponse({
|
|
236
236
|
messaging_product: 'whatsapp',
|
|
237
237
|
contacts: [],
|
|
@@ -252,7 +252,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
252
252
|
})
|
|
253
253
|
|
|
254
254
|
describe('listTemplates', () => {
|
|
255
|
-
|
|
255
|
+
it('sends GET and unwraps data key from response', async () => {
|
|
256
256
|
mockResponse({
|
|
257
257
|
data: [
|
|
258
258
|
{ name: 'hello_world', status: 'APPROVED', category: 'UTILITY', language: 'en_US', components: [] },
|
|
@@ -270,7 +270,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
270
270
|
expect(fetchCalls[0].options?.method).toBe('GET')
|
|
271
271
|
})
|
|
272
272
|
|
|
273
|
-
|
|
273
|
+
it('passes limit parameter in URL', async () => {
|
|
274
274
|
mockResponse({ data: [] })
|
|
275
275
|
|
|
276
276
|
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
@@ -281,7 +281,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
281
281
|
})
|
|
282
282
|
|
|
283
283
|
describe('getTemplate', () => {
|
|
284
|
-
|
|
284
|
+
it('sends GET with name filter and returns first match', async () => {
|
|
285
285
|
mockResponse({
|
|
286
286
|
data: [{ name: 'hello_world', status: 'APPROVED', category: 'UTILITY', language: 'en_US', components: [] }],
|
|
287
287
|
})
|
|
@@ -293,7 +293,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
293
293
|
expect(fetchCalls[0].url).toContain('name=hello_world')
|
|
294
294
|
})
|
|
295
295
|
|
|
296
|
-
|
|
296
|
+
it('throws WhatsAppBotError with not_found code when template not found', async () => {
|
|
297
297
|
mockResponse({ data: [] })
|
|
298
298
|
|
|
299
299
|
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
@@ -309,7 +309,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
309
309
|
})
|
|
310
310
|
|
|
311
311
|
describe('rate limiting', () => {
|
|
312
|
-
|
|
312
|
+
it('waits when x-business-use-case-usage indicates throttle', async () => {
|
|
313
313
|
const usageHeader = JSON.stringify({
|
|
314
314
|
'123456789': [
|
|
315
315
|
{
|
|
@@ -336,7 +336,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
336
336
|
expect(fetchCalls.length).toBe(2)
|
|
337
337
|
})
|
|
338
338
|
|
|
339
|
-
|
|
339
|
+
it('retries on 429 with Retry-After header', async () => {
|
|
340
340
|
mockResponse({ error: { message: 'Rate limited', code: 613 } }, 429, { 'Retry-After': '0.1' })
|
|
341
341
|
mockResponse({ verified_name: 'Test Business' })
|
|
342
342
|
|
|
@@ -347,7 +347,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
347
347
|
expect(fetchCalls.length).toBe(2)
|
|
348
348
|
})
|
|
349
349
|
|
|
350
|
-
|
|
350
|
+
it('throws after max retries exceeded', async () => {
|
|
351
351
|
for (let i = 0; i <= 3; i++) {
|
|
352
352
|
mockResponse({ error: { message: 'Rate limited', code: 613 } }, 429, { 'Retry-After': '0.01' })
|
|
353
353
|
}
|
|
@@ -359,7 +359,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
359
359
|
})
|
|
360
360
|
|
|
361
361
|
describe('retry logic', () => {
|
|
362
|
-
|
|
362
|
+
it('retries on 500 server error for GET requests', async () => {
|
|
363
363
|
mockResponse({ error: { message: 'Internal Server Error' } }, 500)
|
|
364
364
|
mockResponse({ verified_name: 'Test Business' })
|
|
365
365
|
|
|
@@ -370,7 +370,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
370
370
|
expect(fetchCalls.length).toBe(2)
|
|
371
371
|
})
|
|
372
372
|
|
|
373
|
-
|
|
373
|
+
it('does not retry on 500 for POST requests', async () => {
|
|
374
374
|
mockResponse({ error: { message: 'Internal Server Error' } }, 500)
|
|
375
375
|
|
|
376
376
|
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
@@ -378,7 +378,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
378
378
|
expect(fetchCalls.length).toBe(1)
|
|
379
379
|
})
|
|
380
380
|
|
|
381
|
-
|
|
381
|
+
it('does not retry on 4xx client errors (except 429)', async () => {
|
|
382
382
|
mockResponse({ error: { message: 'Not Found', code: 100 } }, 404)
|
|
383
383
|
|
|
384
384
|
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
@@ -386,7 +386,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
386
386
|
expect(fetchCalls.length).toBe(1)
|
|
387
387
|
})
|
|
388
388
|
|
|
389
|
-
|
|
389
|
+
it('does not retry on 403 forbidden', async () => {
|
|
390
390
|
mockResponse({ error: { message: 'Forbidden', code: 200 } }, 403)
|
|
391
391
|
|
|
392
392
|
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-token' })
|
|
@@ -396,7 +396,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
396
396
|
})
|
|
397
397
|
|
|
398
398
|
describe('request URL construction', () => {
|
|
399
|
-
|
|
399
|
+
it('all requests go to https://graph.facebook.com/v23.0/...', async () => {
|
|
400
400
|
mockResponse({ verified_name: 'Test' })
|
|
401
401
|
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'my-phone', accessToken: 'my-token' })
|
|
402
402
|
await client.verifyToken()
|
|
@@ -404,7 +404,7 @@ describe('WhatsAppBotClient', () => {
|
|
|
404
404
|
expect(fetchCalls[0].url.startsWith('https://graph.facebook.com/v23.0/')).toBe(true)
|
|
405
405
|
})
|
|
406
406
|
|
|
407
|
-
|
|
407
|
+
it('Authorization header is Bearer <token>', async () => {
|
|
408
408
|
mockResponse({ verified_name: 'Test' })
|
|
409
409
|
const client = await new WhatsAppBotClient().login({ phoneNumberId: 'phone-123', accessToken: 'my-secret-token' })
|
|
410
410
|
await client.verifyToken()
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, mock,
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, mock, it } from 'bun:test'
|
|
2
2
|
import { existsSync, rmSync } from 'node:fs'
|
|
3
3
|
import { mkdir } from 'node:fs/promises'
|
|
4
4
|
import { tmpdir } from 'node:os'
|
|
@@ -38,7 +38,7 @@ describe('auth commands', () => {
|
|
|
38
38
|
})
|
|
39
39
|
|
|
40
40
|
describe('setAction', () => {
|
|
41
|
-
|
|
41
|
+
it('validates token and stores credentials', async () => {
|
|
42
42
|
const manager = new WhatsAppBotCredentialManager(tempDir)
|
|
43
43
|
|
|
44
44
|
const result = await setAction('12345678901', 'EAAtest-token', { _credManager: manager })
|
|
@@ -52,7 +52,7 @@ describe('auth commands', () => {
|
|
|
52
52
|
expect(creds?.access_token).toBe('EAAtest-token')
|
|
53
53
|
})
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
it('returns error when client throws', async () => {
|
|
56
56
|
mockVerifyToken.mockImplementationOnce(() => Promise.reject(new Error('Invalid token')))
|
|
57
57
|
const manager = new WhatsAppBotCredentialManager(tempDir)
|
|
58
58
|
|
|
@@ -64,7 +64,7 @@ describe('auth commands', () => {
|
|
|
64
64
|
})
|
|
65
65
|
|
|
66
66
|
describe('statusAction', () => {
|
|
67
|
-
|
|
67
|
+
it('returns invalid status when no credentials set', async () => {
|
|
68
68
|
const manager = new WhatsAppBotCredentialManager(tempDir)
|
|
69
69
|
|
|
70
70
|
const result = await statusAction({ _credManager: manager })
|
|
@@ -73,7 +73,7 @@ describe('auth commands', () => {
|
|
|
73
73
|
expect(result.error).toBeDefined()
|
|
74
74
|
})
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
it('returns valid status when credentials are set', async () => {
|
|
77
77
|
const manager = new WhatsAppBotCredentialManager(tempDir)
|
|
78
78
|
await manager.setCredentials({
|
|
79
79
|
phone_number_id: '12345678901',
|
|
@@ -88,7 +88,7 @@ describe('auth commands', () => {
|
|
|
88
88
|
expect(result.account_name).toBe('Test Business')
|
|
89
89
|
})
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
it('returns invalid status when verifyToken fails', async () => {
|
|
92
92
|
mockVerifyToken.mockImplementationOnce(() => Promise.reject(new Error('Token expired')))
|
|
93
93
|
const manager = new WhatsAppBotCredentialManager(tempDir)
|
|
94
94
|
await manager.setCredentials({
|
|
@@ -103,7 +103,7 @@ describe('auth commands', () => {
|
|
|
103
103
|
expect(result.phone_number_id).toBe('12345678901')
|
|
104
104
|
})
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
it('returns error for unknown account', async () => {
|
|
107
107
|
const manager = new WhatsAppBotCredentialManager(tempDir)
|
|
108
108
|
|
|
109
109
|
const result = await statusAction({ account: 'nonexistent', _credManager: manager })
|
|
@@ -114,7 +114,7 @@ describe('auth commands', () => {
|
|
|
114
114
|
})
|
|
115
115
|
|
|
116
116
|
describe('clearAction', () => {
|
|
117
|
-
|
|
117
|
+
it('removes all stored credentials', async () => {
|
|
118
118
|
const manager = new WhatsAppBotCredentialManager(tempDir)
|
|
119
119
|
await manager.setCredentials({
|
|
120
120
|
phone_number_id: '12345678901',
|
|
@@ -130,7 +130,7 @@ describe('auth commands', () => {
|
|
|
130
130
|
})
|
|
131
131
|
|
|
132
132
|
describe('listAction', () => {
|
|
133
|
-
|
|
133
|
+
it('returns empty accounts when none set', async () => {
|
|
134
134
|
const manager = new WhatsAppBotCredentialManager(tempDir)
|
|
135
135
|
|
|
136
136
|
const result = await listAction({ _credManager: manager })
|
|
@@ -138,7 +138,7 @@ describe('auth commands', () => {
|
|
|
138
138
|
expect(result.accounts).toHaveLength(0)
|
|
139
139
|
})
|
|
140
140
|
|
|
141
|
-
|
|
141
|
+
it('returns all stored accounts', async () => {
|
|
142
142
|
const manager = new WhatsAppBotCredentialManager(tempDir)
|
|
143
143
|
await manager.setCredentials({
|
|
144
144
|
phone_number_id: '11111111111',
|
|
@@ -160,7 +160,7 @@ describe('auth commands', () => {
|
|
|
160
160
|
})
|
|
161
161
|
|
|
162
162
|
describe('useAction', () => {
|
|
163
|
-
|
|
163
|
+
it('switches current account', async () => {
|
|
164
164
|
const manager = new WhatsAppBotCredentialManager(tempDir)
|
|
165
165
|
await manager.setCredentials({
|
|
166
166
|
phone_number_id: '11111111111',
|
|
@@ -180,7 +180,7 @@ describe('auth commands', () => {
|
|
|
180
180
|
expect(result.account_name).toBe('Account A')
|
|
181
181
|
})
|
|
182
182
|
|
|
183
|
-
|
|
183
|
+
it('returns error for unknown account', async () => {
|
|
184
184
|
const manager = new WhatsAppBotCredentialManager(tempDir)
|
|
185
185
|
|
|
186
186
|
const result = await useAction('nonexistent', { _credManager: manager })
|
|
@@ -191,7 +191,7 @@ describe('auth commands', () => {
|
|
|
191
191
|
})
|
|
192
192
|
|
|
193
193
|
describe('removeAction', () => {
|
|
194
|
-
|
|
194
|
+
it('removes a stored account', async () => {
|
|
195
195
|
const manager = new WhatsAppBotCredentialManager(tempDir)
|
|
196
196
|
await manager.setCredentials({
|
|
197
197
|
phone_number_id: '12345678901',
|
|
@@ -205,7 +205,7 @@ describe('auth commands', () => {
|
|
|
205
205
|
expect(await manager.getCredentials('12345678901')).toBeNull()
|
|
206
206
|
})
|
|
207
207
|
|
|
208
|
-
|
|
208
|
+
it('returns error for unknown account', async () => {
|
|
209
209
|
const manager = new WhatsAppBotCredentialManager(tempDir)
|
|
210
210
|
|
|
211
211
|
const result = await removeAction('nonexistent', { _credManager: manager })
|