@@ -283,38 +283,39 @@ <h1 class="title">Module <code>slack_sdk.web.internal_utils</code></h1>
283283 if skip_deprecation:
284284 return
285285
286- # At this point, at a minimum, text argument is missing. Warn the user about this.
287- message = (
286+ # if text argument is missing, Warn the user about this.
287+ # However, do not warn if a fallback field exists for all attachments, since this can be substituted.
288+ missing_text_message = (
288289 f"The top-level `text` argument is missing in the request payload for a {endpoint} call - "
289290 f"It's a best practice to always provide a `text` argument when posting a message. "
290291 f"The `text` argument is used in places where content cannot be rendered such as: "
291292 "system push notifications, assistive technology such as screen readers, etc."
292293 )
293- warnings.warn(message, UserWarning)
294+
295+ # https://api.slack.com/reference/messaging/attachments
296+ # Check if the fallback field exists for all the attachments
297+ # Not all attachments have a fallback property; warn about this too!
298+ missing_fallback_message = (
299+ f"Additionally, the attachment-level `fallback` argument is missing in the request payload for a {endpoint} call"
300+ " - To avoid this warning, it is recommended to always provide a top-level `text` argument when posting a"
301+ " message. Alternatively you can provide an attachment-level `fallback` argument, though this is now considered"
302+ " a legacy field (see https://api.slack.com/reference/messaging/attachments#legacy_fields for more details)."
303+ )
294304
295305 # Additionally, specifically for attachments, there is a legacy field available at the attachment level called `fallback`
296306 # Even with a missing text, one can provide a `fallback` per attachment.
297307 # More details here: https://api.slack.com/reference/messaging/attachments#legacy_fields
298308 attachments = kwargs.get("attachments")
299309 # Note that this method does not verify attachments
300310 # if the value is already serialized as a single str value.
301- if (
302- attachments is not None
303- and isinstance(attachments, list)
304- and not all(
311+ if attachments is not None and isinstance(attachments, list):
312+ if not all(
305313 [isinstance(attachment, dict) and len(attachment.get("fallback", "").strip()) > 0 for attachment in attachments]
306- )
307- ):
308- # https://api.slack.com/reference/messaging/attachments
309- # Check if the fallback field exists for all the attachments
310- # Not all attachments have a fallback property; warn about this too!
311- message = (
312- f"Additionally, the attachment-level `fallback` argument is missing in the request payload for a {endpoint} call"
313- f" - To avoid this warning, it is recommended to always provide a top-level `text` argument when posting a"
314- f" message. Alternatively you can provide an attachment-level `fallback` argument, though this is now considered"
315- f" a legacy field (see https://api.slack.com/reference/messaging/attachments#legacy_fields for more details)."
316- )
317- warnings.warn(message, UserWarning)
314+ ):
315+ warnings.warn(missing_text_message, UserWarning)
316+ warnings.warn(missing_fallback_message, UserWarning)
317+ else:
318+ warnings.warn(missing_text_message, UserWarning)
318319
319320
320321def _build_unexpected_body_error_message(body: str) -> str:
0 commit comments