Skip to content

Commit 2726597

Browse files
committed
v2.0.0
1 parent 927935e commit 2726597

File tree

14 files changed

+1544
-2
lines changed

14 files changed

+1544
-2
lines changed

README.md

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,104 @@
1-
# tele-tracker-v2
2-
A version 2 python telegram bot to help track daily expenses onto google sheet!
1+
# Tele-Tracker Bot
2+
A python telegram bot to help track daily expenses onto google sheet
3+
4+
## Release Notes
5+
You can find the release notes over [here](https://github.com/brucewzj99/tele-tracker/blob/master/release_notes.md)
6+
7+
## Table of Contents
8+
- [Getting Started (Users)](#getting-started-users)
9+
- [Getting Started (Developers)](#getting-started-developers)
10+
- [Usage](#usage)
11+
- [Contributing](#contributing)
12+
- [License](#license)
13+
- [Contact](#contact)
14+
15+
## Getting Started (Users)
16+
1. Access the bot on [telegram](https://t.me/telefinance_tracker_bot)
17+
2. Use the /start command and follow the instructions given.
18+
4. Remember to edit the `Dropdown` sheet on Google Sheet to get started.
19+
![image](https://github.com/brucewzj99/tele-tracker/assets/24997286/ddf879be-69f4-4e33-a517-3b5628055e6f)
20+
5. Happy using!
21+
22+
## Getting Started (Developers)
23+
### Step 1
24+
* Fork the repo and run the code below to installed the required dependencies
25+
```python
26+
pip install -r requirements.txt
27+
```
28+
* Install [ngrok](https://ngrok.com/download)
29+
30+
### Step 2
31+
* Go to Google Cloud Platform
32+
* Set up Google Sheet API, download service account key
33+
* Retrieve Google Sheet API email
34+
* Set up Firebase Realtime Database, download service account key
35+
* Retrieve your firebase database url
36+
* Set up telegram bot via [BotFather](https://t.me/BotFather)
37+
* Insert all of them into .env as follows
38+
```.env
39+
BOT_TOKEN=your_bot_token
40+
DATABASE_URL=firebase_url
41+
GOOGLE_API_EMAIL=google_api_email
42+
FIREBASE_JSON=service_account_key
43+
GOOGLE_JSON=service_account_key
44+
```
45+
46+
### Step 3
47+
* Run ngrok
48+
```terminal
49+
ngrok http 5000
50+
```
51+
* Copy the link, it should look something like this 'https://<address>.ap.ngrok.io'
52+
* Set up web hook by opening this link:
53+
```url
54+
https://api.telegram.org/bot<bot_token>/setwebhook?url=https://<address>.ap.ngrok.io/webhook
55+
```
56+
* You should see this:
57+
```json
58+
{"ok":true,"result":true,"description":"Webhook was set"}
59+
```
60+
* Proceed to project directory and run:
61+
```python
62+
python3.9 test.py
63+
```
64+
65+
## Usage
66+
/start - Start the bot and configure your Google Sheet for tracking expenses and other entries.
67+
68+
/config - Update your Google Sheet settings or configure quick settings for adding transport and other entries.
69+
70+
/addentry - Add a new entry to your expense tracking system.
71+
72+
/addtransport - Quickly add a new transport entry to your expense tracker.
73+
74+
/addothers - Quickly add another type of entry to your expense tracker.
75+
76+
/addincome - Add a new entry to your income.
77+
78+
/retrievetransaction - Retrieve a transaction from past date.
79+
80+
/cancel - Cancel the previous conversation with the bot and start fresh.
81+
82+
/help - Show help message
83+
84+
## Contributing
85+
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
86+
87+
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue or work on issues that are currently open.
88+
Don't forget to give the project a star! Thanks again!
89+
90+
1. Fork the Project
91+
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
92+
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
93+
4. Push to the Branch (`git push origin feature/AmazingFeature`)
94+
5. Open a Pull Request
95+
96+
## License
97+
Distributed under the MIT License. See `LICENSE.txt` for more information.
98+
99+
## Contact
100+
Bruce Wang: [email protected]
101+
102+
LinkedIn: [https://www.linkedin.com/in/brucewzj/](https://www.linkedin.com/in/brucewzj/)
103+
104+
Project Link: [https://github.com/brucewzj99/tele-tracker](https://github.com/brucewzj99/tele-tracker)

api/index.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from telegram import Update
2+
from telegram.ext import Updater
3+
from flask import Flask, request, render_template
4+
import os
5+
from bot.telegram_bot import setup_handlers
6+
7+
TOKEN = os.environ.get("BOT_TOKEN")
8+
app = Flask(__name__)
9+
updater = Updater(token=TOKEN)
10+
dispatcher = updater.dispatcher
11+
12+
13+
@app.route("/webhook", methods=["POST"])
14+
def webhook():
15+
update = Update.de_json(request.get_json(), updater.bot)
16+
dispatcher.process_update(update)
17+
return "OK"
18+
19+
20+
@app.route("/")
21+
def index():
22+
return render_template("app.html")
23+
24+
25+
setup_handlers(dispatcher) # Call function to set up bot handlers
26+
27+
if __name__ == "__main__":
28+
app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000)))

api/templates/app.html

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta http-equiv="x-ua-compatible" content="ie=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<title>Tele Tracker Bot</title>
8+
<meta name="description" content="A python telegram bot to help track expenses!" />
9+
<meta name="theme-color" content="#65efa4" />
10+
<style>
11+
*,
12+
*::before,
13+
*::after {
14+
box-sizing: border-box;
15+
}
16+
html {
17+
font-family: sans-serif;
18+
line-height: 1.15;
19+
height: 100%;
20+
-webkit-text-size-adjust: 100%;
21+
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
22+
}
23+
body {
24+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
25+
"Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji",
26+
"Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
27+
font-size: 16px;
28+
margin: 0;
29+
line-height: 1.5;
30+
height: 100%;
31+
text-align: left;
32+
color: #fefefe;
33+
background: #212121;
34+
}
35+
a {
36+
color:#65efa4;
37+
text-decoration: none;
38+
}
39+
a:hover {
40+
text-decoration: underline;
41+
}
42+
.container {
43+
display: table;
44+
max-width: 80%;
45+
height: 100%;
46+
margin: auto;
47+
}
48+
.child {
49+
display: table-cell;
50+
vertical-align: middle;
51+
}
52+
.title {
53+
color: #65efa4;
54+
font-size: 42px;
55+
font-weight: 700;
56+
line-height: 40px;
57+
margin: 0;
58+
}
59+
.subtitle {
60+
font-size: 18px;
61+
font-weight: 500;
62+
line-height: 20px;
63+
margin: 16px 0;
64+
}
65+
.logo {
66+
width: 100px;
67+
height: auto;
68+
}
69+
</style>
70+
</head>
71+
<body>
72+
<div class="container">
73+
<div class="child">
74+
<img src="https://github.com/brucewzj99/tele-tracker-v2/tree/master/api/templates/logo.png" alt="Logo" class="logo" />
75+
<h1 class="title">tele-tracker-bot</h1>
76+
<h2 class="subtitle">A python telegram bot to help track expenses!</h2>
77+
<p>You can access the bot using this <a href="https://t.me/telefinance_tracker_bot">link</a>.
78+
<br>For instructions on how to use the bot, please refer to the <a href="https://github.com/brucewzj99/tele-tracker-v2/wiki/Getting-Started">GitHub Wiki</a>.</p>
79+
<p>If you would like to support my work, you can do so at the following links:</p>
80+
<script type='text/javascript' src='https://storage.ko-fi.com/cdn/widget/Widget_2.js'></script><script type='text/javascript'>kofiwidget2.init('Support Me on Ko-fi', '#2f8a5b', 'H2H8LN59H');kofiwidget2.draw();</script> </div>
81+
</body>
82+
</html>

api/templates/logo.png

45.5 KB
Loading

bot/__init__.py

Whitespace-only changes.

bot/common.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from enum import Enum
2+
3+
4+
class EntryType(Enum):
5+
TRANSPORT = "Transport"
6+
OTHERS = "Others"
7+
8+
9+
class ConversationState(Enum):
10+
(
11+
SET_UP,
12+
RESET_UP,
13+
CONFIG_HANDLER,
14+
START_DESTINATION,
15+
ENTRY,
16+
PRICE,
17+
REMARKS,
18+
CATEGORY,
19+
SUBCATEGORY,
20+
PAYMENT,
21+
SUBPAYMENT,
22+
QUICK_ADD,
23+
QUICK_ADD_CATEGORY,
24+
CONFIG_SETUP,
25+
CONFIG_CATEGORY,
26+
CONFIG_SUBCATEGORY,
27+
CONFIG_PAYMENT,
28+
CONFIG_SUBPAYMENT,
29+
HANDLE_RETRIEVE_TRANSACTION,
30+
INCOME,
31+
WORK_PLACE,
32+
CPF,
33+
) = range(22)

bot/firebase.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from bot.firebase_config import db
2+
3+
4+
# new user setup
5+
def new_user_setup(telegram_id, sheet_id):
6+
ref = db.reference("/users/" + str(telegram_id))
7+
ref.update(
8+
{
9+
"sheet_id": sheet_id,
10+
}
11+
)
12+
13+
14+
# check if user exists
15+
def check_if_user_exists(telegram_id):
16+
ref = db.reference("/users/" + str(telegram_id))
17+
return ref.get() is not None
18+
19+
20+
# get user sheet id
21+
def get_user_sheet_id(telegram_id):
22+
ref = db.reference("/users/" + str(telegram_id) + "/sheet_id")
23+
return ref.get()

bot/firebase_config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import firebase_admin
2+
from firebase_admin import credentials
3+
from firebase_admin import db
4+
import os
5+
import json
6+
from firebase_admin.credentials import Certificate
7+
8+
DATABASE_URL = os.getenv("DATABASE_URL")
9+
FIREBASE_JSON = json.loads(os.environ["FIREBASE_JSON"])
10+
11+
firebase_admin.initialize_app(Certificate(FIREBASE_JSON), {"databaseURL": DATABASE_URL})

0 commit comments

Comments
 (0)