-
Notifications
You must be signed in to change notification settings - Fork 52
Telegram v2 #168
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
Telegram v2 #168
Conversation
leddcode
commented
Jan 31, 2021
- Updated getting current events
- Added creating new events
…into telegram-v2
Codecov Report
@@ Coverage Diff @@
## develop #168 +/- ##
===========================================
+ Coverage 99.39% 99.43% +0.04%
===========================================
Files 38 38
Lines 1489 1603 +114
===========================================
+ Hits 1480 1594 +114
Misses 9 9
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome job! Looks really cool. I left you with 1 major architecture change to do, and 2 SRP issues :)
@@ -27,6 +27,8 @@ def _get_first_name(self, data: Dict) -> str: | |||
|
|||
|
|||
class Bot: | |||
MEMORY = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is problematic. It's equivalent to a global variable and might create problems when working asynchronously.
await telegram_bot.send_message(chat_id=self.chat.user_id, text=answer) | ||
return answer | ||
|
||
async def process_new_event(self, memo_dict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split to functions
@@ -9,3 +11,7 @@ | |||
WEBHOOK_URL = settings.webhook_url | |||
|
|||
telegram_bot = Bot(BOT_API, WEBHOOK_URL) | |||
|
|||
loop = asyncio.get_event_loop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can just asyncio.run
the set_webhook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's impossible - asyncio.run() cannot be called from a running event loop (which started by FastAPI).
It seems "ensure_future" is the best way of executing code in asyncio without awaiting and closing the current loop.