fix: 修复bug

This commit is contained in:
tangyanbiao 2021-12-21 14:57:38 +08:00
parent d3971b01c7
commit 02e161b97d
3 changed files with 10 additions and 3 deletions

View File

@ -1,4 +1,6 @@
import {VercelRequest, VercelResponse} from '@vercel/node' import {VercelRequest, VercelResponse} from '@vercel/node'
import { sendToTelegram } from '../bot/telegram'
import { sendToFeishu } from '../bot/feishu'
function handleMessage(name: string, data: any): string { function handleMessage(name: string, data: any): string {
let action = '' let action = ''
@ -25,7 +27,9 @@ function handleMessage(name: string, data: any): string {
content = data?.payload?.reply?.content content = data?.payload?.reply?.content
break break
default: default:
throw new Error('Bad Request') action = data.type
content = JSON.stringify(data?.payload)
break
} }
return `${name}${action}: ${content}` return `${name}${action}: ${content}`
} }

View File

@ -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 URL = `https://open.feishu.cn/open-apis/bot/v2/hook/${process.env.FEISHU_TOKEN}`
const body = JSON.stringify({ const body = JSON.stringify({
"msg_type": "text", "msg_type": "text",

View File

@ -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 URL = `https://api.telegram.org/bot${process.env.TELEGRAM_TOKEN}/sendMessage`
const body = `chat_id=${process.env.TELEGRAM_CHAT_ID}&text=${text}` const body = `chat_id=${process.env.TELEGRAM_CHAT_ID}&text=${text}`
const res = await fetch(URL, { const res = await fetch(URL, {