mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 16:41:23 +00:00
fix(telegram): wire sendPollTelegram into channel action handler (#16977)
The Telegram channel adapter listed no 'poll' action, so agents could not create polls via the unified action interface. The underlying sendPollTelegram function was already implemented but unreachable. Changes: - telegram.ts: add 'poll' to listActions (enabled by default via gate), add handleAction branch that reads pollQuestion/pollOption params and delegates to handleTelegramAction with action 'sendPoll'. - telegram-actions.ts: add 'sendPoll' handler that validates question, options (≥2), and forwards to sendPollTelegram with threading, silent, and anonymous options. - actions.test.ts: add test verifying poll action routes correctly. Fixes #16977
This commit is contained in:
committed by
Peter Steinberger
parent
068b9c9749
commit
7bb9a7dcfc
@@ -402,5 +402,42 @@ export async function handleTelegramAction(
|
||||
return jsonResult({ ok: true, ...stats });
|
||||
}
|
||||
|
||||
if (action === "sendPoll") {
|
||||
const to = readStringParam(params, "to", { required: true });
|
||||
const question = readStringParam(params, "question") ?? readStringParam(params, "pollQuestion");
|
||||
if (!question) {
|
||||
throw new Error("sendPoll requires 'question'");
|
||||
}
|
||||
const options = (params.options ?? params.pollOption) as string[] | undefined;
|
||||
if (!options || options.length < 2) {
|
||||
throw new Error("sendPoll requires at least 2 options");
|
||||
}
|
||||
const maxSelections =
|
||||
typeof params.maxSelections === "number" ? params.maxSelections : undefined;
|
||||
const isAnonymous = typeof params.isAnonymous === "boolean" ? params.isAnonymous : undefined;
|
||||
const silent = typeof params.silent === "boolean" ? params.silent : undefined;
|
||||
const replyToMessageId = readNumberParam(params, "replyTo");
|
||||
const messageThreadId = readNumberParam(params, "threadId");
|
||||
const pollAccountId = readStringParam(params, "accountId");
|
||||
|
||||
const res = await sendPollTelegram(
|
||||
to,
|
||||
{ question, options, maxSelections },
|
||||
{
|
||||
accountId: pollAccountId?.trim() || undefined,
|
||||
replyToMessageId,
|
||||
messageThreadId,
|
||||
isAnonymous,
|
||||
silent,
|
||||
},
|
||||
);
|
||||
return jsonResult({
|
||||
ok: true,
|
||||
messageId: res.messageId,
|
||||
chatId: res.chatId,
|
||||
pollId: res.pollId,
|
||||
});
|
||||
}
|
||||
|
||||
throw new Error(`Unsupported Telegram action: ${action}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user