Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions src/messaging/outbound/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ function readFeishuSendParams(
};
}

export function readReactionMessageId(
params: Record<string, unknown>,
toolContext?: ChannelThreadingToolContext,
): string | undefined {
return (
readStringParam(params, 'messageId') ??
readStringParam(params, 'message_id') ??
(toolContext?.currentMessageId != null ? String(toolContext.currentMessageId) : undefined)
);
}

// ---------------------------------------------------------------------------
// Adapter
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -201,9 +212,9 @@ export const feishuMessageActions: ChannelMessageActionAdapter = {
case 'send':
return await deliverMessage(cfg, readFeishuSendParams(params, toolContext), aid, ctx.mediaLocalRoots);
case 'react':
return await handleReact(cfg, params, aid);
return await handleReact(cfg, params, aid, toolContext);
case 'reactions':
return await handleReactions(cfg, params, aid);
return await handleReactions(cfg, params, aid, toolContext);
case 'delete':
case 'unsend':
return await handleDelete(cfg, params, aid);
Expand Down Expand Up @@ -335,8 +346,16 @@ async function deliverMedia(
// Reaction handlers
// ---------------------------------------------------------------------------

async function handleReact(cfg: OpenClawConfig, params: Record<string, unknown>, accountId?: string) {
const messageId = readStringParam(params, 'messageId', { required: true });
async function handleReact(
cfg: OpenClawConfig,
params: Record<string, unknown>,
accountId?: string,
toolContext?: ChannelThreadingToolContext,
) {
const messageId = readReactionMessageId(params, toolContext);
if (!messageId) {
throw new Error('messageId required');
}
const { emoji, remove, isEmpty } = readReactionParams(params, {
removeErrorMessage: 'Emoji is required to remove a Feishu reaction.',
});
Expand Down Expand Up @@ -373,8 +392,16 @@ async function handleReact(cfg: OpenClawConfig, params: Record<string, unknown>,
return jsonResult({ ok: true, reactionId });
}

async function handleReactions(cfg: OpenClawConfig, params: Record<string, unknown>, accountId?: string) {
const messageId = readStringParam(params, 'messageId', { required: true });
async function handleReactions(
cfg: OpenClawConfig,
params: Record<string, unknown>,
accountId?: string,
toolContext?: ChannelThreadingToolContext,
) {
const messageId = readReactionMessageId(params, toolContext);
if (!messageId) {
throw new Error('messageId required');
}
const emojiType = readStringParam(params, 'emoji');

const reactions = await listReactionsFeishu({
Expand Down
18 changes: 18 additions & 0 deletions tests/reaction-defaults.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { describe, expect, it } from 'vitest';
import { readReactionMessageId } from '../src/messaging/outbound/actions';

describe('readReactionMessageId', () => {
it('accepts message_id as an alias for messageId', () => {
expect(readReactionMessageId({ message_id: 'om_1' })).toBe('om_1');
});

it('falls back to the current inbound message id from tool context', () => {
expect(readReactionMessageId({}, { currentMessageId: 'om_current' } as never)).toBe('om_current');
});

it('prefers explicit messageId over the current inbound message id', () => {
expect(readReactionMessageId({ messageId: 'om_explicit' }, { currentMessageId: 'om_current' } as never)).toBe(
'om_explicit',
);
});
});