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

Feature/telegram/implementation #637

Merged
merged 21 commits into from
Oct 26, 2024

Conversation

alimaktabi
Copy link
Collaborator

@alimaktabi alimaktabi commented Oct 17, 2024

Summary by Sourcery

Implement Telegram bot integration with features for user connection, bug reporting, and admin broadcast messaging. Add a new constraint for verifying Telegram connections and update documentation to guide users on using these new features.

New Features:

  • Introduce a Telegram bot integration for the application, allowing users to connect their Telegram accounts and interact with the system through a bot interface.
  • Add a bug reporting feature via Telegram, enabling users to report issues directly through the Telegram bot and receive rewards for valid reports.
  • Implement a broadcast message feature in the admin panel to send messages to all connected Telegram users.

Enhancements:

  • Add a new constraint 'HasTelegramConnection' to the system, allowing verification of users' Telegram connections.

Documentation:

  • Add user-facing documentation for the new Telegram bot features, including how to connect accounts and report bugs.

Copy link
Contributor

sourcery-ai bot commented Oct 17, 2024

Reviewer's Guide by Sourcery

This pull request implements Telegram integration for the Unitap platform. It adds new functionality for connecting Telegram accounts, handling Telegram bot interactions, and introduces new constraints and models related to Telegram connections.

Class diagram for Telegram integration

classDiagram
    class TelegramConnection {
        +BigIntegerField user_id
        +CharField first_name
        +CharField last_name
        +CharField username
        +is_connected() bool
    }
    class TelegramMessenger {
        +send_message(chat_id, text, reply_markup)
        +send_photo(chat_id, photo, caption, parse_mode)
        +reply_to(message, text, parse_mode)
        +update_query_messages(call, text, markup)
    }
    class TelegramRateLimiter {
        +send_telegram_request(func, *args, **kwargs)
    }
    class BaseTelegramMessageHandler {
        +handler(message)
    }
    class BaseTelegramCommandHandler {
        +handler(message, command, args)
    }
    class BaseTelegramCallbackHandler {
        +handler(callback)
    }
    class BugReportHandler {
        +handler(message)
        +ask_for_bug_details(message)
        +ask_for_bug_occurence(message, user_bug_details)
        +collect_image(message, user_bug_details, bug_occurence_details)
        +forward_to_private_channel(message, user_bug_details, bug_occurence_details, image)
    }
    class ReportBugRewardHandler {
        +handler(callback)
    }
    class TelegramUtil {
        +verify_login(telegram_data)
    }
    TelegramConnection <|-- BaseTelegramMessageHandler
    TelegramConnection <|-- BaseTelegramCommandHandler
    TelegramConnection <|-- BaseTelegramCallbackHandler
    BaseTelegramMessageHandler <|-- BugReportHandler
    BaseTelegramCallbackHandler <|-- ReportBugRewardHandler
    TelegramMessenger <|-- TelegramRateLimiter
    TelegramMessenger <|-- BugReportHandler
    TelegramMessenger <|-- ReportBugRewardHandler
    TelegramMessenger <|-- BaseTelegramMessageHandler
    TelegramMessenger <|-- BaseTelegramCommandHandler
    TelegramMessenger <|-- BaseTelegramCallbackHandler
    TelegramMessenger <|-- TelegramUtil
Loading

File-Level Changes

Change Details Files
Implement Telegram bot functionality
  • Create TelegramMessenger class for managing bot interactions
  • Implement rate limiting for Telegram API requests
  • Add handlers for various Telegram bot commands and messages
  • Create webhook setup for receiving Telegram updates
telegram/bot.py
telegram/views.py
telegram/apps.py
Add Telegram connection model and related functionality
  • Create TelegramConnection model
  • Implement TelegramConnectionSerializer
  • Add TelegramLoginCallbackView for handling Telegram logins
  • Create migration for TelegramConnection model
telegram/models.py
telegram/serializers.py
telegram/views.py
telegram/migrations/0001_initial.py
Integrate Telegram functionality into existing systems
  • Add Telegram-related environment variables
  • Include Telegram app in INSTALLED_APPS
  • Add Telegram API URLs
  • Create HasTelegramConnection constraint
brightIDfaucet/settings.py
brightIDfaucet/urls.py
core/models.py
core/constraints/__init__.py
core/constraints/telegram.py
Implement Telegram bot message handlers
  • Create handlers for start command, about message, and bug reporting
  • Implement GastapStatsHandler for displaying gas token availability
  • Add menu markup for bot interactions
telegram/messages/start.py
telegram/messages/about.py
telegram/messages/bug_reporter.py
telegram/messages/gastap_stats.py
telegram/messages/menu.py
Add admin functionality for Telegram connections
  • Create TelegramConnectionAdmin with broadcast functionality
  • Add BroadcastMessageForm for sending messages to all Telegram users
  • Create admin template for broadcast functionality
telegram/admin.py
telegram/forms.py
telegram/templates/admin/broadcast.html
Update constraints and migrations for Telegram integration
  • Add HasTelegramConnection constraint to tokenTap and prizetap
  • Create migrations for new Telegram-related constraints
tokenTap/migrations/0067_alter_constraint_name.py
prizetap/migrations/0081_alter_constraint_name.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @alimaktabi - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Implement access control for the broadcast feature (link)

Overall Comments:

  • The implementation looks solid, but unit tests should be added to cover the new Telegram functionality before merging.
  • Consider moving hardcoded message texts to a separate file or using Django's translation system for easier maintenance and potential future internationalization.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🔴 Security: 1 blocking issue
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

telegram/bot.py Show resolved Hide resolved
telegram/admin.py Show resolved Hide resolved
core/thirdpartyapp/telegram.py Outdated Show resolved Hide resolved
telegram/admin.py Show resolved Hide resolved
telegram/bot.py Outdated Show resolved Hide resolved
telegram/bot.py Outdated Show resolved Hide resolved
telegram/bot.py Outdated Show resolved Hide resolved
telegram/views.py Outdated Show resolved Hide resolved
telegram/views.py Outdated Show resolved Hide resolved
telegram/views.py Outdated Show resolved Hide resolved
@ShayanShiravani ShayanShiravani merged commit e022f58 into develop Oct 26, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants