Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
update slackbot;relates #30
Browse files Browse the repository at this point in the history
  • Loading branch information
mageirakos committed Mar 13, 2021
1 parent f26e0f8 commit 181ee6c
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions api/slackbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
signing_secret=os.environ.get("SLACK_SIGNING_SECRET"),
)


@app.event("app_mention")
def mention_handler(body, say):
event = body["event"]
slack_user_id = event["user"]
text = event["text"]
# find the mention pattern start, skip the `<@id>` and keep the rest as the question
question = text[text.find(f"<@") + 2 + len(slack_user_id) + 1 :].lstrip()
question = text[text.find(f"<@")+2+len(slack_user_id)+1:].lstrip()
say(
{
"blocks": [
Expand All @@ -43,7 +42,7 @@ def mention_handler(body, say):
{
"type": "button",
"text": {"type": "plain_text", "text": "FAQs"},
"value": f"{question}",
"value": f"{question}",
"action_id": "faq_button",
},
{
Expand Down Expand Up @@ -93,7 +92,7 @@ def search_faqs(body, ack, say):
"type": "plain_text",
"text": ":white_check_mark:",
},
"value": f"{answer_id}",
"value": f"{answer_id}",
"action_id": "correct_answer",
},
{
Expand Down Expand Up @@ -146,7 +145,7 @@ def search_docs(body, ack, say):
"type": "plain_text",
"text": ":white_check_mark:",
},
"value": f"{answer_id}",
"value": f"{answer_id}",
"action_id": "correct_answer",
},
{
Expand All @@ -160,10 +159,8 @@ def search_docs(body, ack, say):
]
}
)

return


@app.action("correct_answer")
def label_correct(body, client, ack, say):
ack()
Expand All @@ -182,7 +179,7 @@ def label_correct(body, client, ack, say):

answer_id = body["actions"][0]["value"]
# 1 is the positive label
donkeybot.update_label(answer_id, label=1)
donkeybot.update_label(answer_id, label=1)

client.reactions_add(
channel=body["channel"]["id"],
Expand All @@ -191,7 +188,6 @@ def label_correct(body, client, ack, say):
)
return


@app.action("wrong_answer")
def label_wrong(body, client, ack, say):
ack()
Expand Down

0 comments on commit 181ee6c

Please sign in to comment.