From b52aff66a89bac60547097aa51e2d89fb028beaa Mon Sep 17 00:00:00 2001 From: Daniel M Date: Sat, 29 Jun 2024 12:00:44 -0400 Subject: [PATCH] fix:search from slack --- forum/forum/integrations/slack_api.py | 11 ++++++++++- forum/forum/views/integrations/slack_views.py | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/forum/forum/integrations/slack_api.py b/forum/forum/integrations/slack_api.py index 23bb553..4043ed2 100644 --- a/forum/forum/integrations/slack_api.py +++ b/forum/forum/integrations/slack_api.py @@ -111,6 +111,15 @@ def _get_permalink(channel: str, message_ts: str) -> Union[str, None]: logger.warning(f"Couldn't find permalink to {channel}:{message_ts}, slack error: {e.response['error']}") return None +@job +def send_message_to_user(user_id: str, message: Dict[str, Any]): + if not config.SLACK_BOT_TOKEN: + return + try: + logger.info(f"sending message to user {user_id}: {message}") + slack_client.chat_postMessage(channel=user_id, **message) + except SlackApiError as e: + logger.warning(f"Got an error: {e.response['error']}") @job def slack_post_im_message_to_email(text: str, email: str, notification_text: str = None): @@ -123,7 +132,7 @@ def slack_post_im_message_to_email(text: str, email: str, notification_text: str logger.warning(f"slack user for {email} not found, returning") return blocks = [ - SectionBlock(text=TextObject(text=text, type="mrkdwn")), + SectionBlock(text=MarkdownTextObject(text=text)), ] slack_client.chat_postMessage(channel=user_id, text=notification_text or text, blocks=blocks, mrkdwn=True) except SlackApiError as e: diff --git a/forum/forum/views/integrations/slack_views.py b/forum/forum/views/integrations/slack_views.py index 00edbcc..97bf563 100644 --- a/forum/forum/views/integrations/slack_views.py +++ b/forum/forum/views/integrations/slack_views.py @@ -55,4 +55,4 @@ def search_from_slack(request): ) res = slack_api.questions_slack_message(results) logger.debug(res) - return JsonResponse(data=res, status=200) + return JsonResponse(data=res, status=200, headers={"Content-Type": "application/json"})