agent-messenger 2.29.1 → 2.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +15 -0
- package/dist/package.json +1 -1
- package/dist/src/platforms/discord/client.d.ts +1 -0
- package/dist/src/platforms/discord/client.d.ts.map +1 -1
- package/dist/src/platforms/discord/client.js +3 -0
- package/dist/src/platforms/discord/client.js.map +1 -1
- package/dist/src/platforms/discord/commands/message.d.ts +3 -0
- package/dist/src/platforms/discord/commands/message.d.ts.map +1 -1
- package/dist/src/platforms/discord/commands/message.js +30 -0
- package/dist/src/platforms/discord/commands/message.js.map +1 -1
- package/dist/src/platforms/discordbot/commands/message.d.ts +1 -1
- package/dist/src/platforms/discordbot/commands/message.d.ts.map +1 -1
- package/dist/src/platforms/discordbot/commands/message.js +4 -4
- package/dist/src/platforms/discordbot/commands/message.js.map +1 -1
- package/dist/src/platforms/slack/commands/message.js +4 -4
- package/dist/src/platforms/slack/commands/message.js.map +1 -1
- package/dist/src/platforms/slackbot/commands/message.js +4 -4
- package/dist/src/platforms/slackbot/commands/message.js.map +1 -1
- package/dist/src/platforms/teams/client.d.ts +1 -0
- package/dist/src/platforms/teams/client.d.ts.map +1 -1
- package/dist/src/platforms/teams/client.js +19 -0
- package/dist/src/platforms/teams/client.js.map +1 -1
- package/dist/src/platforms/teams/commands/chat.d.ts +3 -0
- package/dist/src/platforms/teams/commands/chat.d.ts.map +1 -1
- package/dist/src/platforms/teams/commands/chat.js +34 -1
- package/dist/src/platforms/teams/commands/chat.js.map +1 -1
- package/dist/src/platforms/telegram/client.d.ts +1 -0
- package/dist/src/platforms/telegram/client.d.ts.map +1 -1
- package/dist/src/platforms/telegram/client.js +21 -0
- package/dist/src/platforms/telegram/client.js.map +1 -1
- package/dist/src/platforms/telegram/commands/message.d.ts.map +1 -1
- package/dist/src/platforms/telegram/commands/message.js +25 -1
- package/dist/src/platforms/telegram/commands/message.js.map +1 -1
- package/dist/src/platforms/telegrambot/commands/message.d.ts +1 -1
- package/dist/src/platforms/telegrambot/commands/message.d.ts.map +1 -1
- package/dist/src/platforms/telegrambot/commands/message.js +3 -3
- package/dist/src/platforms/telegrambot/commands/message.js.map +1 -1
- package/dist/src/platforms/whatsapp/client.d.ts +3 -1
- package/dist/src/platforms/whatsapp/client.d.ts.map +1 -1
- package/dist/src/platforms/whatsapp/client.js +19 -3
- package/dist/src/platforms/whatsapp/client.js.map +1 -1
- package/dist/src/platforms/whatsapp/commands/message.d.ts.map +1 -1
- package/dist/src/platforms/whatsapp/commands/message.js +18 -0
- package/dist/src/platforms/whatsapp/commands/message.js.map +1 -1
- package/docs/content/docs/cli/discordbot.mdx +2 -2
- package/docs/content/docs/cli/slack.mdx +2 -2
- package/docs/content/docs/cli/slackbot.mdx +2 -2
- package/docs/content/docs/cli/telegrambot.mdx +1 -1
- package/e2e/README.md +3 -3
- package/e2e/discordbot.e2e.test.ts +2 -2
- package/e2e/slack.e2e.test.ts +2 -2
- package/e2e/slackbot.e2e.test.ts +2 -2
- package/e2e/telegrambot.e2e.test.ts +2 -2
- 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 +5 -1
- package/skills/agent-discordbot/SKILL.md +3 -3
- package/skills/agent-discordbot/references/common-patterns.md +2 -2
- package/skills/agent-imessage/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 +3 -3
- package/skills/agent-slack/references/common-patterns.md +2 -2
- package/skills/agent-slackbot/SKILL.md +3 -3
- package/skills/agent-slackbot/references/common-patterns.md +4 -4
- package/skills/agent-teams/SKILL.md +6 -1
- package/skills/agent-telegram/SKILL.md +4 -1
- package/skills/agent-telegrambot/SKILL.md +2 -2
- package/skills/agent-webex/SKILL.md +1 -1
- package/skills/agent-webexbot/SKILL.md +1 -1
- package/skills/agent-wechatbot/SKILL.md +1 -1
- package/skills/agent-whatsapp/SKILL.md +25 -1
- package/skills/agent-whatsappbot/SKILL.md +1 -1
- package/src/platforms/discord/client.test.ts +22 -0
- package/src/platforms/discord/client.ts +4 -0
- package/src/platforms/discord/commands/message.test.ts +26 -1
- package/src/platforms/discord/commands/message.ts +41 -0
- package/src/platforms/discordbot/commands/message.test.ts +6 -6
- package/src/platforms/discordbot/commands/message.ts +4 -4
- package/src/platforms/slack/commands/message.test.ts +4 -4
- package/src/platforms/slack/commands/message.ts +4 -4
- package/src/platforms/slackbot/commands/message.ts +4 -4
- package/src/platforms/teams/client.test.ts +24 -0
- package/src/platforms/teams/client.ts +28 -0
- package/src/platforms/teams/commands/chat.test.ts +23 -1
- package/src/platforms/teams/commands/chat.ts +44 -0
- package/src/platforms/telegram/client.test.ts +60 -0
- package/src/platforms/telegram/client.ts +24 -0
- package/src/platforms/telegram/commands/message.test.ts +38 -0
- package/src/platforms/telegram/commands/message.ts +39 -0
- package/src/platforms/telegrambot/commands/message.ts +3 -3
- package/src/platforms/whatsapp/client.test.ts +58 -0
- package/src/platforms/whatsapp/client.ts +23 -3
- package/src/platforms/whatsapp/commands/message.test.ts +43 -0
- package/src/platforms/whatsapp/commands/message.ts +25 -0
|
@@ -9,9 +9,12 @@ const mockListMessages = mock(() =>
|
|
|
9
9
|
|
|
10
10
|
const mockSendMessage = mock(() => Promise.resolve({ id: 3, text: 'Sent message', sender_id: 'user-1', date: 3000 }))
|
|
11
11
|
|
|
12
|
+
const mockEditMessage = mock(() => Promise.resolve({ id: 3, text: 'Edited message', sender_id: 'user-1', date: 3000 }))
|
|
13
|
+
|
|
12
14
|
const mockClient = {
|
|
13
15
|
listMessages: mockListMessages,
|
|
14
16
|
sendMessage: mockSendMessage,
|
|
17
|
+
editMessage: mockEditMessage,
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
mock.module('./shared', () => ({
|
|
@@ -36,6 +39,10 @@ describe('message commands', () => {
|
|
|
36
39
|
mockSendMessage.mockImplementation(() =>
|
|
37
40
|
Promise.resolve({ id: 3, text: 'Sent message', sender_id: 'user-1', date: 3000 }),
|
|
38
41
|
)
|
|
42
|
+
mockEditMessage.mockReset()
|
|
43
|
+
mockEditMessage.mockImplementation(() =>
|
|
44
|
+
Promise.resolve({ id: 3, text: 'Edited message', sender_id: 'user-1', date: 3000 }),
|
|
45
|
+
)
|
|
39
46
|
consoleSpy = spyOn(console, 'log').mockImplementation(() => {})
|
|
40
47
|
processExitSpy = spyOn(process, 'exit').mockImplementation((() => {}) as (code?: number) => never)
|
|
41
48
|
})
|
|
@@ -86,4 +93,35 @@ describe('message commands', () => {
|
|
|
86
93
|
expect(parsed.id).toBe(3)
|
|
87
94
|
})
|
|
88
95
|
})
|
|
96
|
+
|
|
97
|
+
describe('edit subcommand', () => {
|
|
98
|
+
it('calls editMessage with chat reference, numeric message id, and text', async () => {
|
|
99
|
+
await messageCommand.parseAsync(['edit', 'chat-123', '3', 'Edited message'], { from: 'user' })
|
|
100
|
+
|
|
101
|
+
expect(mockEditMessage).toHaveBeenCalledWith('chat-123', 3, 'Edited message')
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('outputs the edited message as JSON', async () => {
|
|
105
|
+
await messageCommand.parseAsync(['edit', 'chat-123', '3', 'Edited message'], { from: 'user' })
|
|
106
|
+
|
|
107
|
+
expect(consoleSpy).toHaveBeenCalled()
|
|
108
|
+
const output = consoleSpy.mock.calls[0][0] as string
|
|
109
|
+
const parsed = JSON.parse(output)
|
|
110
|
+
expect(parsed.text).toBe('Edited message')
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('rejects non-decimal, unsafe, or non-positive message ids', async () => {
|
|
114
|
+
const invalidIds = ['not-a-number', '1e3', '0x10', '0', '9007199254740993']
|
|
115
|
+
|
|
116
|
+
for (const invalidId of invalidIds) {
|
|
117
|
+
mockEditMessage.mockClear()
|
|
118
|
+
processExitSpy.mockClear()
|
|
119
|
+
|
|
120
|
+
await messageCommand.parseAsync(['edit', 'chat-123', invalidId, 'text'], { from: 'user' })
|
|
121
|
+
|
|
122
|
+
expect(mockEditMessage).not.toHaveBeenCalled()
|
|
123
|
+
expect(processExitSpy).toHaveBeenCalledWith(1)
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
})
|
|
89
127
|
})
|
|
@@ -30,6 +30,35 @@ async function sendAction(
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
async function editAction(
|
|
34
|
+
reference: string,
|
|
35
|
+
messageId: string,
|
|
36
|
+
text: string,
|
|
37
|
+
options: { account?: string; pretty?: boolean },
|
|
38
|
+
): Promise<void> {
|
|
39
|
+
try {
|
|
40
|
+
const trimmedMessageId = messageId.trim()
|
|
41
|
+
const parsedMessageId = Number.parseInt(trimmedMessageId, 10)
|
|
42
|
+
if (!/^\d+$/.test(trimmedMessageId) || !Number.isSafeInteger(parsedMessageId) || parsedMessageId <= 0) {
|
|
43
|
+
console.log(
|
|
44
|
+
formatOutput(
|
|
45
|
+
{ error: 'Invalid message ID. Provide the numeric message ID from "message list".' },
|
|
46
|
+
options.pretty,
|
|
47
|
+
),
|
|
48
|
+
)
|
|
49
|
+
process.exit(1)
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const message = await withTelegramClient(options, async (client) =>
|
|
54
|
+
client.editMessage(reference, parsedMessageId, text),
|
|
55
|
+
)
|
|
56
|
+
console.log(formatOutput(message, options.pretty))
|
|
57
|
+
} catch (error) {
|
|
58
|
+
handleError(error as Error)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
33
62
|
export const messageCommand = new Command('message')
|
|
34
63
|
.description('Telegram message commands')
|
|
35
64
|
.addCommand(
|
|
@@ -50,3 +79,13 @@ export const messageCommand = new Command('message')
|
|
|
50
79
|
.option('--pretty', 'Pretty print JSON output')
|
|
51
80
|
.action(sendAction),
|
|
52
81
|
)
|
|
82
|
+
.addCommand(
|
|
83
|
+
new Command('edit')
|
|
84
|
+
.description('Edit a text message (your own messages only, within 48h)')
|
|
85
|
+
.argument('<chat>', 'Chat ID, @username, or title')
|
|
86
|
+
.argument('<message-id>', 'Message ID')
|
|
87
|
+
.argument('<text>', 'New message text')
|
|
88
|
+
.option('--account <id>', 'Use a specific Telegram account')
|
|
89
|
+
.option('--pretty', 'Pretty print JSON output')
|
|
90
|
+
.action(editAction),
|
|
91
|
+
)
|
|
@@ -61,7 +61,7 @@ export async function sendAction(
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export async function
|
|
64
|
+
export async function editAction(
|
|
65
65
|
chat: string,
|
|
66
66
|
messageId: string,
|
|
67
67
|
text: string,
|
|
@@ -162,7 +162,7 @@ export const messageCommand = new Command('message')
|
|
|
162
162
|
),
|
|
163
163
|
)
|
|
164
164
|
.addCommand(
|
|
165
|
-
new Command('
|
|
165
|
+
new Command('edit')
|
|
166
166
|
.description("Edit a message (bot's own messages only)")
|
|
167
167
|
.argument('<chat>', 'Chat ID or @username')
|
|
168
168
|
.argument('<message-id>', 'Message ID')
|
|
@@ -177,7 +177,7 @@ export const messageCommand = new Command('message')
|
|
|
177
177
|
text: string,
|
|
178
178
|
opts: BotOption & { parseMode?: 'HTML' | 'Markdown' | 'MarkdownV2' },
|
|
179
179
|
) => {
|
|
180
|
-
cliOutput(await
|
|
180
|
+
cliOutput(await editAction(chat, messageId, text, opts), opts.pretty)
|
|
181
181
|
},
|
|
182
182
|
),
|
|
183
183
|
)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test'
|
|
2
|
+
|
|
3
|
+
import type { WAMessage } from '@whiskeysockets/baileys'
|
|
4
|
+
|
|
5
|
+
import { summarizeMessage } from '@/platforms/whatsapp/client'
|
|
6
|
+
|
|
7
|
+
describe('summarizeMessage', () => {
|
|
8
|
+
it('summarizes a plain text message', () => {
|
|
9
|
+
const msg = {
|
|
10
|
+
key: { id: 'msg-1', remoteJid: '12025551234@s.whatsapp.net', fromMe: true },
|
|
11
|
+
messageTimestamp: 1_700_000_000,
|
|
12
|
+
message: { conversation: 'Hello' },
|
|
13
|
+
} as unknown as WAMessage
|
|
14
|
+
|
|
15
|
+
const summary = summarizeMessage(msg)
|
|
16
|
+
|
|
17
|
+
expect(summary.id).toBe('msg-1')
|
|
18
|
+
expect(summary.type).toBe('text')
|
|
19
|
+
expect(summary.text).toBe('Hello')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('unwraps a Baileys edit protocolMessage to the edited content', () => {
|
|
23
|
+
const msg = {
|
|
24
|
+
key: { id: 'msg-2', remoteJid: '12025551234@s.whatsapp.net', fromMe: true },
|
|
25
|
+
messageTimestamp: 1_700_000_100,
|
|
26
|
+
message: {
|
|
27
|
+
protocolMessage: {
|
|
28
|
+
type: 14,
|
|
29
|
+
editedMessage: { conversation: 'Edited text' },
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
} as unknown as WAMessage
|
|
33
|
+
|
|
34
|
+
const summary = summarizeMessage(msg)
|
|
35
|
+
|
|
36
|
+
expect(summary.id).toBe('msg-2')
|
|
37
|
+
expect(summary.type).toBe('text')
|
|
38
|
+
expect(summary.text).toBe('Edited text')
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('unwraps an edit that uses extendedTextMessage', () => {
|
|
42
|
+
const msg = {
|
|
43
|
+
key: { id: 'msg-3', remoteJid: '12025551234@s.whatsapp.net', fromMe: true },
|
|
44
|
+
messageTimestamp: 1_700_000_200,
|
|
45
|
+
message: {
|
|
46
|
+
protocolMessage: {
|
|
47
|
+
type: 14,
|
|
48
|
+
editedMessage: { extendedTextMessage: { text: 'Edited via extended' } },
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
} as unknown as WAMessage
|
|
52
|
+
|
|
53
|
+
const summary = summarizeMessage(msg)
|
|
54
|
+
|
|
55
|
+
expect(summary.type).toBe('text')
|
|
56
|
+
expect(summary.text).toBe('Edited via extended')
|
|
57
|
+
})
|
|
58
|
+
})
|
|
@@ -48,11 +48,15 @@ function resolveJid(input: string): string {
|
|
|
48
48
|
return `${digits}@s.whatsapp.net`
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
function summarizeMessage(msg: WAMessage): WhatsAppMessageSummary {
|
|
51
|
+
export function summarizeMessage(msg: WAMessage): WhatsAppMessageSummary {
|
|
52
52
|
const jid = msg.key.remoteJid ?? ''
|
|
53
53
|
const isGroup = jid.endsWith('@g.us')
|
|
54
54
|
const from = msg.key.fromMe ? '' : isGroup ? (msg.key.participant ?? msg.participant ?? jid) : jid
|
|
55
55
|
|
|
56
|
+
// Baileys wraps an edit as a protocolMessage whose editedMessage holds the new
|
|
57
|
+
// content; unwrap it so the summary reflects the edited text and type.
|
|
58
|
+
const content = msg.message?.protocolMessage?.editedMessage ?? msg.message
|
|
59
|
+
|
|
56
60
|
return {
|
|
57
61
|
id: msg.key.id ?? '',
|
|
58
62
|
chat_id: jid,
|
|
@@ -60,8 +64,8 @@ function summarizeMessage(msg: WAMessage): WhatsAppMessageSummary {
|
|
|
60
64
|
from_name: msg.pushName ?? undefined,
|
|
61
65
|
timestamp: new Date(toTimestampMs(msg.messageTimestamp)).toISOString(),
|
|
62
66
|
is_outgoing: Boolean(msg.key.fromMe),
|
|
63
|
-
type: getMessageType(
|
|
64
|
-
text: extractMessageText(
|
|
67
|
+
type: getMessageType(content),
|
|
68
|
+
text: extractMessageText(content),
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
71
|
|
|
@@ -660,6 +664,22 @@ export class WhatsAppClient {
|
|
|
660
664
|
})
|
|
661
665
|
}
|
|
662
666
|
|
|
667
|
+
async editMessage(jid: string, messageId: string, text: string): Promise<WhatsAppMessageSummary> {
|
|
668
|
+
if (!this.sock) throw new WhatsAppError('Not connected', 'not_connected')
|
|
669
|
+
|
|
670
|
+
const resolvedJid = resolveJid(jid)
|
|
671
|
+
const result = await this.sock.sendMessage(resolvedJid, {
|
|
672
|
+
text,
|
|
673
|
+
edit: { remoteJid: resolvedJid, fromMe: true, id: messageId },
|
|
674
|
+
})
|
|
675
|
+
|
|
676
|
+
if (!result) {
|
|
677
|
+
throw new WhatsAppError('Failed to edit message', 'edit_failed')
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
return summarizeMessage(result)
|
|
681
|
+
}
|
|
682
|
+
|
|
663
683
|
async close(): Promise<void> {
|
|
664
684
|
try {
|
|
665
685
|
await this.saveStore()
|
|
@@ -42,6 +42,16 @@ const mockSendMessage = mock(() =>
|
|
|
42
42
|
}),
|
|
43
43
|
)
|
|
44
44
|
|
|
45
|
+
const mockEditMessage = mock(() =>
|
|
46
|
+
Promise.resolve({
|
|
47
|
+
id: 'msg-2',
|
|
48
|
+
text: 'Edited text',
|
|
49
|
+
from: 'me@s.whatsapp.net',
|
|
50
|
+
timestamp: 3000,
|
|
51
|
+
fromMe: true,
|
|
52
|
+
}),
|
|
53
|
+
)
|
|
54
|
+
|
|
45
55
|
const mockSendReaction = mock(() => Promise.resolve())
|
|
46
56
|
const mockConnect = mock(() => Promise.resolve())
|
|
47
57
|
const mockClose = mock(() => Promise.resolve())
|
|
@@ -55,6 +65,7 @@ mock.module('../client', () => ({
|
|
|
55
65
|
close = mockClose
|
|
56
66
|
getMessages = mockGetMessages
|
|
57
67
|
sendMessage = mockSendMessage
|
|
68
|
+
editMessage = mockEditMessage
|
|
58
69
|
sendReaction = mockSendReaction
|
|
59
70
|
},
|
|
60
71
|
}))
|
|
@@ -71,6 +82,7 @@ describe('message commands', () => {
|
|
|
71
82
|
mockEnsureAccountPaths.mockReset()
|
|
72
83
|
mockGetMessages.mockReset()
|
|
73
84
|
mockSendMessage.mockReset()
|
|
85
|
+
mockEditMessage.mockReset()
|
|
74
86
|
mockSendReaction.mockReset()
|
|
75
87
|
mockConnect.mockReset()
|
|
76
88
|
mockClose.mockReset()
|
|
@@ -107,6 +119,15 @@ describe('message commands', () => {
|
|
|
107
119
|
fromMe: true,
|
|
108
120
|
}),
|
|
109
121
|
)
|
|
122
|
+
mockEditMessage.mockImplementation(() =>
|
|
123
|
+
Promise.resolve({
|
|
124
|
+
id: 'msg-2',
|
|
125
|
+
text: 'Edited text',
|
|
126
|
+
from: 'me@s.whatsapp.net',
|
|
127
|
+
timestamp: 3000,
|
|
128
|
+
fromMe: true,
|
|
129
|
+
}),
|
|
130
|
+
)
|
|
110
131
|
mockSendReaction.mockImplementation(() => Promise.resolve())
|
|
111
132
|
mockConnect.mockImplementation(() => Promise.resolve())
|
|
112
133
|
mockClose.mockImplementation(() => Promise.resolve())
|
|
@@ -182,6 +203,28 @@ describe('message commands', () => {
|
|
|
182
203
|
})
|
|
183
204
|
})
|
|
184
205
|
|
|
206
|
+
describe('edit', () => {
|
|
207
|
+
it('edits a message in a chat', async () => {
|
|
208
|
+
await messageCommand.parseAsync(['edit', '12025551234@s.whatsapp.net', 'msg-2', 'Edited text'], { from: 'user' })
|
|
209
|
+
|
|
210
|
+
expect(processExitSpy).toHaveBeenCalledWith(0)
|
|
211
|
+
expect(mockEditMessage).toHaveBeenCalledWith('12025551234@s.whatsapp.net', 'msg-2', 'Edited text')
|
|
212
|
+
const output = JSON.parse(consoleLogSpy.mock.calls[0][0])
|
|
213
|
+
expect(output.id).toBe('msg-2')
|
|
214
|
+
expect(output.text).toBe('Edited text')
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
it('passes account option to credential manager', async () => {
|
|
218
|
+
await messageCommand.parseAsync(
|
|
219
|
+
['edit', '12025551234@s.whatsapp.net', 'msg-2', 'Edited text', '--account', 'my-account'],
|
|
220
|
+
{ from: 'user' },
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
expect(processExitSpy).toHaveBeenCalledWith(0)
|
|
224
|
+
expect(mockGetAccount).toHaveBeenCalledWith('my-account')
|
|
225
|
+
})
|
|
226
|
+
})
|
|
227
|
+
|
|
185
228
|
describe('react', () => {
|
|
186
229
|
it('sends a reaction to a message', async () => {
|
|
187
230
|
await messageCommand.parseAsync(['react', '12025551234@s.whatsapp.net', 'msg-1', '👍'], { from: 'user' })
|
|
@@ -29,6 +29,21 @@ async function sendAction(chat: string, text: string, options: { account?: strin
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
async function editAction(
|
|
33
|
+
chat: string,
|
|
34
|
+
messageId: string,
|
|
35
|
+
text: string,
|
|
36
|
+
options: { account?: string; pretty?: boolean },
|
|
37
|
+
): Promise<void> {
|
|
38
|
+
try {
|
|
39
|
+
const message = await withWhatsAppClient(options, (client) => client.editMessage(chat, messageId, text))
|
|
40
|
+
console.log(formatOutput(message, options.pretty))
|
|
41
|
+
process.exit(0)
|
|
42
|
+
} catch (error) {
|
|
43
|
+
handleError(error as Error)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
32
47
|
async function reactAction(
|
|
33
48
|
chat: string,
|
|
34
49
|
messageId: string,
|
|
@@ -64,6 +79,16 @@ export const messageCommand = new Command('message')
|
|
|
64
79
|
.option('--pretty', 'Pretty print JSON output')
|
|
65
80
|
.action(sendAction),
|
|
66
81
|
)
|
|
82
|
+
.addCommand(
|
|
83
|
+
new Command('edit')
|
|
84
|
+
.description('Edit one of your own messages (within ~15 minutes)')
|
|
85
|
+
.argument('<chat>', 'Chat JID or phone number')
|
|
86
|
+
.argument('<message-id>', 'Message ID to edit')
|
|
87
|
+
.argument('<text>', 'New message text')
|
|
88
|
+
.option('--account <id>', 'Use a specific WhatsApp account')
|
|
89
|
+
.option('--pretty', 'Pretty print JSON output')
|
|
90
|
+
.action(editAction),
|
|
91
|
+
)
|
|
67
92
|
.addCommand(
|
|
68
93
|
new Command('react')
|
|
69
94
|
.description('React to a message with an emoji')
|