Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Interactive Buttons for Slack message to approve and disapprove message from Slack #4393

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MinhThieu145
Copy link
Contributor

@MinhThieu145 MinhThieu145 commented Jul 4, 2024

This pull request adds interactive buttons to the Slack message for approving and disapproving a challenge. When the buttons are clicked, the corresponding action is performed and a response message is sent back to the backend.

Demo Vid:

2024-07-04.06-54-40.mp4

@codecov-commenter
Copy link

codecov-commenter commented Jul 4, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.30%. Comparing base (96968d6) to head (b2815fd).
Report is 1110 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4393      +/-   ##
==========================================
- Coverage   72.93%   69.30%   -3.63%     
==========================================
  Files          83       20      -63     
  Lines        5368     3574    -1794     
==========================================
- Hits         3915     2477    -1438     
+ Misses       1453     1097     -356     

see 64 files with indirect coverage changes

see 64 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update da7e068...b2815fd. Read the comment docs.

@MinhThieu145
Copy link
Contributor Author

Instruction on how to add Interactive Endpoint to Slack:
In order for Slack to interact with our back-end, we would need an open HTTP endpoint. After creating the url, go to your Slack API APP -> Basic Information on the column on the left -> Interactive Component
image

Then you can paste in your endpoint to Request URL. You may have to enable it first and add the bot to the channel. Read more here: https://api.slack.com/messaging/interactivity
image

@MinhThieu145
Copy link
Contributor Author

Instruction for the Slack Bot authentication

Our bot will use the personal token to verify the source of the request. You'll have to go to your app -> Basic Information -> App Credentials -> Then Copy your Verification Token, created an env variable called SLACK_VERIFICATION_TOKEN and pastein your token

image

"username": "EvalAI",
}
else:
data = message
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add condition to support 2 types of Slack message:

  • Normal text message
  • Message with interactive buttons (like the approve, disapprove)

@@ -260,6 +260,39 @@ def is_active(self):
return False


def slack_challenge_approval_callback(challenge_id):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A function similar to create_eks_cluster_or_ec2_for_challenge but used for Slack (cause we don't have instance and created if we call this function in our backend)

r"^challenge/slack_actions/$",
views.slack_actions,
name="challenge_slack_actions",
),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An open endpoint for slack to send any action to (any click or any interaction will be sent here)

models.slack_challenge_approval_callback(challenge_id)

return JsonResponse(
{"text": f"Challenge {challenge_id} has been disapproved"}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle the request from Slack, include our custom autherization method

"name": "approval",
"text": "No",
"type": "button",
"value": f"disapprove_{challenge_pk}",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add buttons to the Slack Message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants