From 7d1f9bed868c6c714d24bda543c443bc4372b334 Mon Sep 17 00:00:00 2001 From: tangyanbiao Date: Mon, 27 Dec 2021 10:47:27 +0800 Subject: [PATCH] fix: update .env.example --- .env.example | 4 ++-- README.md | 9 ++++++--- api/txc.ts | 6 +++--- bot/feishu.ts | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.env.example b/.env.example index 8ade2b0..c114206 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ -BOTS='TELEGRAM' -FEISHU_TOKEN='' +BOTS='TELEGRAM,FEISHU' +FEISHU_BOT_URL='' TELEGRAM_TOKEN='' TELEGRAM_CHAT_ID='' \ No newline at end of file diff --git a/README.md b/README.md index a5fc407..c2b3806 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ # 腾讯兔小巢 Webhooks -接入飞书群机器人到腾讯兔小巢,当有新反馈时自动推送消息到飞书群机器人 +接入 webhook 到腾讯兔小巢,当有新反馈时自动推送消息到飞书群机器人,Telegram bot ## 如何使用 -- 在飞书新建一个群机器人,复制群机器人的 webhook 地址,详情见 [飞书开放平台·自定义机器人指南](https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN) -- 将 `.env.example` 重命名为 `.env.local`,`FEISHU_token`修改为你自己的群机器人 webhook TOKEN +- 将 `.env.example` 重命名为 `.env.local`,`BOTS` 选项设置你需要接入的机器人,用逗号隔开 `FEISHU_BOT_URL`修改为你自己飞书群机器人的 webhook url,同样,`TELEGRAM_TOKEN` 和 `TELEGRAM_CHAT_ID` 修改为你的 telegram bot - 点击右侧按钮一键部署到 Vercel [![Deploy](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/tyanbiao/txc-webhooks.git) - 在腾讯兔小巢中配置 Webhooks,`${your domain}/hooks/${product name}`,参考 [腾讯兔小巢·配置 Webhooks](https://txc.qq.com/helper/webHookGuide) + +## 如何创建机器人 +- 飞书: [飞书开放平台·自定义机器人指南](https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN) +- Telegram: [How do I create a bot?](https://core.telegram.org/bots#3-how-do-i-create-a-bot) \ No newline at end of file diff --git a/api/txc.ts b/api/txc.ts index 705d0dc..76717e5 100644 --- a/api/txc.ts +++ b/api/txc.ts @@ -34,7 +34,7 @@ function handleMessage(name: string, data: any): string { return `${name}有${action}: ${content}` } -function main(req: VercelRequest, res: VercelResponse) { +async function main(req: VercelRequest, res: VercelResponse) { if (req.method !== 'POST') { res.setHeader('Allow', 'POST') return res.status(405).end('Method Not Allowed') @@ -44,10 +44,10 @@ function main(req: VercelRequest, res: VercelResponse) { const product = req.query.product.toString() || 'Unknown' const content = handleMessage(product, req.body) if (bots.indexOf('TELEGRAM') >= 0) { - sendToTelegram(content) + await sendToTelegram(content) } if (bots.indexOf('FEISHU') >= 0) { - sendToFeishu(content) + await sendToFeishu(content) } return res.status(200).end('ok') } catch (e) { diff --git a/bot/feishu.ts b/bot/feishu.ts index 17d258c..4e37dbd 100644 --- a/bot/feishu.ts +++ b/bot/feishu.ts @@ -1,7 +1,7 @@ import fetch from 'node-fetch' export async function sendToFeishu(content: string) { - const URL = `https://open.feishu.cn/open-apis/bot/v2/hook/${process.env.FEISHU_TOKEN}` + const URL = process.env.FEISHU_BOT_URL const body = JSON.stringify({ "msg_type": "text", "content": {