Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ ETHPLORER_API_KEY = ""
CURRENCY = ""
RUNTIME_ENVIRONMENT = "DEV"
WEBHOOK_SECRET_TOKEN = ""
REDIS_HOST = ""
REDIS_PASSWORD = ""
13 changes: 6 additions & 7 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@
from aiogram import Bot, Dispatcher
from aiogram.enums import ParseMode
from fastapi import FastAPI, Request, status, HTTPException
from config import TOKEN, WEBHOOK_URL, ADMIN_ID_LIST, WEBHOOK_SECRET_TOKEN
from db import create_db_and_tables
import uvicorn
from fastapi.responses import JSONResponse
from services.notification import NotificationService

redis = Redis(password=config.REDIS_PASSWORD)
bot = Bot(TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML))
redis = Redis(host=config.REDIS_HOST, password=config.REDIS_PASSWORD)
bot = Bot(config.TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML))
dp = Dispatcher(storage=RedisStorage(redis))
app = FastAPI()


@app.post(config.WEBHOOK_PATH)
async def webhook(request: Request):
secret_token = request.headers.get("X-Telegram-Bot-Api-Secret-Token")
if secret_token != WEBHOOK_SECRET_TOKEN:
if secret_token != config.WEBHOOK_SECRET_TOKEN:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Unauthorized")

try:
Expand All @@ -40,10 +39,10 @@ async def webhook(request: Request):
async def on_startup():
await create_db_and_tables()
await bot.set_webhook(
url=WEBHOOK_URL,
secret_token=WEBHOOK_SECRET_TOKEN
url=config.WEBHOOK_URL,
secret_token=config.WEBHOOK_SECRET_TOKEN
)
for admin in ADMIN_ID_LIST:
for admin in config.ADMIN_ID_LIST:
try:
await bot.send_message(admin, 'Bot is working')
except Exception as e:
Expand Down
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
ETHPLORER_API_KEY = os.environ.get("ETHPLORER_API_KEY")
CURRENCY = Currency(os.environ.get("CURRENCY"))
WEBHOOK_SECRET_TOKEN = os.environ.get("WEBHOOK_SECRET_TOKEN")
REDIS_HOST = os.environ.get("REDIS_HOST")
REDIS_PASSWORD = os.environ.get("REDIS_PASSWORD")
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ services:
CURRENCY: "USD" # fiat currency
RUNTIME_ENVIRONMENT: "PROD"
WEBHOOK_SECRET_TOKEN: "1234567890" # Any string you want
REDIS_HOST: "redis"
REDIS_PASSWORD: "1234567890" # Any string you want
labels:
caddy: YOUR-DOMAIN-GOES-HERE
caddy.reverse_proxy: "bot:5000"
Expand Down Expand Up @@ -68,6 +70,8 @@ services:
volumes:
- redis_data:/data
restart: always
networks:
- caddy

volumes:
AiogramShopBot:
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ Litecoin, Solana and stablecoins in the TRC20 and ERC20 networks, which allows y
| ETHPLORER_API_KEY | API Key from ethplorer.io, used to get ERC20 balances. | No recommended value |
| CURRENCY | Currency to be used in the bot. | "USD" or "EUR" or "JPY" or "CAD" or "GBP" |
| RUNTIME_ENVIRONMENT | If set to "dev", the bot will be connected via an ngrok tunnel. "prod" will use [Caddy](https://hub.docker.com/r/lucaslorentz/caddy-docker-proxy) as reverse proxy together with your public hostname | "prod" or "dev" |
| WEBHOOK_SECRET_TOKEN | Required variable, used to protect requests coming from Telegram servers from spoofing. | Any string you want |
| REDIS_HOST | Required variable, needed to make the throttling mechanism work. | "redis" for docker-compose.yml |
| REDIS_PASSWORD | Required variable, needed to make the throttling mechanism work. | Any string you want |

### 1.1 Starting AiogramShopBot with Docker-compose.

Expand Down
Loading