I have been spending a couple of weekends to develop something that makes tracking expenses a breeze. After trying a lot of methods, I realized that I needed something that’s either fully automated or requires minimum intervention from me. That’s when I thought of using a Discord bot to automate this task.
I already knew the power of Discord bots from when I created AKSH. (AKSH is a Discord bot that automates the self-hosted lab deployment on AWS for my course Red Team Adversary Emulation). So I came up with a design that leverages a Discord bot (henceforth referred to as KFKA) to automate my expense tracking.
KFKA Expense Flow
Here’s a simple illustration that demonstrates the design:
- The user (i.e. me) forwards the payment SMS to KFKA.
- KFKA receives the message and calls the updateExpense() method with the SMS content as the argument.
- The updateExpense() method identifies the payment method based on the content of the SMS and calls smsParser() method with the content of the SMS and the payment method as arguments.
- The smsParser() method parses the content, according to the payment method identified, and extracts the amount, the merchant name and the date (if available) from the content. The smsParser() method then calls the getExpenseCategory() method with the merchant name as the argument.
- The getExpenseCategory() method identifies the expense category based on the merchant name passed to it and returns the expense category back to the smsParse() method.
- The smsParse() method puts all the parsed information about the transaction into a dictionary and returns it to the updateExpense() method.
- If all went well (I haven’t included error handling in the above design to keep things simple), the updateExpense() method will call updateExpenseTillDate() method twice. The first time it calls the method to update the expense amount for the specified category and the second time it calls the method to update the total expense amount. The working of updateExpenseTillDate() method is beyond the scope of this post.
- Again, if all went well, the updateExpense() will return a success response to KFKA which in turn will relay the message to the user.
- The user can then retrieve category-wise expense till date and total expense till date amounts by sending a simple command to KFKA.
KFKA In Action
Here are a few redacted screenshots of KFKA in action:
Here are the components working behind this project:
- Python 3.10
- Raspberry Pi 4 Model B (for hosting KFKA). Know more about my adventures with Raspberry Pi.
- If the payment SMS is not received, most likely that expense will be missed.
- Card transactions mostly don’t include merchant name, so it’s difficult to categorize those expenses.
- Currently, payments made to an unmapped vendor will not be recorded.
- I am not aware of a method to pull all UPI transactions programatically, if you do please let me know.