Уведомления в Telegram (Телеграм): различия между версиями

Материал из Sprut.hub Wiki
(Новая страница: «<syntaxhighlight lang="js" line="1"> function sendToTelegramSilent(text) { HttpClient.POST("https://api.telegram.org") .path("bot" + "666666666:AABBCCddEeffggeeHH-IIJJkKLlMmnno_oP") .path("sendMessage") .queryString("chat_id", 666666666) .queryString("text", text) .queryString("parse_mode", "Markdown") .queryString("disable_notification", true) .send() } </syntaxhighlight>»)
Метка: wikieditor
 
Нет описания правки
Метка: wikieditor
Строка 1: Строка 1:
<syntaxhighlight lang="js" line="1">
<syntaxhighlight lang="js" line="1">
function sendToTelegramSilent(text) {
let chatIDs = ["666666666"];
     HttpClient.POST("https://api.telegram.org")
let token = "666666666:AABBCCddEeffggeeHH-IIJJkKLlMmnno_oP"
        .path("bot" + "666666666:AABBCCddEeffggeeHH-IIJJkKLlMmnno_oP")
 
        .path("sendMessage")
function sendToTelegram(text, notify) {
        .queryString("chat_id", 666666666)
     try {
        .queryString("text", text)
        if (!Array.isArray(text))
        .queryString("parse_mode", "Markdown")
            text = [text];
        .queryString("disable_notification", true)
 
         .send()
        chatIDs.forEach(function (chatID) {
}  
            HttpClient.POST("https://api.telegram.org")
                .path("bot" + token)
                .path("sendMessage")
                .queryString("chat_id", chatID)
                .queryString("text", text.join("\n"))
                .queryString("parse_mode", "Markdown")
                .queryString("disable_notification", notify == null ? false : !notify)
                .send()
        })
    } catch (e) {
         log.error(e.message);
    }
}
</syntaxhighlight>
</syntaxhighlight>

Версия от 18:53, 14 ноября 2022

let chatIDs = ["666666666"];
let token = "666666666:AABBCCddEeffggeeHH-IIJJkKLlMmnno_oP"

function sendToTelegram(text, notify) {
    try {
        if (!Array.isArray(text))
            text = [text];

        chatIDs.forEach(function (chatID) {
            HttpClient.POST("https://api.telegram.org")
                .path("bot" + token)
                .path("sendMessage")
                .queryString("chat_id", chatID)
                .queryString("text", text.join("\n"))
                .queryString("parse_mode", "Markdown")
                .queryString("disable_notification", notify == null ? false : !notify)
                .send()
        })
    } catch (e) {
        log.error(e.message);
    }
}