getUpdated changed to webhook, removed exposed port for mongodb, added extra configuration for docker ports, updated README.md

This commit is contained in:
miloszowi 2021-10-04 18:19:26 +02:00
parent 1644aa35a1
commit ff1d037be9
6 changed files with 36 additions and 12 deletions

3
.env.local Normal file
View File

@ -0,0 +1,3 @@
MONGODB_INTERNAL_PORT=
APP_INTERNAL_PORT=
APP_EXPOSED_PORT=

View File

@ -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
```bash
cp .env.local .env
cp docker/config/app.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
### 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)
- `WEBHOOK_URL` - url for telegram webhooks (withour the bot token)
- `PORT` - port used for initializing webhook & app
- `MONGODB_DATABASE` - MongoDB database name
- `MONGODB_USERNAME` - MongoDB username
- `MONGODB_PASSWORD` - MongoDB password
- `MONGODB_HOSTNAME` - MongoDB host (default `database` - container name)
- `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_PASSWORD` - conf from `app.env`
- `MONGO_INITDB_DATABASE` - conf from `app.env`

View File

@ -4,13 +4,14 @@ services:
database:
image: mongo:5.0.2
command: mongod --port $MONGODB_INTERNAL_PORT
restart: unless-stopped
env_file:
- ./docker/config/database.env
volumes:
- db-data:/data/db
ports:
- 27017:27017
- $MONGODB_INTERNAL_PORT
networks:
- web
@ -22,12 +23,12 @@ services:
volumes:
- ./src:/src
ports:
- 9000:9000
- $APP_EXPOSED_PORT:$APP_INTERNAL_PORT
depends_on:
- database
networks:
- web
restart: on-failure
restart: unless-stopped
networks:
web:

View File

@ -1,4 +1,6 @@
BOT_TOKEN=
WEBHOOK_URL=
PORT=
MONGODB_DATABASE=
MONGODB_USERNAME=

View File

@ -1,7 +1,7 @@
from telegram.ext import Updater
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 import (inHandler, mentionHandler, outHandler, silentMentionHandler, groupsHandler)
@ -15,8 +15,8 @@ class App:
def run(self) -> None:
self.register_handlers()
self.register_webhook()
self.updater.start_polling()
self.updater.idle()
def register_handlers(self) -> None:
@ -25,6 +25,13 @@ class App:
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__":
app = App()

View File

@ -5,6 +5,8 @@ from dotenv import load_dotenv
load_dotenv()
BOT_TOKEN = os.environ['BOT_TOKEN']
WEBHOOK_URL = os.environ['WEBHOOK_URL']
PORT = os.environ['PORT']
MONGODB_DATABASE = os.environ['MONGODB_DATABASE']
MONGODB_USERNAME = os.environ['MONGODB_USERNAME']