mirror of
https://github.com/Llloooggg/TextSouls.git
synced 2026-03-06 04:26:23 +03:00
telegram: базовая регистрация
This commit is contained in:
@@ -15,5 +15,5 @@ scripts/runserver.sh
|
|||||||
### Запуск Telegram
|
### Запуск Telegram
|
||||||
Из папки Telegram:
|
Из папки Telegram:
|
||||||
```
|
```
|
||||||
python telegram/main.py
|
python textsouls/main.py
|
||||||
```
|
```
|
||||||
15
telegram/textsouls/common.py
Normal file
15
telegram/textsouls/common.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import json
|
||||||
|
import requests
|
||||||
|
|
||||||
|
with open("textsouls/config.json") as config_file:
|
||||||
|
config_data = json.load(config_file)
|
||||||
|
|
||||||
|
|
||||||
|
class Backend:
|
||||||
|
base_url = config_data["backend_settings"]["base_url"]
|
||||||
|
|
||||||
|
def post(self, relative_url, data):
|
||||||
|
requests.post(f"{self.base_url}{relative_url}", json=data)
|
||||||
|
|
||||||
|
|
||||||
|
backend = Backend()
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
{
|
{
|
||||||
"main_settings": {
|
"main_settings": {
|
||||||
"BOT_TOKEN": "token-from-@BotFather"
|
"bot_token": "token-from-@BotFather"
|
||||||
|
},
|
||||||
|
"backend_settings": {
|
||||||
|
"base_url": "http://localhost:5000"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,17 +2,27 @@ import json
|
|||||||
|
|
||||||
from aiogram import Bot, Dispatcher, executor
|
from aiogram import Bot, Dispatcher, executor
|
||||||
|
|
||||||
with open("telegram/config.json") as config_file:
|
from common import backend
|
||||||
|
|
||||||
|
with open("textsouls/config.json") as config_file:
|
||||||
config_data = json.load(config_file)
|
config_data = json.load(config_file)
|
||||||
|
|
||||||
API_TOKEN = config_data["main_settings"]["BOT_TOKEN"]
|
API_TOKEN = config_data["main_settings"]["bot_token"]
|
||||||
|
|
||||||
bot = Bot(token=API_TOKEN)
|
bot = Bot(token=API_TOKEN)
|
||||||
dp = Dispatcher(bot)
|
dp = Dispatcher(bot)
|
||||||
|
|
||||||
|
|
||||||
@dp.message_handler(commands=["start", "help"])
|
@dp.message_handler(commands=["start"])
|
||||||
async def send_welcome(message):
|
async def start(message):
|
||||||
|
tg_user = message.from_user
|
||||||
|
ts_user = {
|
||||||
|
"tg_id": tg_user.id,
|
||||||
|
"first_name": tg_user.first_name,
|
||||||
|
"last_name": tg_user.last_name,
|
||||||
|
"username": tg_user.username,
|
||||||
|
}
|
||||||
|
backend.post("/registration", ts_user)
|
||||||
await message.reply("Nice!")
|
await message.reply("Nice!")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user