From 039181afe419aca909a403c2ac90a441192d079f Mon Sep 17 00:00:00 2001 From: Xtao_dada Date: Mon, 27 Dec 2021 02:03:53 +0800 Subject: [PATCH 1/2] Update txc.ts --- api/txc.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/txc.ts b/api/txc.ts index 705d0dc..3159406 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) { @@ -56,4 +56,4 @@ function main(req: VercelRequest, res: VercelResponse) { } } -export default main \ No newline at end of file +export default main From 044fc276afcc467824a6a0826b4ea36c9933682d Mon Sep 17 00:00:00 2001 From: Xtao_dada Date: Mon, 27 Dec 2021 02:10:09 +0800 Subject: [PATCH 2/2] Update telegram.ts --- bot/telegram.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bot/telegram.ts b/bot/telegram.ts index ed1903b..2c9f5fa 100644 --- a/bot/telegram.ts +++ b/bot/telegram.ts @@ -1,4 +1,5 @@ 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}` @@ -13,4 +14,4 @@ export async function sendToTelegram(text: string) { if (!data.ok) { console.error(data.StatusMessage) } -} \ No newline at end of file +}