Skip to content

Commit

Permalink
fix:search from slack
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Jun 29, 2024
1 parent 2d6c3c0 commit b52aff6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion forum/forum/integrations/slack_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion forum/forum/views/integrations/slack_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"})

0 comments on commit b52aff6

Please sign in to comment.