-
Notifications
You must be signed in to change notification settings - Fork 2k
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
StatesV2: Support for topics, multibots, and business messages #2321
StatesV2: Support for topics, multibots, and business messages #2321
Conversation
@Badiboy I might need your opinion for further development. Have you used states before I ask you a question? |
@coder2020official I never used States :( |
Finished for sync - only left thing is to add a "bridge" between old and new formats of states to ease switching between these two. |
…t to avoid conflicts, added support of statesv2 to async(only memory storage)
telebot/async_telebot.py
Outdated
self.bot_id = None | ||
|
||
if token_check: | ||
result = apihelper.get_me(token) |
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.
@Badiboy do you think this is a good idea
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.
So basically due to sync init, I had to call getMe from apihelper to obtain types.User due to token_check being true(new param)
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.
So basically due to sync init, I had to call getMe from apihelper to obtain types.User due to token_check being true(new param)
Looks a bit ugly, but functional.
Checklist:
|
Pickle storage is the worst out of all. I had some bugs when simultaneously testing my states code. |
Breaking changes will be here
|
…return empty dict on get_data & raise runtimeerror on key not existing
@Badiboy i need your opinion on something I addressed before. Check the comment above(about sync call in async, I tagged you there) |
…y redis as it should be used for production.
@Badiboy I am nearly done with this PR. Now, I would like you to review:
|
All that is left is cleaning up the code, which I will do after you proceed with the review |
@Badiboy I am fully done, need your review |
@coder2020official I saw the request but I'm not sure when I'll be able to pass all of this: Especially as far as I never used states. |
You can review only crucial files(not new ones, etc), e.g init, async_telebot.py, etc |
Also I have addressed all breaking changes above |
telebot/__init__.py
Outdated
if validate_token: | ||
util.validate_token(self.token) | ||
|
||
self.bot_id = util.extract_bot_id(self.token) # subject to change in future, unspecified |
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.
May cause error if token is not in valid form. extract_bot_id should return NONE if extract fails.
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.
But validate_token raises an error if token is not in valid form?
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.
Yes. But only if validate_token is enabled. It's optional.
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.
oh yes. Btw, you are fine with validate_token being True by default?
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 saw it. I'm not happy, but as far it is not breaking and can be disabled - I can deal with it.
telebot/__init__.py
Outdated
@@ -1172,6 +1184,9 @@ def polling(self, non_stop: Optional[bool]=False, skip_pending: Optional[bool]=F | |||
if restart_on_change: | |||
self._setup_change_detector(path_to_watch) | |||
|
|||
if not self._user: |
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.
We discussed that get_me should be optional.
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.
Yep, my bad, for sync there's no need for this as self.user is a property that already does this
telebot/__init__.py
Outdated
""" | ||
Reset data for a user in chat. | ||
Reset data for a user in chat: sets the 'data' fieldi to an empty dictionary. |
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.
fieldi => field?
telebot/async_telebot.py
Outdated
if validate_token: | ||
util.validate_token(self.token) | ||
|
||
self.bot_id: int = util.extract_bot_id(self.token) # subject to change, unspecified |
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.
May cause error if token is not in valid form. extract_bot_id should return NONE if extract fails.
telebot/async_telebot.py
Outdated
@@ -424,7 +437,8 @@ async def _process_polling(self, non_stop: bool=False, interval: int=0, timeout: | |||
# show warning | |||
logger.warning("Setting non_stop to False will stop polling on API and system exceptions.") | |||
|
|||
self._user = await self.get_me() | |||
if not self._user: | |||
self._user = await self.get_me() |
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.
We discussed that get_me should be optional.
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 will return this to the original version, where it is called by default?
@coder2020official I checked only main files. All related to states are on your responcibility ) |
…sing error when extracting a bot id
Anything else left? |
I returned them to their original versions. Before, async would always call a getme request |
For 1), ok will fix it |
fixed 1), addressed 2) |
LGTM, let's go ) |
merge? |
@Badiboy bot api update was released just now. |
Need to change version to 4.23.0 |
Have nothing against it. Push it here and merge. |
I am afk, so we will have to delay this a little |
@Badiboy done, merging since you approved. |
We will also need a special changelog for next version with changes specifically for states. |
States Breaking changes
Features of new states
To automatically set business_message_id or message_thread_id, check for examples that use StateContext: |
Only sync memorystorage working now