mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 20:50:19 +08:00
fix: Support Telegram Notification provider (#2225)
* fear: support telegram provider * fix: fix telegram logo * fix: fix telegram bot package * Update telegram.go * Update notification.go --------- Co-authored-by: hsluoyz <hsluoyz@qq.com>
This commit is contained in:
@ -20,6 +20,7 @@ import * as Setting from "./Setting";
|
||||
import i18next from "i18next";
|
||||
import {authConfig} from "./auth/Auth";
|
||||
import * as ProviderEditTestEmail from "./common/TestEmailWidget";
|
||||
import * as ProviderNotification from "./common/TestNotificationWidget";
|
||||
import * as ProviderEditTestSms from "./common/TestSmsWidget";
|
||||
import copy from "copy-to-clipboard";
|
||||
import {CaptchaPreview} from "./common/CaptchaPreview";
|
||||
@ -275,6 +276,11 @@ class ProviderEditPage extends React.Component {
|
||||
text = i18next.t("provider:App ID");
|
||||
tooltip = i18next.t("provider:App ID - Tooltip");
|
||||
}
|
||||
} else if (provider.category === "Notification") {
|
||||
if (provider.type === "Telegram") {
|
||||
text = i18next.t("provider:Api Token");
|
||||
tooltip = i18next.t("provider:Api Token - Tooltip");
|
||||
}
|
||||
}
|
||||
|
||||
if (text === "" && tooltip === "") {
|
||||
@ -379,6 +385,8 @@ class ProviderEditPage extends React.Component {
|
||||
this.updateProviderField("type", "Default");
|
||||
} else if (value === "Web3") {
|
||||
this.updateProviderField("type", "MetaMask");
|
||||
} else if (value === "Notification") {
|
||||
this.updateProviderField("type", "Telegram");
|
||||
}
|
||||
})}>
|
||||
{
|
||||
@ -391,6 +399,7 @@ class ProviderEditPage extends React.Component {
|
||||
{id: "SMS", name: "SMS"},
|
||||
{id: "Storage", name: "Storage"},
|
||||
{id: "Web3", name: "Web3"},
|
||||
{id: "Notification", name: "Notification"},
|
||||
]
|
||||
.sort((a, b) => a.name.localeCompare(b.name))
|
||||
.map((providerCategory, index) => <Option key={index} value={providerCategory.id}>{providerCategory.name}</Option>)
|
||||
@ -555,7 +564,7 @@ class ProviderEditPage extends React.Component {
|
||||
(this.state.provider.category === "Captcha" && this.state.provider.type === "Default") ||
|
||||
(this.state.provider.category === "SMS" && this.state.provider.type === "Custom HTTP SMS") ||
|
||||
(this.state.provider.category === "Web3") ||
|
||||
(this.state.provider.category === "Storage" && this.state.provider.type === "Local File System") ? null : (
|
||||
(this.state.provider.category === "Storage" && this.state.provider.type === "Local File System" || (this.state.provider.category === "Notification")) ? null : (
|
||||
<React.Fragment>
|
||||
<Row style={{marginTop: "20px"}} >
|
||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||
@ -759,7 +768,34 @@ class ProviderEditPage extends React.Component {
|
||||
}
|
||||
{this.getAppIdRow(this.state.provider)}
|
||||
{
|
||||
this.state.provider.category === "Email" ? (
|
||||
this.state.provider.category === "Notification" ? (
|
||||
<React.Fragment>
|
||||
<Row style={{marginTop: "20px"}} >
|
||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||
{Setting.getLabel(i18next.t("provider:Notification content"), i18next.t("provider:Notification content - Tooltip"))} :
|
||||
</Col>
|
||||
<Col span={22} >
|
||||
<TextArea autoSize={{minRows: 3, maxRows: 100}} value={this.state.provider.content} onChange={e => {
|
||||
this.updateProviderField("content", e.target.value);
|
||||
}} />
|
||||
</Col>
|
||||
</Row>
|
||||
<Row style={{marginTop: "20px"}} >
|
||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||
{Setting.getLabel(i18next.t("provider:Chat Id"), i18next.t("provider:Chat Id - Tooltip"))} :
|
||||
</Col>
|
||||
<Col span={4} >
|
||||
<Input value={this.state.provider.receiver} placeholder = {i18next.t("user:Input your chat id")} onChange={e => {
|
||||
this.updateProviderField("receiver", e.target.value);
|
||||
}} />
|
||||
</Col>
|
||||
<Button style={{marginLeft: "10px", marginBottom: "5px"}} type="primary"
|
||||
onClick={() => ProviderNotification.sendTestNotification(this.state.provider, this.state.provider.receiver)} >
|
||||
{i18next.t("provider:Send Testing Notification")}
|
||||
</Button>
|
||||
</Row>
|
||||
</React.Fragment>
|
||||
) : this.state.provider.category === "Email" ? (
|
||||
<React.Fragment>
|
||||
<Row style={{marginTop: "20px"}} >
|
||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||
|
@ -271,6 +271,12 @@ export const OtherProviderInfo = {
|
||||
url: "https://onboard.blocknative.com/",
|
||||
},
|
||||
},
|
||||
Notification: {
|
||||
"Telegram": {
|
||||
logo: `${StaticBaseUrl}/img/social_telegram.png`,
|
||||
url: "https://telegram.org/",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export function initCountries() {
|
||||
@ -957,6 +963,10 @@ export function getProviderTypeOptions(category) {
|
||||
{id: "MetaMask", name: "MetaMask"},
|
||||
{id: "Web3Onboard", name: "Web3-Onboard"},
|
||||
]);
|
||||
} else if (category === "Notification") {
|
||||
return ([
|
||||
{id: "Telegram", name: "Telegram"},
|
||||
]);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
42
web/src/common/TestNotificationWidget.js
Normal file
42
web/src/common/TestNotificationWidget.js
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright 2023 The Casdoor Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import * as Setting from "../Setting";
|
||||
import i18next from "i18next";
|
||||
|
||||
export function sendTestNotification(provider, notification) {
|
||||
testNotificationProvider(provider, notification)
|
||||
.then((res) => {
|
||||
if (res.status === "ok") {
|
||||
Setting.showMessage("success", `${i18next.t("provider:Notification sent successfully")}`);
|
||||
} else {
|
||||
Setting.showMessage("error", res.msg);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
||||
});
|
||||
}
|
||||
|
||||
function testNotificationProvider(provider, email = "") {
|
||||
const notificationForm = {
|
||||
content: provider.content,
|
||||
};
|
||||
|
||||
return fetch(`${Setting.ServerUrl}/api/send-notification?provider=` + provider.name, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
body: JSON.stringify(notificationForm),
|
||||
}).then(res => res.json());
|
||||
}
|
Reference in New Issue
Block a user