mirror of
https://github.com/miloszowi/everyone-mention-telegram-bot.git
synced 2025-05-20 09:14:07 +00:00
getUpdated changed to webhook, removed exposed port for mongodb, added extra configuration for docker ports, updated README.md
This commit is contained in:
parent
1644aa35a1
commit
ff1d037be9
3
.env.local
Normal file
3
.env.local
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
MONGODB_INTERNAL_PORT=
|
||||||
|
APP_INTERNAL_PORT=
|
||||||
|
APP_EXPOSED_PORT=
|
13
README.md
13
README.md
@ -29,6 +29,7 @@ git clone https://github.com/miloszowi/everyone-mention-telegram-bot.git
|
|||||||
```
|
```
|
||||||
after that, you need to copy env files and fulfill it with correct values
|
after that, you need to copy env files and fulfill it with correct values
|
||||||
```bash
|
```bash
|
||||||
|
cp .env.local .env
|
||||||
cp docker/config/app.dist.env docker/config/app.env
|
cp docker/config/app.dist.env docker/config/app.env
|
||||||
cp docker/config/database.dist.env docker/config/app.env
|
cp docker/config/database.dist.env docker/config/app.env
|
||||||
```
|
```
|
||||||
@ -44,15 +45,23 @@ docker/logs <container>
|
|||||||
```
|
```
|
||||||
to check container logs
|
to check container logs
|
||||||
### Env files
|
### Env files
|
||||||
app.env
|
`.env`
|
||||||
|
- `MONGODB_INTERNAL_PORT` - Mongodb internal port (should be the same as declared in `app.env`)
|
||||||
|
- `APP_INTERNAL_PORT` - App internal port (should be the same as declared in `app.env`)
|
||||||
|
- `APP_EXPOSED_PORT` - App exposed port (if you are not using any reverse proxy it should be also the same as declared in `app.env`)
|
||||||
|
|
||||||
|
|
||||||
|
`app.env`
|
||||||
- `BOT_TOKEN` - your telegram bot token from [BotFather](https://telegram.me/BotFather)
|
- `BOT_TOKEN` - your telegram bot token from [BotFather](https://telegram.me/BotFather)
|
||||||
|
- `WEBHOOK_URL` - url for telegram webhooks (withour the bot token)
|
||||||
|
- `PORT` - port used for initializing webhook & app
|
||||||
- `MONGODB_DATABASE` - MongoDB database name
|
- `MONGODB_DATABASE` - MongoDB database name
|
||||||
- `MONGODB_USERNAME` - MongoDB username
|
- `MONGODB_USERNAME` - MongoDB username
|
||||||
- `MONGODB_PASSWORD` - MongoDB password
|
- `MONGODB_PASSWORD` - MongoDB password
|
||||||
- `MONGODB_HOSTNAME` - MongoDB host (default `database` - container name)
|
- `MONGODB_HOSTNAME` - MongoDB host (default `database` - container name)
|
||||||
- `MONGODB_PORT` - MongoDB port (default `27017` - given in docker-compose configuration)
|
- `MONGODB_PORT` - MongoDB port (default `27017` - given in docker-compose configuration)
|
||||||
|
|
||||||
database.env
|
`database.env`
|
||||||
- `MONGO_INITDB_ROOT_USERNAME` - conf from `app.env`
|
- `MONGO_INITDB_ROOT_USERNAME` - conf from `app.env`
|
||||||
- `MONGO_INITDB_ROOT_PASSWORD` - conf from `app.env`
|
- `MONGO_INITDB_ROOT_PASSWORD` - conf from `app.env`
|
||||||
- `MONGO_INITDB_DATABASE` - conf from `app.env`
|
- `MONGO_INITDB_DATABASE` - conf from `app.env`
|
||||||
|
@ -4,13 +4,14 @@ services:
|
|||||||
|
|
||||||
database:
|
database:
|
||||||
image: mongo:5.0.2
|
image: mongo:5.0.2
|
||||||
|
command: mongod --port $MONGODB_INTERNAL_PORT
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file:
|
env_file:
|
||||||
- ./docker/config/database.env
|
- ./docker/config/database.env
|
||||||
volumes:
|
volumes:
|
||||||
- db-data:/data/db
|
- db-data:/data/db
|
||||||
ports:
|
ports:
|
||||||
- 27017:27017
|
- $MONGODB_INTERNAL_PORT
|
||||||
networks:
|
networks:
|
||||||
- web
|
- web
|
||||||
|
|
||||||
@ -22,12 +23,12 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./src:/src
|
- ./src:/src
|
||||||
ports:
|
ports:
|
||||||
- 9000:9000
|
- $APP_EXPOSED_PORT:$APP_INTERNAL_PORT
|
||||||
depends_on:
|
depends_on:
|
||||||
- database
|
- database
|
||||||
networks:
|
networks:
|
||||||
- web
|
- web
|
||||||
restart: on-failure
|
restart: unless-stopped
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
web:
|
web:
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
BOT_TOKEN=
|
BOT_TOKEN=
|
||||||
|
WEBHOOK_URL=
|
||||||
|
PORT=
|
||||||
|
|
||||||
MONGODB_DATABASE=
|
MONGODB_DATABASE=
|
||||||
MONGODB_USERNAME=
|
MONGODB_USERNAME=
|
||||||
|
11
src/app.py
11
src/app.py
@ -1,7 +1,7 @@
|
|||||||
from telegram.ext import Updater
|
from telegram.ext import Updater
|
||||||
from telegram.ext.dispatcher import Dispatcher
|
from telegram.ext.dispatcher import Dispatcher
|
||||||
|
|
||||||
from config.credentials import BOT_TOKEN
|
from config.credentials import BOT_TOKEN, PORT, WEBHOOK_URL
|
||||||
from handler.abstractHandler import AbstractHandler
|
from handler.abstractHandler import AbstractHandler
|
||||||
from handler import (inHandler, mentionHandler, outHandler, silentMentionHandler, groupsHandler)
|
from handler import (inHandler, mentionHandler, outHandler, silentMentionHandler, groupsHandler)
|
||||||
|
|
||||||
@ -15,8 +15,8 @@ class App:
|
|||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
self.register_handlers()
|
self.register_handlers()
|
||||||
|
self.register_webhook()
|
||||||
|
|
||||||
self.updater.start_polling()
|
|
||||||
self.updater.idle()
|
self.updater.idle()
|
||||||
|
|
||||||
def register_handlers(self) -> None:
|
def register_handlers(self) -> None:
|
||||||
@ -25,6 +25,13 @@ class App:
|
|||||||
handler().get_bot_handler()
|
handler().get_bot_handler()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def register_webhook(self) -> None:
|
||||||
|
self.updater.start_webhook(
|
||||||
|
listen="0.0.0.0",
|
||||||
|
port=int(PORT),
|
||||||
|
url_path=BOT_TOKEN,
|
||||||
|
webhook_url="/".join([WEBHOOK_URL, BOT_TOKEN])
|
||||||
|
)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = App()
|
app = App()
|
||||||
|
@ -5,6 +5,8 @@ from dotenv import load_dotenv
|
|||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
BOT_TOKEN = os.environ['BOT_TOKEN']
|
BOT_TOKEN = os.environ['BOT_TOKEN']
|
||||||
|
WEBHOOK_URL = os.environ['WEBHOOK_URL']
|
||||||
|
PORT = os.environ['PORT']
|
||||||
|
|
||||||
MONGODB_DATABASE = os.environ['MONGODB_DATABASE']
|
MONGODB_DATABASE = os.environ['MONGODB_DATABASE']
|
||||||
MONGODB_USERNAME = os.environ['MONGODB_USERNAME']
|
MONGODB_USERNAME = os.environ['MONGODB_USERNAME']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user