Skip to content

Commit

Permalink
Add optional long polling usage
Browse files Browse the repository at this point in the history
Signed-off-by: alfred richardsn <rchrdsn@protonmail.ch>
  • Loading branch information
r4rdsn committed Nov 19, 2020
1 parent 7039a3e commit b81169d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Connection
TOKEN_FILENAME=/run/secrets/tbtoken
SET_WEBHOOK=true # Use long polling if set to false
INTERNAL_HOST=0.0.0.0
SERVER_HOST=example.com
SERVER_PORT=5000
Expand All @@ -12,7 +13,6 @@ DATABASE_NAME=tellerbot

# Logging
LOGGER_LEVEL=INFO
LOG_FILENAME=/var/log/tellerbot.log
DATABASE_LOGGING_ENABLED=true

# Chat IDs
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ cp .env.example .env
11. Install and start [MongoDB server](https://docs.mongodb.com/manual/installation/).
12. Set environment variables:
```bash
export $(grep -v '^#' .env | xargs)
export $(sed 's/#.*//' .env | xargs)
```
13. Create database user:
```bash
Expand Down
19 changes: 11 additions & 8 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,17 @@ def main():
webhook_path = config.WEBHOOK_PATH + "/" + url_token

bot.setup()
executor.start_webhook(
dispatcher=dp,
webhook_path=webhook_path,
on_startup=lambda *args: on_startup(webhook_path, *args),
on_shutdown=lambda *args: close_blockchains(),
host=config.INTERNAL_HOST,
port=config.SERVER_PORT,
)
if config.SET_WEBHOOK:
executor.start_webhook(
dispatcher=dp,
webhook_path=webhook_path,
on_startup=lambda *args: on_startup(webhook_path, *args),
on_shutdown=lambda *args: close_blockchains(),
host=config.INTERNAL_HOST,
port=config.SERVER_PORT,
)
else:
executor.start_polling(dispatcher=dp)
print() # noqa: T001 Executor stopped with ^C

# Stop all background tasks
Expand Down
3 changes: 2 additions & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@


DEFAULT_VALUES = {
"SET_WEBHOOK": False,
"INTERNAL_HOST": "127.0.0.1",
"DATABASE_HOST": "127.0.0.1",
"DATABASE_PORT": 27017,
"DATABASE_NAME": "tellerbot",
"ESCROW_ENABLED": True,
"ESCROW_ENABLED": False,
}


Expand Down

0 comments on commit b81169d

Please sign in to comment.