|
1 |
| -// @version 0.0.3 新增了环境变量,以解决aircode 的时不时抽风问题 |
| 1 | +// @version 0.0.4 新增自检能力 |
2 | 2 | const aircode = require('aircode');
|
3 | 3 | const lark = require('@larksuiteoapi/node-sdk');
|
4 | 4 | var axios = require('axios');
|
@@ -77,7 +77,88 @@ async function getOpenAIReply(content) {
|
77 | 77 | return response.data.choices[0].text.replace("\n\n", "")
|
78 | 78 | }
|
79 | 79 |
|
| 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 | + |
80 | 157 | module.exports = async function (params, context) {
|
| 158 | + // 自检查逻辑 |
| 159 | + if(!params.hasOwnProperty("header") || context.trigger == "DEBUG"){ |
| 160 | + return await doctor(); |
| 161 | + } |
81 | 162 | // 处理飞书开放平台的服务端校验
|
82 | 163 | if (params.type == "url_verification") {
|
83 | 164 | return {
|
|
0 commit comments