Skip to content

Commit 2c0c7b3

Browse files
telegram bot commands group
1 parent 523c54c commit 2c0c7b3

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
web: gunicorn system.wsgi:app
2-
webhook: flask webhook
2+
webhook: flask telegram webhook
33
upgrade: flask db upgrade

system/commands.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
1-
import click
2-
3-
from flask.cli import with_appcontext
4-
5-
import telegram_bot.polling
6-
import telegram_bot.webhook
7-
8-
9-
@click.command('polling')
10-
@with_appcontext
11-
def start_polling():
12-
telegram_bot.polling.start_polling()
13-
14-
15-
@click.command('webhook')
16-
@with_appcontext
17-
def start_webhook():
18-
telegram_bot.webhook.set_webhook()
1+
from telegram_bot.commands import telegram_cli
192

203

214
def register_commands(app):
22-
app.cli.add_command(start_polling)
23-
app.cli.add_command(start_webhook)
5+
app.cli.add_command(telegram_cli)

telegram_bot/commands.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from flask.cli import AppGroup, with_appcontext
2+
3+
import telegram_bot.polling
4+
import telegram_bot.webhook
5+
6+
7+
telegram_cli = AppGroup('telegram')
8+
9+
10+
@telegram_cli.command('polling')
11+
@with_appcontext
12+
def start_polling():
13+
"""
14+
Starts telegram bot in the long-polling mode
15+
"""
16+
telegram_bot.polling.start_polling()
17+
18+
19+
@telegram_cli.command('webhook')
20+
@with_appcontext
21+
def start_webhook():
22+
"""
23+
Starts telegram bot in the webhook mode
24+
"""
25+
telegram_bot.webhook.set_webhook()

telegram_bot/webhook.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55

66
def set_webhook():
7-
host_url = current_app.config['HOST_URL']
8-
host_port = current_app.config['HOST_PORT']
9-
telegram_token = current_app.config['TELEGRAM_TOKEN']
7+
host_url = current_app.config.get('HOST_URL')
8+
host_port = current_app.config.get('HOST_PORT')
9+
telegram_token = current_app.config.get('TELEGRAM_TOKEN')
1010
bot = TelegramBot(telegram_token)
1111
bot.set_webhook(
1212
webhook_url='https://%s:%s/telegram/%s' % (

0 commit comments

Comments
 (0)