Merge pull request #1 from xtaodada/patch-1
[fix] await outside async function
This commit is contained in:
commit
bbcf0a7ede
@ -34,7 +34,7 @@ function handleMessage(name: string, data: any): string {
|
|||||||
return `${name}有${action}: ${content}`
|
return `${name}有${action}: ${content}`
|
||||||
}
|
}
|
||||||
|
|
||||||
function main(req: VercelRequest, res: VercelResponse) {
|
async function main(req: VercelRequest, res: VercelResponse) {
|
||||||
if (req.method !== 'POST') {
|
if (req.method !== 'POST') {
|
||||||
res.setHeader('Allow', 'POST')
|
res.setHeader('Allow', 'POST')
|
||||||
return res.status(405).end('Method Not Allowed')
|
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 product = req.query.product.toString() || 'Unknown'
|
||||||
const content = handleMessage(product, req.body)
|
const content = handleMessage(product, req.body)
|
||||||
if (bots.indexOf('TELEGRAM') >= 0) {
|
if (bots.indexOf('TELEGRAM') >= 0) {
|
||||||
sendToTelegram(content)
|
await sendToTelegram(content)
|
||||||
}
|
}
|
||||||
if (bots.indexOf('FEISHU') >= 0) {
|
if (bots.indexOf('FEISHU') >= 0) {
|
||||||
sendToFeishu(content)
|
await sendToFeishu(content)
|
||||||
}
|
}
|
||||||
return res.status(200).end('ok')
|
return res.status(200).end('ok')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import fetch from 'node-fetch'
|
import fetch from 'node-fetch'
|
||||||
|
|
||||||
export async function sendToTelegram(text: string) {
|
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}`
|
||||||
|
Loading…
Reference in New Issue
Block a user