txc-webhooks/bot/telegram.ts

15 lines
457 B
TypeScript
Raw Normal View History

2021-12-21 06:31:29 +00:00
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)
}
}