Spaces:
Sleeping
Sleeping
import json | |
import requests | |
class SlackNotifier: | |
def __init__(self, webhook_url): | |
""" | |
Initializes the SlackNotifier with the webhook URL. | |
:param webhook_url: The Slack webhook URL for sending messages. | |
""" | |
self.webhook_url = webhook_url | |
def send_message(self, text): | |
""" | |
Sends a plain text message to Slack. | |
:param text: The message to send. | |
:raises: Exception if the message fails to send. | |
""" | |
payload = {"text": text} | |
response = requests.post( | |
self.webhook_url, | |
data=json.dumps(payload), | |
headers={"Content-Type": "application/json"} | |
) | |
if response.status_code != 200: | |
raise RuntimeError(f"Failed to send message to Slack: {response.status_code}, {response.text}") | |
def send_candidate_info(self, name, email, years_of_experience, skills, performance_score=None): | |
""" | |
Sends a formatted message with candidate information to Slack. | |
:param name: Candidate's name. | |
:param email: Candidate's email. | |
:param years_of_experience: Total years of experience. | |
:param skills: Candidate's skills. | |
:param performance_score: Candidate's performance score (optional). | |
""" | |
message = ( | |
f"*Candidate Assessment Report*\n\n" | |
f"*Name:* {name}\n" | |
f"*Email:* {email}\n" | |
f"*Experience:* {years_of_experience} years\n" | |
f"*Skills:* {skills}\n" | |
f"*Performance Score:* {performance_score if performance_score is not None else 'N/A'}\n" | |
) | |
self.send_message(message) |