Goal: To create a bot that works like a wallet. It will be able to create accounts for users, transfer money from account to account between users, send invoices and money in the message directly using a special link or inline message from the bot. It could also store the user's documents as a picture with a nickname, delete them and send via link. It would support the possibility of setting daily and monthly limits and overview user transactions.
To launch the bot, you need to download the Telegram app, follow the link and click Start button.
Features (Presentation)
- Send funds to friends in seconds!
- Сreate invoice or cheque and send as a link!
- Keep your documents in one safe place!
/topup [AMOUNT]
— top up the balance for the specified amount
/send [AMOUNT] [USERID]
— sends the amount to the user by the specified id
/createinvoice [AMOUNT]
— creates an invoice to receive the specified amount
/createcheque [AMOUNT]
— creates a cheque with the specified amount. The user can get it only if there is a sufficient balance
/dailylimit [AMOUNT]
— sets a daily limit for all operations to the user
/monthlylimit [AMOUNT]
— sets a monthly limit for all operations to the user
/uploaddocument [DOCUMENTID]
— uploads the document
/showdocument [DOCUMENTID]
— shows the document to the user
/deletedocument [DOCUMENTID]
— deletes the document
/deletealldocuments
— deletes all documents
After entering @TeleWalleterBot in the text field with another user and then specifying the amount, it becomes possible to send or request the funds directly in the conversation. If you enter doc
you will be able to see the list of your documents and share it.
To get started you need to connect the Telegram.BotAPI for NET library. Use command $ dotnet add PROJECT package Telegram.BotAPI
. The bot is launched via dotnet run
command in the project directory. The bot will be launched by the link t.me/TeleWalleterBot. If you want to use different bot, use the constructor t.me/BotFather and then change BotUsername and BotToken constants.
Bot is constantly waiting for a request from the user. When an update is received, it is checked and then the appropriate command is executed. In case of an unsuccessful command, the bot sends a corresponding message.
The Bot API is an HTTP-based interface. This bot uses three types of updates:
- InlineQuery Update
- Message Update
- CallbackQuery Update
The update comes when a user writes a bot username in a dialog with another user and puts a space, then entering the necessary data.
The update comes when the user sends a message to the bot. The message can contain both a picture, a sticker, an audio file and much more.
The update occurs when the user clicks the InlineKeyboardMarkup button. It allows you to make convenient navigation for the user in the form of a menu.
- Bot receives an update;
- Passes the update to processors;
- Processors based on the data from the user make a decision and change the data if necessary;
- The corresponding response is sent to the user.
Сreates database tables and starts bot polling.
Processes inline queries from the user and responds to them.
Handles the document sent by the user and saves it to the database, if successful.
Handles text commands from the user.
Handles callbacks that the user sends via buttons.
Сhecks transactions for compliance with the conditions, in particular:
- The required balance
- The correct user ID
- Exceeding limits
Sends the transaction if it is valid and notifies users of the changes.
Sends a message to the user using the Telegram Bot API.
Executes sql queries to the database.
Сontains immutable data, such as error messages, bot token, database name and bot username.
Generates text for the user using the transmitted data.
Creates Reply Markup for messages. The buttons, when pressed, send a call back query to which the bot responds.
Сreates a unique hash for later use in the database and obtaining documents. Used to increase user security.
Сreates a cheque and writes it to the database.
The hash of checks and documents is created randomly and protects the user from bruteforce. The user, even knowing the hash of another user's document, will not be able to delete it. The cheque can only be received once if the creator of it has enough funds and limits are not exceeded.
A little difficulty caused the creation of secure links for sending documents and receipts. Also, understanding of the telegram documentation itself and understanding how it interacts with the user and how I can use it in my case.