mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: add Telegram bot config UI (#1747)
* Add retry wait for telegram.GetUpdates * Add support to set telegram robot token from UI * Change validator of UserSettingTelegramUserID * Add support to set telegram user id from UI * Fix typescript check * Add validator for SystemSettingTelegramRobotTokenName * Optimize error notice while config telegram params * Change for review * Fix telegram user id could not be empty * Fix telegram robot could not be empty * Fix for eslint (again) * Update web/src/components/Settings/SystemSection.tsx --------- Co-authored-by: Athurg Feng <athurg@gooth.org> Co-authored-by: boojack <stevenlgtm@gmail.com>
This commit is contained in:
@ -32,6 +32,7 @@ const SystemSection = () => {
|
||||
disablePublicMemos: systemStatus.disablePublicMemos,
|
||||
maxUploadSizeMiB: systemStatus.maxUploadSizeMiB,
|
||||
});
|
||||
const [telegramRobotToken, setTelegramRobotToken] = useState<string>("");
|
||||
const [openAIConfig, setOpenAIConfig] = useState<OpenAIConfig>({
|
||||
key: "",
|
||||
host: "",
|
||||
@ -47,6 +48,11 @@ const SystemSection = () => {
|
||||
if (openAIConfigSetting) {
|
||||
setOpenAIConfig(JSON.parse(openAIConfigSetting.value));
|
||||
}
|
||||
|
||||
const telegramRobotSetting = systemSettings.find((setting) => setting.name === "telegram-robot-token");
|
||||
if (telegramRobotSetting) {
|
||||
setTelegramRobotToken(telegramRobotSetting.value);
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
||||
@ -126,6 +132,24 @@ const SystemSection = () => {
|
||||
toast.success("OpenAI Config updated");
|
||||
};
|
||||
|
||||
const handleTelegramRobotTokenChanged = (value: string) => {
|
||||
setTelegramRobotToken(value);
|
||||
};
|
||||
|
||||
const handleSaveTelegramRobotToken = async () => {
|
||||
try {
|
||||
await api.upsertSystemSetting({
|
||||
name: "telegram-robot-token",
|
||||
value: telegramRobotToken,
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
toast.error(error.response.data.message);
|
||||
return;
|
||||
}
|
||||
toast.success("OpenAI Config updated");
|
||||
};
|
||||
|
||||
const handleAdditionalStyleChanged = (value: string) => {
|
||||
setState({
|
||||
...state,
|
||||
@ -246,6 +270,27 @@ const SystemSection = () => {
|
||||
/>
|
||||
</div>
|
||||
<Divider className="!mt-3 !my-4" />
|
||||
<div className="form-label">
|
||||
<div className="flex flex-row items-center">
|
||||
<span className="text-sm mr-1">{t("setting.system-section.telegram-robot-token")}</span>
|
||||
<HelpButton
|
||||
hint={t("setting.system-section.telegram-robot-token-description")}
|
||||
url="https://core.telegram.org/bots#how-do-i-create-a-bot"
|
||||
/>
|
||||
</div>
|
||||
<Button onClick={handleSaveTelegramRobotToken}>{t("common.save")}</Button>
|
||||
</div>
|
||||
<Input
|
||||
className="w-full"
|
||||
sx={{
|
||||
fontFamily: "monospace",
|
||||
fontSize: "14px",
|
||||
}}
|
||||
placeholder={t("setting.system-section.telegram-robot-token-placeholder")}
|
||||
value={telegramRobotToken}
|
||||
onChange={(event) => handleTelegramRobotTokenChanged(event.target.value)}
|
||||
/>
|
||||
<Divider className="!mt-3 !my-4" />
|
||||
<div className="form-label">
|
||||
<div className="flex flex-row items-center">
|
||||
<span className="text-sm mr-1">{t("setting.system-section.openai-api-key")}</span>
|
||||
|
Reference in New Issue
Block a user