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 ccdf0f3 commit 4f90354
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions forum/forum/integrations/slack_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
TextObject,
LinkButtonElement,
DividerBlock,
HeaderBlock, MarkdownTextObject,
HeaderBlock, MarkdownTextObject, Block,
)
from slack_sdk.models.messages.message import Message
from slack_sdk.models.views import View
from slack_sdk.signature import SignatureVerifier

Expand Down Expand Up @@ -111,6 +110,7 @@ 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:
Expand All @@ -121,6 +121,7 @@ def send_message_to_user(user_id: str, message: Dict[str, Any]):
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):
if not config.SLACK_BOT_TOKEN:
Expand Down Expand Up @@ -283,12 +284,10 @@ def verify_request(request) -> bool:
def questions_slack_message(questions: List[Question]) -> Dict[str, Any]:
question_ids = [str(q.id) for q in questions]
logger.debug(f"Sending to slack question IDs ({','.join(question_ids)})")
blocks = list()
blocks: List[Block] = list()
for question in questions:
question_url = get_model_url_with_base("question", question)
blocks.append(
HeaderBlock(text=question.title, )
)
blocks.append(HeaderBlock(text=question.title, ))
content = question.content[:1000]
content = content.split("\r\n")
num_lines = len(content)
Expand All @@ -299,8 +298,8 @@ def questions_slack_message(questions: List[Question]) -> Dict[str, Any]:
SectionBlock(
text=MarkdownTextObject(text=content),
accessory=LinkButtonElement(text="Go to question", url=question_url),
).to_dict()
)
)
blocks.append(DividerBlock().to_dict())
res = dict(blocks=blocks)
blocks.append(DividerBlock())
res = dict(blocks=[b.to_dict() for b in blocks])
return res

0 comments on commit 4f90354

Please sign in to comment.