Created
March 3, 2021 14:58
-
-
Save mahdyar/47348a67eb83d336d4bb0556a40bcc32 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addEventListener("fetch", (event) => { | |
event.respondWith(handleRequest(event)); | |
}); | |
let data = { | |
ok: false, | |
}; | |
async function handleRequest(event) { | |
if (event.request.method == "POST") { | |
let body = await event.request.json(); | |
if (body.url && body.title && body.telemark_code) { | |
const url = body.url; | |
const title = body.title; | |
const telemark_code = body.telemark_code; | |
const api = | |
"https://api.telegram.org/bot" + | |
API_KEY + | |
"/sendMessage?chat_id=" + | |
telemark_code + | |
"&text=[" + | |
title + | |
"](" + | |
url + | |
")&parse_mode=markdown"; | |
const init = { | |
method: "GET", | |
headers: { | |
"content-type": "application/json;charset=UTF-8", | |
}, | |
}; | |
const response = await fetch(api, init); | |
const responseBody = await response.json(); | |
data = { | |
ok: responseBody.ok, | |
}; | |
} | |
} | |
const json = JSON.stringify(data, null, 2); | |
return new Response(json, { | |
headers: { | |
"content-type": "application/json;charset=UTF-8", | |
}, | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment