mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 22:44:36 +00:00
Revert "Default Telegram polls to public"
This reverts commit c43e95e011.
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import type { Message, ReactionTypeEmoji } from "@grammyjs/types";
|
||||
import type { TelegramGroupConfig, TelegramTopicConfig } from "../config/types.js";
|
||||
import type { TelegramMediaRef } from "./bot-message-context.js";
|
||||
import type { TelegramContext } from "./bot/types.js";
|
||||
import { resolveDefaultAgentId } from "../agents/agent-scope.js";
|
||||
import { hasControlCommand } from "../auto-reply/command-detection.js";
|
||||
import {
|
||||
@@ -14,7 +17,6 @@ import { resolveChannelConfigWrites } from "../channels/plugins/config-writes.js
|
||||
import { loadConfig } from "../config/config.js";
|
||||
import { writeConfigFile } from "../config/io.js";
|
||||
import { loadSessionStore, resolveStorePath } from "../config/sessions.js";
|
||||
import type { TelegramGroupConfig, TelegramTopicConfig } from "../config/types.js";
|
||||
import { danger, logVerbose, warn } from "../globals.js";
|
||||
import { enqueueSystemEvent } from "../infra/system-events.js";
|
||||
import { readChannelAllowFromStore } from "../pairing/pairing-store.js";
|
||||
@@ -26,7 +28,6 @@ import {
|
||||
normalizeAllowFromWithStore,
|
||||
type NormalizedAllowFrom,
|
||||
} from "./bot-access.js";
|
||||
import type { TelegramMediaRef } from "./bot-message-context.js";
|
||||
import { RegisterTelegramHandlerParams } from "./bot-native-commands.js";
|
||||
import { MEDIA_GROUP_TIMEOUT_MS, type MediaGroupEntry } from "./bot-updates.js";
|
||||
import { resolveMedia } from "./bot/delivery.js";
|
||||
@@ -36,7 +37,6 @@ import {
|
||||
resolveTelegramForumThreadId,
|
||||
resolveTelegramGroupAllowFromContext,
|
||||
} from "./bot/helpers.js";
|
||||
import type { TelegramContext } from "./bot/types.js";
|
||||
import {
|
||||
evaluateTelegramGroupBaseAccess,
|
||||
evaluateTelegramGroupPolicyAccess,
|
||||
@@ -51,7 +51,6 @@ import {
|
||||
parseModelCallbackData,
|
||||
type ProviderInfo,
|
||||
} from "./model-buttons.js";
|
||||
import { getSentPoll } from "./poll-vote-cache.js";
|
||||
import { buildInlineKeyboard } from "./send.js";
|
||||
import { wasSentByBot } from "./sent-message-cache.js";
|
||||
|
||||
@@ -844,65 +843,6 @@ export const registerTelegramHandlers = ({
|
||||
}
|
||||
});
|
||||
|
||||
bot.on("poll_answer", async (ctx) => {
|
||||
try {
|
||||
if (shouldSkipUpdate(ctx)) {
|
||||
return;
|
||||
}
|
||||
const pollAnswer = (ctx.update as { poll_answer?: unknown })?.poll_answer as
|
||||
| {
|
||||
poll_id?: string;
|
||||
user?: { id?: number; username?: string; first_name?: string };
|
||||
option_ids?: number[];
|
||||
}
|
||||
| undefined;
|
||||
if (!pollAnswer) {
|
||||
return;
|
||||
}
|
||||
const pollId = pollAnswer?.poll_id?.trim();
|
||||
if (!pollId) {
|
||||
return;
|
||||
}
|
||||
const pollMeta = getSentPoll(pollId);
|
||||
if (!pollMeta) {
|
||||
return;
|
||||
}
|
||||
if (pollMeta.accountId && pollMeta.accountId !== accountId) {
|
||||
return;
|
||||
}
|
||||
const userId = pollAnswer.user?.id;
|
||||
if (typeof userId !== "number") {
|
||||
return;
|
||||
}
|
||||
const optionIds = Array.isArray(pollAnswer.option_ids) ? pollAnswer.option_ids : [];
|
||||
const selected = optionIds.map((id) => pollMeta.options[id] ?? `option#${id + 1}`);
|
||||
const selectedText = selected.length > 0 ? selected.join(", ") : "(cleared vote)";
|
||||
const syntheticText = `Poll vote update: "${pollMeta.question}" -> ${selectedText}`;
|
||||
const syntheticMessage = {
|
||||
message_id: Date.now(),
|
||||
date: Math.floor(Date.now() / 1000),
|
||||
chat: {
|
||||
id: Number(pollMeta.chatId),
|
||||
type: String(pollMeta.chatId).startsWith("-") ? "supergroup" : "private",
|
||||
},
|
||||
from: {
|
||||
id: userId,
|
||||
is_bot: false,
|
||||
first_name: pollAnswer.user?.first_name ?? "User",
|
||||
username: pollAnswer.user?.username,
|
||||
},
|
||||
text: syntheticText,
|
||||
} as unknown as Message;
|
||||
const storeAllowFrom = await loadStoreAllowFrom();
|
||||
await processMessage(buildSyntheticContext(ctx, syntheticMessage), [], storeAllowFrom, {
|
||||
forceWasMentioned: true,
|
||||
messageIdOverride: `poll:${pollId}:${userId}:${Date.now()}`,
|
||||
});
|
||||
} catch (err) {
|
||||
runtime.error?.(danger(`poll_answer handler failed: ${String(err)}`));
|
||||
}
|
||||
});
|
||||
|
||||
// Handle group migration to supergroup (chat ID changes)
|
||||
bot.on("message:migrate_to_chat_id", async (ctx) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user