Skip to content

Commit 4572e48

Browse files
authored
0.0.4 self check
1 parent 5cd8c3e commit 4572e48

File tree

1 file changed

+82
-1
lines changed

1 file changed

+82
-1
lines changed

event.js

+82-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @version 0.0.3 新增了环境变量,以解决aircode 的时不时抽风问题
1+
// @version 0.0.4 新增自检能力
22
const aircode = require('aircode');
33
const lark = require('@larksuiteoapi/node-sdk');
44
var axios = require('axios');
@@ -77,7 +77,88 @@ async function getOpenAIReply(content) {
7777
return response.data.choices[0].text.replace("\n\n", "")
7878
}
7979

80+
// 自检函数
81+
async function doctor() {
82+
83+
if(FEISHU_APP_ID == ""){
84+
return {
85+
code: 1,
86+
message:{
87+
zh_CN: "你没有配置飞书应用的 AppID,请检查 & 部署后重试",
88+
en_US: "Here is no FeiSHu APP id, please check & re-Deploy & call again"
89+
}
90+
}
91+
}
92+
if(!FEISHU_APP_ID.startsWith("cli_")){
93+
return {
94+
code: 1,
95+
message:{
96+
zh_CN: "你配置的飞书应用的 AppID 是错误的,请检查后重试。飞书应用的 APPID 以 cli_ 开头。",
97+
en_US: "Your FeiShu App ID is Wrong, Please Check and call again. FeiShu APPID must Start with cli"
98+
}
99+
}
100+
}
101+
if(FEISHU_APP_SECRET == ""){
102+
return {
103+
code: 1,
104+
message:{
105+
zh_CN: "你没有配置飞书应用的 Secret,请检查 & 部署后重试",
106+
en_US: "Here is no FeiSHu APP Secret, please check & re-Deploy & call again"
107+
}
108+
}
109+
}
110+
111+
if(FEISHU_BOTNAME == ""){
112+
return {
113+
code: 1,
114+
message:{
115+
zh_CN: "你没有配置飞书应用的名称,请检查 & 部署后重试",
116+
en_US: "Here is no FeiSHu APP Name, please check & re-Deploy & call again"
117+
}
118+
}
119+
}
120+
121+
if(OPENAI_KEY == ""){
122+
return {
123+
code: 1,
124+
message:{
125+
zh_CN: "你没有配置 OpenAI 的 Key,请检查 & 部署后重试",
126+
en_US: "Here is no OpenAI Key, please check & re-Deploy & call again"
127+
}
128+
}
129+
}
130+
131+
if(!OPENAI_KEY.startsWith("sk-")){
132+
return {
133+
code: 1,
134+
message:{
135+
zh_CN: "你配置的 OpenAI Key 是错误的,请检查后重试。飞书应用的 APPID 以 cli_ 开头。",
136+
en_US: "Your OpenAI Key is Wrong, Please Check and call again. FeiShu APPID must Start with cli"
137+
}
138+
}
139+
}
140+
return {
141+
code: 0,
142+
message: {
143+
zh_CN:
144+
"✅ Configuration is correct, you can use this bot in your FeiShu App",
145+
en_US:
146+
"✅ 配置成功,接下来你可以在飞书应用当中使用机器人来完成你的工作。",
147+
},
148+
meta:{
149+
FEISHU_APP_ID,
150+
OPENAI_MODEL,
151+
OPENAI_MAX_TOKEN,
152+
FEISHU_BOTNAME
153+
}
154+
};
155+
}
156+
80157
module.exports = async function (params, context) {
158+
// 自检查逻辑
159+
if(!params.hasOwnProperty("header") || context.trigger == "DEBUG"){
160+
return await doctor();
161+
}
81162
// 处理飞书开放平台的服务端校验
82163
if (params.type == "url_verification") {
83164
return {

0 commit comments

Comments
 (0)