机器人增加关键词设置
This commit is contained in:
parent
a3201b9d50
commit
b25614f75c
3 changed files with 55 additions and 4 deletions
11
.env.example
11
.env.example
|
|
@ -1,3 +1,12 @@
|
||||||
OPENAI_API_KEY=sk-your-key-here
|
OPENAI_API_KEY=sk-your-key-here
|
||||||
OPENAI_BASE_URL=https://api.openai.com/v1
|
OPENAI_BASE_URL=https://api.openai.com/v1
|
||||||
OPENAI_MODEL=gpt-4o
|
OPENAI_MODEL=gpt-4o
|
||||||
|
|
||||||
|
# Notifications (Optional)
|
||||||
|
# Configure Webhook URL and Security Keyword for your IM platform
|
||||||
|
FEISHU_WEBHOOK=
|
||||||
|
FEISHU_KEYWORD=
|
||||||
|
DINGTALK_WEBHOOK=
|
||||||
|
DINGTALK_KEYWORD=
|
||||||
|
WECOM_WEBHOOK=
|
||||||
|
WECOM_KEYWORD=
|
||||||
29
src/index.ts
29
src/index.ts
|
|
@ -38,8 +38,11 @@ interface AppConfig {
|
||||||
tavilyApiKey?: string;
|
tavilyApiKey?: string;
|
||||||
autoConfirm?: boolean;
|
autoConfirm?: boolean;
|
||||||
feishuWebhook?: string;
|
feishuWebhook?: string;
|
||||||
|
feishuKeyword?: string;
|
||||||
dingtalkWebhook?: string;
|
dingtalkWebhook?: string;
|
||||||
|
dingtalkKeyword?: string;
|
||||||
wecomWebhook?: string;
|
wecomWebhook?: string;
|
||||||
|
wecomKeyword?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadJsonConfig(filePath: string): AppConfig {
|
function loadJsonConfig(filePath: string): AppConfig {
|
||||||
|
|
@ -222,6 +225,12 @@ async function runSetup() {
|
||||||
: 'Feishu Webhook (Optional):',
|
: 'Feishu Webhook (Optional):',
|
||||||
mask: '*'
|
mask: '*'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
name: 'feishuKeyword',
|
||||||
|
message: 'Feishu Security Keyword (Optional):',
|
||||||
|
default: currentConfig.feishuKeyword
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: 'password',
|
type: 'password',
|
||||||
name: 'dingtalkWebhook',
|
name: 'dingtalkWebhook',
|
||||||
|
|
@ -230,6 +239,12 @@ async function runSetup() {
|
||||||
: 'DingTalk Webhook (Optional):',
|
: 'DingTalk Webhook (Optional):',
|
||||||
mask: '*'
|
mask: '*'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
name: 'dingtalkKeyword',
|
||||||
|
message: 'DingTalk Security Keyword (Optional):',
|
||||||
|
default: currentConfig.dingtalkKeyword
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: 'password',
|
type: 'password',
|
||||||
name: 'wecomWebhook',
|
name: 'wecomWebhook',
|
||||||
|
|
@ -237,12 +252,21 @@ async function runSetup() {
|
||||||
? `WeCom Webhook (Leave empty to keep ${maskSecret(currentConfig.wecomWebhook)}):`
|
? `WeCom Webhook (Leave empty to keep ${maskSecret(currentConfig.wecomWebhook)}):`
|
||||||
: 'WeCom Webhook (Optional):',
|
: 'WeCom Webhook (Optional):',
|
||||||
mask: '*'
|
mask: '*'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
name: 'wecomKeyword',
|
||||||
|
message: 'WeCom Security Keyword (Optional):',
|
||||||
|
default: currentConfig.wecomKeyword
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
notifyConfig = {
|
notifyConfig = {
|
||||||
feishuWebhook: notifyAnswers.feishuWebhook || currentConfig.feishuWebhook,
|
feishuWebhook: notifyAnswers.feishuWebhook || currentConfig.feishuWebhook,
|
||||||
|
feishuKeyword: notifyAnswers.feishuKeyword || currentConfig.feishuKeyword,
|
||||||
dingtalkWebhook: notifyAnswers.dingtalkWebhook || currentConfig.dingtalkWebhook,
|
dingtalkWebhook: notifyAnswers.dingtalkWebhook || currentConfig.dingtalkWebhook,
|
||||||
wecomWebhook: notifyAnswers.wecomWebhook || currentConfig.wecomWebhook
|
dingtalkKeyword: notifyAnswers.dingtalkKeyword || currentConfig.dingtalkKeyword,
|
||||||
|
wecomWebhook: notifyAnswers.wecomWebhook || currentConfig.wecomWebhook,
|
||||||
|
wecomKeyword: notifyAnswers.wecomKeyword || currentConfig.wecomKeyword
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -302,8 +326,11 @@ async function runChat(queryParts: string[], options: any) {
|
||||||
if (process.env.SMTP_PASS) fullConfig.smtpPass = process.env.SMTP_PASS;
|
if (process.env.SMTP_PASS) fullConfig.smtpPass = process.env.SMTP_PASS;
|
||||||
if (process.env.TAVILY_API_KEY) fullConfig.tavilyApiKey = process.env.TAVILY_API_KEY;
|
if (process.env.TAVILY_API_KEY) fullConfig.tavilyApiKey = process.env.TAVILY_API_KEY;
|
||||||
if (process.env.FEISHU_WEBHOOK) fullConfig.feishuWebhook = process.env.FEISHU_WEBHOOK;
|
if (process.env.FEISHU_WEBHOOK) fullConfig.feishuWebhook = process.env.FEISHU_WEBHOOK;
|
||||||
|
if (process.env.FEISHU_KEYWORD) fullConfig.feishuKeyword = process.env.FEISHU_KEYWORD;
|
||||||
if (process.env.DINGTALK_WEBHOOK) fullConfig.dingtalkWebhook = process.env.DINGTALK_WEBHOOK;
|
if (process.env.DINGTALK_WEBHOOK) fullConfig.dingtalkWebhook = process.env.DINGTALK_WEBHOOK;
|
||||||
|
if (process.env.DINGTALK_KEYWORD) fullConfig.dingtalkKeyword = process.env.DINGTALK_KEYWORD;
|
||||||
if (process.env.WECOM_WEBHOOK) fullConfig.wecomWebhook = process.env.WECOM_WEBHOOK;
|
if (process.env.WECOM_WEBHOOK) fullConfig.wecomWebhook = process.env.WECOM_WEBHOOK;
|
||||||
|
if (process.env.WECOM_KEYWORD) fullConfig.wecomKeyword = process.env.WECOM_KEYWORD;
|
||||||
|
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
console.log(chalk.yellow("API Key not found."));
|
console.log(chalk.yellow("API Key not found."));
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,11 @@ import { ToolModule } from './interface.js';
|
||||||
|
|
||||||
export const NotifyTool: ToolModule = {
|
export const NotifyTool: ToolModule = {
|
||||||
name: "Group Bot Notification",
|
name: "Group Bot Notification",
|
||||||
configKeys: ["feishuWebhook", "dingtalkWebhook", "wecomWebhook"],
|
configKeys: [
|
||||||
|
"feishuWebhook", "feishuKeyword",
|
||||||
|
"dingtalkWebhook", "dingtalkKeyword",
|
||||||
|
"wecomWebhook", "wecomKeyword"
|
||||||
|
],
|
||||||
definition: {
|
definition: {
|
||||||
type: "function",
|
type: "function",
|
||||||
function: {
|
function: {
|
||||||
|
|
@ -26,14 +30,23 @@ export const NotifyTool: ToolModule = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handler: async (args: any, config: any) => {
|
handler: async (args: any, config: any) => {
|
||||||
const { platform, content } = args;
|
let { platform, content } = args;
|
||||||
let webhookUrl = '';
|
let webhookUrl = '';
|
||||||
let payload = {};
|
let payload = {};
|
||||||
|
|
||||||
|
// Helper to ensure security keyword is present
|
||||||
|
const ensureKeyword = (envKey: string, configKey: string) => {
|
||||||
|
const keyword = config[configKey] || process.env[envKey];
|
||||||
|
if (keyword && !content.includes(keyword)) {
|
||||||
|
content = `[${keyword}] ${content}`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// 1. Determine Webhook URL and Payload Format
|
// 1. Determine Webhook URL and Payload Format
|
||||||
switch (platform) {
|
switch (platform) {
|
||||||
case 'feishu':
|
case 'feishu':
|
||||||
webhookUrl = config.feishuWebhook || process.env.FEISHU_WEBHOOK;
|
webhookUrl = config.feishuWebhook || process.env.FEISHU_WEBHOOK;
|
||||||
|
ensureKeyword('FEISHU_KEYWORD', 'feishuKeyword');
|
||||||
if (!webhookUrl) return "Error: Feishu Webhook URL is not configured.";
|
if (!webhookUrl) return "Error: Feishu Webhook URL is not configured.";
|
||||||
payload = {
|
payload = {
|
||||||
msg_type: "text",
|
msg_type: "text",
|
||||||
|
|
@ -43,6 +56,7 @@ export const NotifyTool: ToolModule = {
|
||||||
|
|
||||||
case 'dingtalk':
|
case 'dingtalk':
|
||||||
webhookUrl = config.dingtalkWebhook || process.env.DINGTALK_WEBHOOK;
|
webhookUrl = config.dingtalkWebhook || process.env.DINGTALK_WEBHOOK;
|
||||||
|
ensureKeyword('DINGTALK_KEYWORD', 'dingtalkKeyword');
|
||||||
if (!webhookUrl) return "Error: DingTalk Webhook URL is not configured.";
|
if (!webhookUrl) return "Error: DingTalk Webhook URL is not configured.";
|
||||||
payload = {
|
payload = {
|
||||||
msgtype: "text",
|
msgtype: "text",
|
||||||
|
|
@ -52,6 +66,7 @@ export const NotifyTool: ToolModule = {
|
||||||
|
|
||||||
case 'wecom':
|
case 'wecom':
|
||||||
webhookUrl = config.wecomWebhook || process.env.WECOM_WEBHOOK;
|
webhookUrl = config.wecomWebhook || process.env.WECOM_WEBHOOK;
|
||||||
|
ensureKeyword('WECOM_KEYWORD', 'wecomKeyword');
|
||||||
if (!webhookUrl) return "Error: WeCom Webhook URL is not configured.";
|
if (!webhookUrl) return "Error: WeCom Webhook URL is not configured.";
|
||||||
payload = {
|
payload = {
|
||||||
msgtype: "text",
|
msgtype: "text",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue