Storefront bot with payments in TON
In this article, we'll guide you through the process of accepting payments in a Telegram bot.
📖 What you'll learn
In this article, you'll learn how to:
- create a Telegram bot using Python + Aiogram
- work with the public TON API (TON Center)
- work with SQlite database
And finally: how to accept payments in a Telegram bot with the knowledge from previous steps.
📚 Before we begin
Make sure you have installed the latest version of Python and have installed the following packages:
- aiogram
- requests
- sqlite3
🚀 Let's get started!
We'll follow the order below:
- Work with SQlite database
- Work with the public TON API (TON Center)
- Create a Telegram bot using Python + Aiogram
- Profit!
Let's create the following four files in our project directory:
telegram-bot
├── config.json
├── main.py
├── api.py
└── db.py
Config
In config.json we'll store our bot token and our public TON API key.
{
"BOT_TOKEN": "Your bot token",
"MAINNET_API_TOKEN": "Your mainnet api token",
"TESTNET_API_TOKEN": "Your testnet api token",
"MAINNET_WALLET": "Your mainnet wallet",
"TESTNET_WALLET": "Your testnet wallet",
"WORK_MODE": "testnet"
}
In config.json we decide which network we'll use: testnet or mainnet.
Database
Create a database
This example uses a local Sqlite database.
Create db.py.
To start working with the database, we need to import the sqlite3 module and some modules for working with time.
import sqlite3
import datetime
import pytz