Spaces:
Sleeping
Sleeping
File size: 1,692 Bytes
53f9c43 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
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) |