@@ -162,30 +162,17 @@ <h2 class="section-title" id="header-classes">Classes</h2>
162162 else:
163163 self.bot_scopes = bot_scopes
164164 self.bot_refresh_token = bot_refresh_token
165+
165166 if bot_token_expires_at is not None:
166- if type(bot_token_expires_at) == datetime:
167- self.bot_token_expires_at = int(bot_token_expires_at.timestamp()) # type: ignore
168- elif type(bot_token_expires_at) == str and not re.match("^\\d+$", bot_token_expires_at):
169- self.bot_token_expires_at = int(_from_iso_format_to_unix_timestamp(bot_token_expires_at))
170- else:
171- self.bot_token_expires_at = int(bot_token_expires_at)
167+ self.bot_token_expires_at = _timestamp_to_type(bot_token_expires_at, int)
172168 elif bot_token_expires_in is not None:
173169 self.bot_token_expires_at = int(time()) + bot_token_expires_in
174170 else:
175171 self.bot_token_expires_at = None
172+
176173 self.is_enterprise_install = is_enterprise_install or False
177174
178- if type(installed_at) == float:
179- self.installed_at = installed_at # type: ignore
180- elif type(installed_at) == datetime:
181- self.installed_at = installed_at.timestamp() # type: ignore
182- elif type(installed_at) == str:
183- if re.match("^\\d+.\\d+$", installed_at):
184- self.installed_at = float(installed_at)
185- else:
186- self.installed_at = _from_iso_format_to_unix_timestamp(installed_at)
187- else:
188- raise ValueError(f"Unsupported data format for installed_at {installed_at}")
175+ self.installed_at = _timestamp_to_type(installed_at, float)
189176
190177 self.custom_values = custom_values if custom_values is not None else {}
191178
@@ -340,7 +327,7 @@ <h3>Methods</h3>
340327</ dd >
341328< dt id ="slack_sdk.oauth.installation_store.FileInstallationStore "> < code class ="flex name class ">
342329< span > class < span class ="ident "> FileInstallationStore</ span > </ span >
343- < span > (</ span > < span > *, base_dir: str = '/Users/seratch /.bolt-app-installation', historical_data_enabled: bool = True, client_id: Optional[str] = None, logger: logging.Logger = <Logger slack_sdk.oauth.installation_store.file (WARNING)>)</ span >
330+ < span > (</ span > < span > *, base_dir: str = '/Users/kazuhiro.sera /.bolt-app-installation', historical_data_enabled: bool = True, client_id: Optional[str] = None, logger: logging.Logger = <Logger slack_sdk.oauth.installation_store.file (WARNING)>)</ span >
344331</ code > </ dt >
345332< dd >
346333< div class ="desc "> < p > The installation store interface.</ p >
@@ -429,6 +416,10 @@ <h3>Methods</h3>
429416 f.write(entity)
430417
431418 def save_bot(self, bot: Bot):
419+ if bot.bot_token is None:
420+ self.logger.debug("Skipped saving a new row because of the absense of bot token in it")
421+ return
422+
432423 none = "none"
433424 e_id = bot.enterprise_id or none
434425 t_id = bot.team_id or none
@@ -521,10 +512,13 @@ <h3>Methods</h3>
521512 data = json.loads(f.read())
522513 installation = Installation(**data)
523514
524- if installation is not None and user_id is not None:
515+ has_user_installation = user_id is not None and installation is not None
516+ no_bot_token_installation = installation is not None and installation.bot_token is None
517+ should_find_bot_installation = has_user_installation or no_bot_token_installation
518+ if should_find_bot_installation:
525519 # Retrieve the latest bot token, just in case
526520 # See also: https://github.com/slackapi/bolt-python/issues/664
527- latest_bot_installation = self.find_installation (
521+ latest_bot_installation = self.find_bot (
528522 enterprise_id=enterprise_id,
529523 team_id=team_id,
530524 is_enterprise_install=is_enterprise_install,
@@ -781,14 +775,9 @@ <h3>Inherited members</h3>
781775 else:
782776 self.bot_scopes = bot_scopes
783777 self.bot_refresh_token = bot_refresh_token
778+
784779 if bot_token_expires_at is not None:
785- if type(bot_token_expires_at) == datetime:
786- ts: float = bot_token_expires_at.timestamp() # type: ignore
787- self.bot_token_expires_at = int(ts)
788- elif type(bot_token_expires_at) == str and not re.match("^\\d+$", bot_token_expires_at):
789- self.bot_token_expires_at = int(_from_iso_format_to_unix_timestamp(bot_token_expires_at))
790- else:
791- self.bot_token_expires_at = bot_token_expires_at # type: ignore
780+ self.bot_token_expires_at = _timestamp_to_type(bot_token_expires_at, int)
792781 elif bot_token_expires_in is not None:
793782 self.bot_token_expires_at = int(time()) + bot_token_expires_in
794783 else:
@@ -801,14 +790,9 @@ <h3>Inherited members</h3>
801790 else:
802791 self.user_scopes = user_scopes
803792 self.user_refresh_token = user_refresh_token
793+
804794 if user_token_expires_at is not None:
805- if type(user_token_expires_at) == datetime:
806- ts: float = user_token_expires_at.timestamp() # type: ignore
807- self.user_token_expires_at = int(ts)
808- elif type(user_token_expires_at) == str and not re.match("^\\d+$", user_token_expires_at):
809- self.user_token_expires_at = int(_from_iso_format_to_unix_timestamp(user_token_expires_at))
810- else:
811- self.user_token_expires_at = user_token_expires_at # type: ignore
795+ self.user_token_expires_at = _timestamp_to_type(user_token_expires_at, int)
812796 elif user_token_expires_in is not None:
813797 self.user_token_expires_at = int(time()) + user_token_expires_in
814798 else:
@@ -824,17 +808,8 @@ <h3>Inherited members</h3>
824808
825809 if installed_at is None:
826810 self.installed_at = datetime.now().timestamp()
827- elif type(installed_at) == float:
828- self.installed_at = installed_at # type: ignore
829- elif type(installed_at) == datetime:
830- self.installed_at = installed_at.timestamp() # type: ignore
831- elif type(installed_at) == str:
832- if re.match("^\\d+.\\d+$", installed_at):
833- self.installed_at = float(installed_at)
834- else:
835- self.installed_at = _from_iso_format_to_unix_timestamp(installed_at)
836811 else:
837- raise ValueError(f"Unsupported data format for installed_at {installed_at}" )
812+ self.installed_at = _timestamp_to_type( installed_at, float )
838813
839814 self.custom_values = custom_values if custom_values is not None else {}
840815
0 commit comments