diff --git a/gh2slack.py b/gh2slack.py index f3c0213..7dbced2 100755 --- a/gh2slack.py +++ b/gh2slack.py @@ -273,19 +273,20 @@ def process_news( for html_url in to_publish: cache_item = cache.items[html_url] try: - msg_blocks = [ - format_message( - logger, - gh_data.repo_owner, - gh_data.repo_name, - ALIASES[gh_data.repo_section], - html_url, - cache_item, - ) - ] + msg_block = format_message( + logger, + gh_data.repo_owner, + gh_data.repo_name, + ALIASES[gh_data.repo_section], + html_url, + cache_item, + ) + msg_blocks = [msg_block] + msg_as_text = msg_block["text"]["text"] rss2slack.post_to_slack( logger, msg_blocks, + msg_as_text, slack_client, slack_channel, ) diff --git a/git_commits2slack.py b/git_commits2slack.py index 78d5d1e..902bee5 100755 --- a/git_commits2slack.py +++ b/git_commits2slack.py @@ -193,6 +193,7 @@ def main(): args.git_web, branch_name, repo_name, commit_count ) msg_blocks.insert(0, heading) + msg_as_text = heading["text"]["text"] slack_client = rss2slack.get_slack_web_client( slack_token, args.slack_base_url, args.slack_timeout @@ -200,6 +201,7 @@ def main(): rss2slack.post_to_slack( logger, msg_blocks, + msg_as_text, slack_client, args.slack_channel, ) diff --git a/phpbb2slack.py b/phpbb2slack.py index 9d67cdf..35ff527 100755 --- a/phpbb2slack.py +++ b/phpbb2slack.py @@ -224,11 +224,14 @@ def process_news( ): """Process news and post it to Slack.""" for url in list(news.keys()): - msg_blocks = [format_message(url, news[url], handle)] + msg_block = format_message(url, news[url], handle) + msg_blocks = [msg_block] + msg_as_text = msg_block["text"]["text"] try: rss2slack.post_to_slack( logger, msg_blocks, + msg_as_text, slack_client, slack_channel, ) diff --git a/requirements.txt b/requirements.txt index 22d6c1b..da04723 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ feedparser==6.0.12 requests==2.32.5 -slackclient==2.9.4 +slack-sdk==3.40.1 diff --git a/rss2slack.py b/rss2slack.py index 4d39833..f08549f 100755 --- a/rss2slack.py +++ b/rss2slack.py @@ -13,7 +13,7 @@ from typing import List from typing import Tuple -from slack import WebClient +from slack_sdk import WebClient import rss2irc from lib import cli_args @@ -174,14 +174,19 @@ def parse_args() -> argparse.Namespace: def post_to_slack( logger: logging.Logger, msg_blocks: List, + msg_as_text: str, slack_client: WebClient, slack_channel: str, ) -> None: """Post news to Slack channel.""" try: logger.debug("Will post %s", repr(msg_blocks)) + # NOTE(zstyblik): "we highly recommended that you include text to + # provide a fallback when using blocks." rsp = slack_client.chat_postMessage( - channel=slack_channel, blocks=msg_blocks + channel=slack_channel, + blocks=msg_blocks, + text=msg_as_text, ) logger.debug("Response from Slack: %s", rsp) if not rsp: @@ -208,11 +213,14 @@ def process_news( ) -> None: """Process news and post it to Slack.""" for url in list(news.keys()): - msg_blocks = [format_message(url, news[url], handle)] + msg_block = format_message(url, news[url], handle) + msg_blocks = [msg_block] + msg_as_text = msg_block["text"]["text"] try: post_to_slack( logger, msg_blocks, + msg_as_text, slack_client, slack_channel, ) diff --git a/tests/test_gh2slack.py b/tests/test_gh2slack.py index 7f3933b..c79e6c5 100644 --- a/tests/test_gh2slack.py +++ b/tests/test_gh2slack.py @@ -261,6 +261,11 @@ def test_main_ideal( } ], "channel": expected_slack_channel, + "text": ( + "[] | some title#2" + ), }, { "blocks": [ @@ -277,6 +282,11 @@ def test_main_ideal( } ], "channel": expected_slack_channel, + "text": ( + "[] " + + " | some title#1" + ), }, ] # diff --git a/tests/test_git_commits2slack.py b/tests/test_git_commits2slack.py index 5bd8856..45bae10 100644 --- a/tests/test_git_commits2slack.py +++ b/tests/test_git_commits2slack.py @@ -340,6 +340,10 @@ def test_main_ideal( }, ], "channel": expected_slack_channel, + "text": ( + " 1 commit".format(repo_name) + ), } ] # diff --git a/tests/test_phpbb2slack.py b/tests/test_phpbb2slack.py index 1851a1a..0afe4d6 100644 --- a/tests/test_phpbb2slack.py +++ b/tests/test_phpbb2slack.py @@ -137,6 +137,11 @@ def test_main_ideal( } ], "channel": expected_slack_channel, + "text": ( + "[test] (0)" + ), } ] diff --git a/tests/test_rss2slack.py b/tests/test_rss2slack.py index 2968338..b411239 100644 --- a/tests/test_rss2slack.py +++ b/tests/test_rss2slack.py @@ -115,6 +115,10 @@ def test_main_ideal( } ], "channel": expected_slack_channel, + "text": ( + "[test] " + ), }, { "blocks": [ @@ -130,6 +134,10 @@ def test_main_ideal( } ], "channel": expected_slack_channel, + "text": ( + "[test] " + ), }, ] # Mock/set SLACK_TOKEN