From 02e161b97d8de2611bd9280bc46254135e2ffb8e Mon Sep 17 00:00:00 2001 From: tangyanbiao Date: Tue, 21 Dec 2021 14:57:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/txc.ts | 6 +++++- bot/feishu.ts | 4 +++- bot/telegram.ts | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/api/txc.ts b/api/txc.ts index 0bf795c..76717e5 100644 --- a/api/txc.ts +++ b/api/txc.ts @@ -1,4 +1,6 @@ import {VercelRequest, VercelResponse} from '@vercel/node' +import { sendToTelegram } from '../bot/telegram' +import { sendToFeishu } from '../bot/feishu' function handleMessage(name: string, data: any): string { let action = '' @@ -25,7 +27,9 @@ function handleMessage(name: string, data: any): string { content = data?.payload?.reply?.content break default: - throw new Error('Bad Request') + action = data.type + content = JSON.stringify(data?.payload) + break } return `${name}有${action}: ${content}` } diff --git a/bot/feishu.ts b/bot/feishu.ts index 61c6f59..17d258c 100644 --- a/bot/feishu.ts +++ b/bot/feishu.ts @@ -1,4 +1,6 @@ -async function sendToFeishu(content: string) { +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 body = JSON.stringify({ "msg_type": "text", diff --git a/bot/telegram.ts b/bot/telegram.ts index f8c4780..ed1903b 100644 --- a/bot/telegram.ts +++ b/bot/telegram.ts @@ -1,4 +1,5 @@ -async function sendToTelegram(text: string) { +import fetch from 'node-fetch' +export async function sendToTelegram(text: string) { const URL = `https://api.telegram.org/bot${process.env.TELEGRAM_TOKEN}/sendMessage` const body = `chat_id=${process.env.TELEGRAM_CHAT_ID}&text=${text}` const res = await fetch(URL, {