Send to Telegram

Send from web to telegram using script

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Send to Telegram
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Send from web to telegram using script
// @match        *
// @grant        GM_xmlhttpRequest
// @grant        unsafeWindow
// @connect      api.telegram.org
// @sandbox      JavaScript
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const BOT_TOKEN = "enter_bot_token_here";
    const CHAT_ID = "enter_chat_id_here"; //https://gist.github.com/nafiesl/4ad622f344cd1dc3bb1ecbe468ff9f8a

    window.addEventListener("message", function(event) {
        if (event.data?.type === "<DEFINE-YOUR-TYPE-HERE>") {
            const a = event.data.payload;
            const content = a?.data?.msgs?.[0]?.content || "[No content]";
            const sender = a?.data?.msgs?.[0]?.dName || "Unknown";

            const text = `💬 Message from ${sender}:\n${content}`;

            GM_xmlhttpRequest({
                method: "POST",
                url: `https://api.telegram.org/bot${BOT_TOKEN}/sendMessage`,
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded"
                },
                data: `chat_id=${CHAT_ID}&text=${encodeURIComponent(text)}`,
                onload: function(response) {
                    console.log("Send Telegram:", response.responseText);
                },
                onerror: function(err) {
                    console.error("Error :", err);
                }
            });

        }
    });
})();

/*
How to use: 
From another instance, you can use:
window.postMessage({
    type: "ZALO_DATA",
    payload: parsed
}, "*");
to send data to this handler
*/