Home

Awesome

<p align="center"> <img src="botfather/logo.png" width="200"> </p>

🤖 telegram-expense-bot

This is a bot for the Telegram messaging app using their bot platform. The code is open-source and consequently anybody could set up an own instance of the bot. To learn how to do so, see this section. The official hosted version is available as @ExpenseBot. To learn more about this bot, please refer to this blog article or just send the bot a message with the /help command.

What does it do?

This bot’s purpose is to help people manage their daily expenses and keep track of their financial situation. Users can add expenses from wherever they are using a few simple commands from within the chat and have an eye on how much they have spent in a month or a day. This obviates the need for confusing Excel spreadsheets or paper notes.

Initial setup

When you first start using the bot, please send it your current location as a message, so the bot is aware of your time zone and can handle dates properly for you.

How to host it myself?

Prerequisites

In order to host this bot on your own, you need a few things.

Configuration

To configure your bot, clone this repository, copy config.example.json to config.json and edit it.

PropertyDefaultRequiredDescription
BOT_TOKEN-YesYour bot's token (received from BotFather).
PUBLIC_URL-Webhook onlyURL at which your bot is publicly available (for Telegram to send updates). Required in webhook mode. Ex.: https://bot.example.org.
DB_URL-YesMongoDB database connection string (starting with mongodb://)
DB_COLLECTIONexpensesNoMongoDB collection for storing expenses
BIND_IPV4127.0.0.1Webhook onlyAddress where to listen for HTTP requests
PORT3010Webhook onlyPort where to listen for HTTP requests
BOT_NAME``YesThe bot's name
BOT_TELEGRAM_USERNAME``YesThe bot's actual unique Telegram username
ADMIN[]YesList of Telegram user IDs to grant admin access
RATE_LIMIT250NoMaximum number of messages per hour per user

Install

$ yarn

Run

$ yarn start:production

Metrics

When using webhook mode, Prometheus metrics are exposed at /metrics.

Database

db.expenses.createIndex({ "user": 1 }, { name: "idx_user" });
db.expenses.createIndex({ "user": 1, "isTemplate": 1, "timestamp": 1, "category": 1 }, { name: "idx_full_query" });
db.expenses.createIndex({ "isTemplate": 1, "user": 1 }, { name: "idx_template_user" });
db.expenses.createIndex({ "isTemplate": 1, "user": 1, "timestamp": 1 }, { name: "idx_template_user_time" });
db.expenses.createIndex({ "ref": 1 }, { name: "idx_ref" });

License

MIT @ Ferdinand Mütsch