2021-12-21 06:57:38 +00:00
|
|
|
import fetch from 'node-fetch'
|
2021-12-26 18:10:09 +00:00
|
|
|
|
2021-12-21 06:57:38 +00:00
|
|
|
export async function sendToTelegram(text: string) {
|
2021-12-21 06:31:29 +00:00
|
|
|
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)
|
|
|
|
}
|
2021-12-26 18:10:09 +00:00
|
|
|
}
|