Setting Up Telegram Bot on Apps Script

Here is technical side of what I did on development on Apps Script. main article // Main webhook handler - receives all Telegram updates function doPost(e) { try { if (!e || !e.postData) { return ContentService.createTextOutput('Invalid request').setMimeType(ContentService.MimeType.TEXT).setStatusCode(400); } const update = JSON.parse(e.postData.contents); if (update.message) { handleMessage(update.message); } // IMPORTANT: Always return OK with proper content type and mainly proper status code (200<=status<300) to prevent retries return ContentService.createTextOutput('OK').setMimeType(ContentService.MimeType.TEXT).setStatusCode(200); } catch (error) { console.error('Error in doPost:', error); // Even on error, return OK to prevent Telegram retries return ContentService.createTextOutput('OK').setMimeType(ContentService.MimeType.TEXT).setStatusCode(500); } } By the nature of apps script, doPost is used when the app received POST request. Telegram sends data via POST to webhook url. So we set up POST listener. ...

July 22, 2025 · 2 min

Apps Script

Beginning I mainly started freelancing from 2024. At that time I had a client who had accounting/consulting firm, they needed a telegram bot to create template word contracts. They said they had started doing it but didn’t have time to finish it themselves. I saw their code, it was on apps script. At that time I first came across with apps script. I made the telegram with aiogram/python. btw, I used encoding files with base64, docxtpl to render docx files from template. ...

July 22, 2025 · 3 min