Skip to content

Instantly share code, notes, and snippets.

@gilpanal
gilpanal / app.js
Last active April 3, 2024 15:16
The following code demonstrates how to get a file from Telegram without exposing Bot Secret Token in the client side. In this case is used to retrieve a MP3, but the example should work for other file types. An intermediate API, (server.js) built using Node.js, get the raw data of the file and forward it to the web client (index.html and app.js)
const TEL_PATH = '/music/file_352.mp3'
const API_FILEDONWLOAD = 'http://localhost:3000/fileDownload?'
const load = () => {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest()
xhr.open('GET', API_FILEDONWLOAD + TEL_PATH, true)
xhr.responseType = 'arraybuffer'