You are on page 1of 25

Life Hacks

Manage your daily expenses with Telegram


❏ Laptop
❏ Telegram account
Open your telegram in desktop

Things to prepare

version
❏ Google account
It’s better to be prepared than
to get ready ❏ Try to open your google
spreadsheet
Google
spreadsheet
Create a new google spreadsheet and
named it “Monthly expenses”, and set
the tab named “Sept_2021”
Google
spreadsheet
Budget: 500
Total Expenses: “=sum(C:C)”
Balance: “=B1-B2”
Google
spreadsheet
Add 3 columns below:
Date
Items
Price
Google
spreadsheet
Tools > Script editor
Apps Script editor
Left side bar > Code.gs
[ Code 1 ] Copy & paste below code to your script editor

var token = "<REPLACE_THIS_WITH_YOUR_TOKEN>";


var telegramUrl = "https://api.telegram.org/bot" + token;
var webAppUrl = "<REPLACE_THIS_WITH_DEPLOY_ID>";
[ Code 2 ] Copy & paste below code to your script editor

function setWebhook() {
var url = telegramUrl + "/setWebhook?url=" + webAppUrl;
var response = UrlFetchApp.fetch(url);
}
[ Code 3 ] Copy & paste below code to your script editor

function sendMessage(id, text, keyBoard) {


var data = {
method: "post",
payload: {
method: "sendMessage",
chat_id: String(id),
text: text,
parse_mode: "HTML",
reply_markup: JSON.stringify(keyBoard)
}
}
UrlFetchApp.fetch(telegramUrl + "/", data);
}
[ Code 4 ] Click on below link, copy & paste the code to your
script editor
https://docs.google.com/document/d/17VXRAdhrNKUdbefAeMZCeaZuXQp6r1LO1emxrSCpqbo/edit?usp=sh
aring
Telegram desktop
On Search bar type BotFather
Telegram desktop
List of commands in the chat bot
To create a new bot so type
“/newbot” to start
And named it “expenseBot”
Username: “expense[x]_bot”
Telegram desktop
Copy the token from the bot you
created and paste it into your Apps
Script editor to replace
<REPLACE_THIS_WITH_YOUR_TOKEN>
Google
spreadsheet
find your Google sheet ID from URL:
eg:https://docs.google.com/spreadsheets/d/{ID_HERE}/edit

And copy and replace


<REPLACE_THIS_WITH_YOUR_SSID>
in Apps Script editor
Google
spreadsheet
find your Tab name from your spreadsheet
and replace
<REPLACE_THIS_WITH_YOUR_SHEET_TAB_NAME>

in Apps Script editor


Apps Script editor
On top right corner > Deploy button
Apps Script editor
Choose “New deployment”
select type: “Web app”
New description: “Deploy 1”
Click: “Deploy”
Apps Script editor
Who has access: Anyone
Apps Script editor
Proceed with Authorize access button
Apps Script editor
Choose Advanced to proceed. Go with “Go
to Expenses (unsafe)” and press “Allow”.
Apps Script editor
Copy the Web app URL and paste it to
your code replace it with
<REPLACE_THIS_WITH_DEPLOY_ID>
Apps Script editor
click Run button
Telegram bot
It’s time to test it out
Thank you

Reference link: https://chacatherine.medium.com/life-hack-track-your-monthly-expense-spreadsheet-through-telegram-bot-50869bbe3ec3

You might also like