Skip to content

Commit

Permalink
version 1.14.2
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Jul 21, 2022
1 parent dbdb2c5 commit ff9c796
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 25 deletions.
4 changes: 3 additions & 1 deletion docs/api-docs/slack_bolt/middleware/async_builtins.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ <h2 class="section-title" id="header-classes">Classes</h2>
next: Callable[[], Awaitable[BoltResponse]],
) -&gt; BoltResponse:
auth_result = req.context.authorize_result
if self._is_self_event(auth_result, req.context.user_id, req.body):
# message events can have $.event.bot_id while it does not have its user_id
bot_id = req.body.get(&#34;event&#34;, {}).get(&#34;bot_id&#34;)
if self._is_self_event(auth_result, req.context.user_id, bot_id, req.body):
self._debug_log(req.body)
return await req.context.ack()
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ <h1 class="title">Module <code>slack_bolt.middleware.ignoring_self_events.async_
next: Callable[[], Awaitable[BoltResponse]],
) -&gt; BoltResponse:
auth_result = req.context.authorize_result
if self._is_self_event(auth_result, req.context.user_id, req.body):
# message events can have $.event.bot_id while it does not have its user_id
bot_id = req.body.get(&#34;event&#34;, {}).get(&#34;bot_id&#34;)
if self._is_self_event(auth_result, req.context.user_id, bot_id, req.body):
self._debug_log(req.body)
return await req.context.ack()
else:
Expand Down Expand Up @@ -79,7 +81,9 @@ <h2 class="section-title" id="header-classes">Classes</h2>
next: Callable[[], Awaitable[BoltResponse]],
) -&gt; BoltResponse:
auth_result = req.context.authorize_result
if self._is_self_event(auth_result, req.context.user_id, req.body):
# message events can have $.event.bot_id while it does not have its user_id
bot_id = req.body.get(&#34;event&#34;, {}).get(&#34;bot_id&#34;)
if self._is_self_event(auth_result, req.context.user_id, bot_id, req.body):
self._debug_log(req.body)
return await req.context.ack()
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,35 @@ <h1 class="title">Module <code>slack_bolt.middleware.ignoring_self_events.ignori
next: Callable[[], BoltResponse],
) -&gt; BoltResponse:
auth_result = req.context.authorize_result
if self._is_self_event(auth_result, req.context.user_id, req.body):
# message events can have $.event.bot_id while it does not have its user_id
bot_id = req.body.get(&#34;event&#34;, {}).get(&#34;bot_id&#34;)
if self._is_self_event(auth_result, req.context.user_id, bot_id, req.body):
self._debug_log(req.body)
return req.context.ack()
else:
return next()

# -----------------------------------------

# Its an Events API event that isn&#39;t of type message,
# It&#39;s an Events API event that isn&#39;t of type message,
# but the user ID might match our own app. Filter these out.
# However, some events still must be fired, because they can make sense.
events_that_should_be_kept = [&#34;member_joined_channel&#34;, &#34;member_left_channel&#34;]

@classmethod
def _is_self_event(cls, auth_result: AuthorizeResult, user_id: str, body: Dict[str, Any]):
def _is_self_event(
cls,
auth_result: AuthorizeResult,
user_id: Optional[str],
bot_id: Optional[str],
body: Dict[str, Any],
):
return (
auth_result is not None
and user_id is not None
and user_id == auth_result.bot_user_id
and (
(user_id is not None and user_id == auth_result.bot_user_id)
or (bot_id is not None and bot_id == auth_result.bot_id) # for bot_message events
)
and body.get(&#34;event&#34;) is not None
and body.get(&#34;event&#34;, {}).get(&#34;type&#34;) not in cls.events_that_should_be_kept
)
Expand Down Expand Up @@ -111,25 +121,35 @@ <h2 class="section-title" id="header-classes">Classes</h2>
next: Callable[[], BoltResponse],
) -&gt; BoltResponse:
auth_result = req.context.authorize_result
if self._is_self_event(auth_result, req.context.user_id, req.body):
# message events can have $.event.bot_id while it does not have its user_id
bot_id = req.body.get(&#34;event&#34;, {}).get(&#34;bot_id&#34;)
if self._is_self_event(auth_result, req.context.user_id, bot_id, req.body):
self._debug_log(req.body)
return req.context.ack()
else:
return next()

# -----------------------------------------

# Its an Events API event that isn&#39;t of type message,
# It&#39;s an Events API event that isn&#39;t of type message,
# but the user ID might match our own app. Filter these out.
# However, some events still must be fired, because they can make sense.
events_that_should_be_kept = [&#34;member_joined_channel&#34;, &#34;member_left_channel&#34;]

@classmethod
def _is_self_event(cls, auth_result: AuthorizeResult, user_id: str, body: Dict[str, Any]):
def _is_self_event(
cls,
auth_result: AuthorizeResult,
user_id: Optional[str],
bot_id: Optional[str],
body: Dict[str, Any],
):
return (
auth_result is not None
and user_id is not None
and user_id == auth_result.bot_user_id
and (
(user_id is not None and user_id == auth_result.bot_user_id)
or (bot_id is not None and bot_id == auth_result.bot_id) # for bot_message events
)
and body.get(&#34;event&#34;) is not None
and body.get(&#34;event&#34;, {}).get(&#34;type&#34;) not in cls.events_that_should_be_kept
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,35 @@ <h2 class="section-title" id="header-classes">Classes</h2>
next: Callable[[], BoltResponse],
) -&gt; BoltResponse:
auth_result = req.context.authorize_result
if self._is_self_event(auth_result, req.context.user_id, req.body):
# message events can have $.event.bot_id while it does not have its user_id
bot_id = req.body.get(&#34;event&#34;, {}).get(&#34;bot_id&#34;)
if self._is_self_event(auth_result, req.context.user_id, bot_id, req.body):
self._debug_log(req.body)
return req.context.ack()
else:
return next()

# -----------------------------------------

# Its an Events API event that isn&#39;t of type message,
# It&#39;s an Events API event that isn&#39;t of type message,
# but the user ID might match our own app. Filter these out.
# However, some events still must be fired, because they can make sense.
events_that_should_be_kept = [&#34;member_joined_channel&#34;, &#34;member_left_channel&#34;]

@classmethod
def _is_self_event(cls, auth_result: AuthorizeResult, user_id: str, body: Dict[str, Any]):
def _is_self_event(
cls,
auth_result: AuthorizeResult,
user_id: Optional[str],
bot_id: Optional[str],
body: Dict[str, Any],
):
return (
auth_result is not None
and user_id is not None
and user_id == auth_result.bot_user_id
and (
(user_id is not None and user_id == auth_result.bot_user_id)
or (bot_id is not None and bot_id == auth_result.bot_id) # for bot_message events
)
and body.get(&#34;event&#34;) is not None
and body.get(&#34;event&#34;, {}).get(&#34;type&#34;) not in cls.events_that_should_be_kept
)
Expand Down
20 changes: 15 additions & 5 deletions docs/api-docs/slack_bolt/middleware/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -242,25 +242,35 @@ <h3>Inherited members</h3>
next: Callable[[], BoltResponse],
) -&gt; BoltResponse:
auth_result = req.context.authorize_result
if self._is_self_event(auth_result, req.context.user_id, req.body):
# message events can have $.event.bot_id while it does not have its user_id
bot_id = req.body.get(&#34;event&#34;, {}).get(&#34;bot_id&#34;)
if self._is_self_event(auth_result, req.context.user_id, bot_id, req.body):
self._debug_log(req.body)
return req.context.ack()
else:
return next()

# -----------------------------------------

# Its an Events API event that isn&#39;t of type message,
# It&#39;s an Events API event that isn&#39;t of type message,
# but the user ID might match our own app. Filter these out.
# However, some events still must be fired, because they can make sense.
events_that_should_be_kept = [&#34;member_joined_channel&#34;, &#34;member_left_channel&#34;]

@classmethod
def _is_self_event(cls, auth_result: AuthorizeResult, user_id: str, body: Dict[str, Any]):
def _is_self_event(
cls,
auth_result: AuthorizeResult,
user_id: Optional[str],
bot_id: Optional[str],
body: Dict[str, Any],
):
return (
auth_result is not None
and user_id is not None
and user_id == auth_result.bot_user_id
and (
(user_id is not None and user_id == auth_result.bot_user_id)
or (bot_id is not None and bot_id == auth_result.bot_id) # for bot_message events
)
and body.get(&#34;event&#34;) is not None
and body.get(&#34;event&#34;, {}).get(&#34;type&#34;) not in cls.events_that_should_be_kept
)
Expand Down
2 changes: 1 addition & 1 deletion docs/api-docs/slack_bolt/version.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h1 class="title">Module <code>slack_bolt.version</code></h1>
<span>Expand source code</span>
</summary>
<pre><code class="python">&#34;&#34;&#34;Check the latest version at https://pypi.org/project/slack-bolt/&#34;&#34;&#34;
__version__ = &#34;1.14.1&#34;</code></pre>
__version__ = &#34;1.14.2&#34;</code></pre>
</details>
</section>
<section>
Expand Down
2 changes: 1 addition & 1 deletion slack_bolt/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Check the latest version at https://pypi.org/project/slack-bolt/"""
__version__ = "1.14.1"
__version__ = "1.14.2"

0 comments on commit ff9c796

Please sign in to comment.