import { useTranslation } from "react-i18next" import type { ChannelConfig } from "@/api/channels" import { getSecretInputPlaceholder } from "@/components/channels/channel-config-fields" import { Field, KeyInput, SwitchCardField } from "@/components/shared-form" import { Card, CardContent } from "@/components/ui/card" import { Input } from "@/components/ui/input" interface TelegramFormProps { config: ChannelConfig onChange: (key: string, value: unknown) => void configuredSecrets: string[] fieldErrors?: Record } function asString(value: unknown): string { return typeof value === "string" ? value : "" } function asStringArray(value: unknown): string[] { if (!Array.isArray(value)) return [] return value.filter((item): item is string => typeof item === "string") } function asRecord(value: unknown): Record { if (value && typeof value === "object" && !Array.isArray(value)) { return value as Record } return {} } function asBool(value: unknown): boolean { return value === true } export function TelegramForm({ config, onChange, configuredSecrets, fieldErrors = {}, }: TelegramFormProps) { const { t } = useTranslation() const typingConfig = asRecord(config.typing) const placeholderConfig = asRecord(config.placeholder) const placeholderEnabled = asBool(placeholderConfig.enabled) return (
onChange("_token", v)} placeholder={getSecretInputPlaceholder( configuredSecrets, "token", t("channels.field.secretHintSet"), t("channels.field.tokenPlaceholder"), )} /> onChange("base_url", e.target.value)} placeholder="https://api.telegram.org" /> onChange("proxy", e.target.value)} placeholder="http://127.0.0.1:7890" /> onChange( "allow_from", e.target.value .split(",") .map((s: string) => s.trim()) .filter(Boolean), ) } placeholder={t("channels.field.allowFromPlaceholder")} />
onChange("typing", { ...typingConfig, enabled: checked }) } ariaLabel={t("channels.field.typingEnabled")} />
onChange("placeholder", { ...placeholderConfig, enabled: checked, }) } ariaLabel={t("channels.field.placeholderEnabled")} > {placeholderEnabled && (
onChange("placeholder", { ...placeholderConfig, text: e.target.value, }) } placeholder={t("channels.field.placeholderText")} aria-label={t("channels.field.placeholderText")} />
)}
) }