Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix telegram bot #1389

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions api/management/commands/telegram_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ def handle(self, *args, **options):
parts = message.split(" ")
if len(parts) < 2:
self.notifications.send_telegram_message(
chat_id=result["message"]["from"]["id"],
text='You must enable the notifications bot using the RoboSats client. Click on your "Robot robot" -> "Enable Telegram" and follow the link or scan the QR code.',
result["message"]["from"]["id"],
'You must enable the notifications bot using the RoboSats client. Click on your "Robot robot" -> "Enable Telegram" and follow the link or scan the QR code.',
)
continue
token = parts[-1]
robot = Robot.objects.filter(telegram_token=token).first()
if not robot:
self.notifications.send_telegram_message(
chat_id=result["message"]["from"]["id"],
text=f'Wops, invalid token! There is no Robot with telegram chat token "{token}"',
result["message"]["from"]["id"],
f'Wops, invalid token! There is no Robot with telegram chat token "{token}"',
)
continue

Expand Down
4 changes: 2 additions & 2 deletions api/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ def send_message(self, order, robot, title, description=""):
if robot.telegram_enabled:
self.send_telegram_message(robot.telegram_chat_id, title, description)

def save_message(self, order, robot, title, description):
def save_message(self, order, robot, title, description=""):
"""Save a message for a user"""
Notification.objects.create(
title=title, description=description, robot=robot, order=order
)

def send_telegram_message(self, chat_id, title, description):
def send_telegram_message(self, chat_id, title, description=""):
"""sends a message to a user with telegram notifications enabled"""

bot_token = config("TELEGRAM_TOKEN")
Expand Down