txc-webhooks/bot/telegram.ts
2021-12-27 02:10:09 +08:00

18 lines
497 B
TypeScript

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, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body,
})
const data = await res.json()
if (!data.ok) {
console.error(data.StatusMessage)
}
}