|
import streamlit as st |
|
import smtplib |
|
from email.mime.multipart import MIMEMultipart |
|
from email.mime.text import MIMEText |
|
from email.mime.base import MIMEBase |
|
from email import encoders |
|
import requests |
|
import base64 |
|
import os |
|
|
|
|
|
|
|
|
|
def get_base64_image(image_path): |
|
with open(image_path, "rb") as image_file: |
|
return base64.b64encode(image_file.read()).decode() |
|
|
|
|
|
|
|
|
|
Slack_email_addresses = { |
|
'Rahul Mandowara': '[email protected]', |
|
'Abhimanyu':'[email protected]', |
|
'VS': '[email protected]', |
|
'ninadmandavkar': '[email protected]', |
|
'Priyanshi Nahata': '[email protected]', |
|
'kiran jadhav': '[email protected]', |
|
'Bhavin Parmar': '[email protected]', |
|
'RJ': '[email protected]', |
|
'Roshani Mohan': '[email protected]', |
|
'omkarsp': '[email protected]', |
|
'Abhilash Sawant': '[email protected]', |
|
'Hemant Yadav': '[email protected]', |
|
'SandeeP Salunkhe': '[email protected]', |
|
'Sid': '[email protected]', |
|
'chetanpatole': '[email protected]', |
|
'Shweta Kanungo': '[email protected]', |
|
'chandnichaurasia': '[email protected]', |
|
'Rasika': '[email protected]', |
|
'Bhushan Khapare': '[email protected]', |
|
'Vaibhavi':'[email protected]', |
|
'Khushbu':'[email protected]', |
|
'daily-alerts-for-unsubscribed-companies': 'daily-alerts-for-unsu-aaaanufptnpzgjtmknapgi45oq@gofynd.slack.com', |
|
'finance_team_internal': 'finance_team_internal-aaaabrz6gd5km3hjwxs7saxa4a@gofynd.slack.com', |
|
'valyx-fynd-poc': '[email protected]', |
|
'valyx_auto_invoices': '[email protected]', |
|
'recon-check': '[email protected]' |
|
} |
|
|
|
gmail_addresses = { |
|
'Rahul Mandowara': '[email protected]', |
|
'Abhimanyu':'[email protected]', |
|
'VS': '[email protected]', |
|
'ninadmandavkar': '[email protected]', |
|
'omkarsp': '[email protected]', |
|
'Priyanshi Nahata': '[email protected]', |
|
'kiran jadhav': '[email protected]', |
|
'Bhavin Parmar': '[email protected]', |
|
'RJ': '[email protected]', |
|
'Roshani Mohan': '[email protected]', |
|
'Abhilash Sawant': '[email protected]', |
|
'Hemant Yadav': '[email protected]', |
|
'SandeeP Salunkhe': '[email protected]', |
|
'Sid': '[email protected]', |
|
'chetanpatole': '[email protected]', |
|
'Shweta Kanungo': '[email protected]', |
|
'chandnichaurasia': '[email protected]', |
|
'Rasika': '[email protected]', |
|
'Bhushan Khapare': '[email protected]', |
|
'Vaibhavi': '[email protected]', |
|
'Khushbu': '[email protected]', |
|
'daily-alerts-for-unsubscribed-companies': 'daily-alerts-for-unsu-aaaanufptnpzgjtmknapgi45oq@gofynd.slack.com', |
|
'finance_team_internal': 'finance_team_internal-aaaabrz6gd5km3hjwxs7saxa4a@gofynd.slack.com', |
|
'valyx-fynd-poc': '[email protected]', |
|
'valyx_auto_invoices': '[email protected]', |
|
'recon-check': '[email protected]' |
|
} |
|
|
|
Webhook_urls = { |
|
'Rahul Mandowara': 'https://hooks.slack.com/services/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', |
|
'Abhimanyu':'https://hooks.slack.com/services/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', |
|
'VS': 'https://hooks.slack.com/services/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', |
|
'ninadmandavkar': 'https://hooks.slack.com/services/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', |
|
'Priyanshi Nahata': 'https://hooks.slack.com/services/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', |
|
'kiran jadhav': 'https://hooks.slack.com/services/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', |
|
'Bhavin Parmar': 'https://hooks.slack.com/services/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', |
|
'RJ': 'https://hooks.slack.com/services/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', |
|
'Roshani Mohan': 'https://hooks.slack.com/services/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', |
|
'omkarsp': 'https://hooks.slack.com/services/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', |
|
'Abhilash Sawant': 'https://hooks.slack.com/services/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', |
|
'Hemant Yadav': 'https://hooks.slack.com/services/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', |
|
'SandeeP Salunkhe': 'https://hooks.slack.com/services/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', |
|
'Sid': 'https://hooks.slack.com/services/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', |
|
'chetanpatole': 'https://hooks.slack.com/services/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', |
|
'Shweta Kanungo': 'https://hooks.slack.com/services/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', |
|
'chandnichaurasia': 'https://hooks.slack.com/services/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', |
|
'Rasika': 'https://hooks.slack.com/services/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', |
|
'Khushbu': 'https://hooks.slack.com/services/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', |
|
'Bhushan Khapare': 'https://hooks.slack.com/services/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', |
|
'Vaibhavi': 'https://hooks.slack.com/services/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', |
|
'daily-alerts-for-unsubscribed-companies': 'https://hooks.slack.com/services/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', |
|
'finance_team_internal': 'https://hooks.slack.com/services/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', |
|
'valyx-fynd-poc': 'https://hooks.slack.com/services/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', |
|
'valyx_auto_invoices': 'https://hooks.slack.com/services/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', |
|
'recon-check': 'https://hooks.slack.com/services/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' |
|
} |
|
|
|
|
|
EMAIL_HOST = 'smtp.gmail.com' |
|
EMAIL_PORT = 587 |
|
EMAIL_HOST_USER = '[email protected]' |
|
EMAIL_HOST_PASSWORD = 'etdv kmvs qbsi zose' |
|
|
|
def send_message_via_email(message, email_address, files, subject=None, body=None): |
|
try: |
|
|
|
server = smtplib.SMTP(EMAIL_HOST, EMAIL_PORT) |
|
server.starttls() |
|
server.login(EMAIL_HOST_USER, EMAIL_HOST_PASSWORD) |
|
|
|
|
|
msg = MIMEMultipart() |
|
msg['From'] = EMAIL_HOST_USER |
|
msg['To'] = email_address |
|
msg['Subject'] = subject if subject else "🚨 Alerter" |
|
|
|
|
|
msg.attach(MIMEText(body if body else message, 'plain')) |
|
|
|
|
|
if files: |
|
for uploaded_file in files: |
|
part = MIMEBase('application', 'octet-stream') |
|
part.set_payload(uploaded_file.read()) |
|
encoders.encode_base64(part) |
|
part.add_header('Content-Disposition', f'attachment; filename={uploaded_file.name}') |
|
msg.attach(part) |
|
|
|
|
|
server.sendmail(EMAIL_HOST_USER, email_address, msg.as_string()) |
|
server.quit() |
|
return True, "Message sent successfully" |
|
except Exception as e: |
|
return False, str(e) |
|
|
|
def send_message_via_webhook(message, webhook_url): |
|
try: |
|
payload = { |
|
"text": message |
|
} |
|
response = requests.post(webhook_url, json=payload) |
|
response.raise_for_status() |
|
return True, "Message sent successfully" |
|
except requests.exceptions.RequestException as e: |
|
return False, str(e) |
|
|
|
def main(): |
|
|
|
|
|
image_path = "Designer (1).png" |
|
base64_image = get_base64_image(image_path) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
html_subject = """ |
|
<html> |
|
<head> |
|
<style> |
|
.button { |
|
display: inline-block; |
|
padding: 10px 20px; |
|
border-radius: 12px; |
|
background: linear-gradient(to bottom, #f8f9fa, #e0e0e0); |
|
box-shadow: |
|
0 6px 12px rgba(0, 0, 0, 0.3), |
|
0 8px 16px rgba(0, 0, 0, 0.2), |
|
inset 0 -2px 4px rgba(255, 255, 255, 0.6); |
|
text-align: center; |
|
position: relative; |
|
transform: translateY(4px); |
|
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out; |
|
cursor: pointer; |
|
user-select: none; |
|
} |
|
.button:hover { |
|
box-shadow: |
|
0 8px 16px rgba(0, 0, 0, 0.3), |
|
0 12px 24px rgba(0, 0, 0, 0.2); |
|
transform: translateY(2px); |
|
} |
|
.button:active { |
|
box-shadow: |
|
0 4px 8px rgba(0, 0, 0, 0.3), |
|
0 6px 12px rgba(0, 0, 0, 0.2); |
|
transform: translateY(0); |
|
} |
|
</style> |
|
</head> |
|
<body> |
|
<div class="button"> |
|
<h3 style=" |
|
font-size: 20px; |
|
color: #ffffff; |
|
background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9); |
|
background-clip: text; |
|
-webkit-background-clip: text; |
|
text-fill-color: transparent; |
|
-webkit-text-fill-color: transparent; |
|
margin: 0; |
|
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4); |
|
">Write a Slack message</h3> |
|
</div> |
|
</body> |
|
</html> |
|
""" |
|
|
|
|
|
|
|
st.markdown(html_subject, unsafe_allow_html=True) |
|
message = st.text_area("", "") |
|
|
|
|
|
|
|
html_subject = """ |
|
<html> |
|
<head> |
|
<style> |
|
.button { |
|
display: inline-block; |
|
padding: 10px 20px; |
|
border-radius: 12px; |
|
background: linear-gradient(to bottom, #f8f9fa, #e0e0e0); |
|
box-shadow: |
|
0 6px 12px rgba(0, 0, 0, 0.3), |
|
0 8px 16px rgba(0, 0, 0, 0.2), |
|
inset 0 -2px 4px rgba(255, 255, 255, 0.6); |
|
text-align: center; |
|
position: relative; |
|
transform: translateY(4px); |
|
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out; |
|
cursor: pointer; |
|
user-select: none; |
|
} |
|
.button:hover { |
|
box-shadow: |
|
0 8px 16px rgba(0, 0, 0, 0.3), |
|
0 12px 24px rgba(0, 0, 0, 0.2); |
|
transform: translateY(2px); |
|
} |
|
.button:active { |
|
box-shadow: |
|
0 4px 8px rgba(0, 0, 0, 0.3), |
|
0 6px 12px rgba(0, 0, 0, 0.2); |
|
transform: translateY(0); |
|
} |
|
</style> |
|
</head> |
|
<body> |
|
<div class="button"> |
|
<h3 style=" |
|
font-size: 20px; |
|
color: #ffffff; |
|
background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9); |
|
background-clip: text; |
|
-webkit-background-clip: text; |
|
text-fill-color: transparent; |
|
-webkit-text-fill-color: transparent; |
|
margin: 0; |
|
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4); |
|
">Upload documents</h3> |
|
</div> |
|
</body> |
|
</html> |
|
""" |
|
|
|
|
|
st.markdown(html_subject, unsafe_allow_html=True) |
|
uploaded_file = st.file_uploader("", type=["pdf", "docx", "png", "jpeg", "xlsx", "csv", "json"], key="file_uploader", accept_multiple_files= True) |
|
|
|
|
|
options = list(Slack_email_addresses.keys()) |
|
html_subject = """ |
|
<html> |
|
<head> |
|
<style> |
|
.button { |
|
display: inline-block; |
|
padding: 10px 20px; |
|
border-radius: 12px; |
|
background: linear-gradient(to bottom, #f8f9fa, #e0e0e0); |
|
box-shadow: |
|
0 6px 12px rgba(0, 0, 0, 0.3), |
|
0 8px 16px rgba(0, 0, 0, 0.2), |
|
inset 0 -2px 4px rgba(255, 255, 255, 0.6); |
|
text-align: center; |
|
position: relative; |
|
transform: translateY(4px); |
|
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out; |
|
cursor: pointer; |
|
user-select: none; |
|
} |
|
.button:hover { |
|
box-shadow: |
|
0 8px 16px rgba(0, 0, 0, 0.3), |
|
0 12px 24px rgba(0, 0, 0, 0.2); |
|
transform: translateY(2px); |
|
} |
|
.button:active { |
|
box-shadow: |
|
0 4px 8px rgba(0, 0, 0, 0.3), |
|
0 6px 12px rgba(0, 0, 0, 0.2); |
|
transform: translateY(0); |
|
} |
|
</style> |
|
</head> |
|
<body> |
|
<div class="button"> |
|
<h3 style=" |
|
font-size: 20px; |
|
color: #ffffff; |
|
background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9); |
|
background-clip: text; |
|
-webkit-background-clip: text; |
|
text-fill-color: transparent; |
|
-webkit-text-fill-color: transparent; |
|
margin: 0; |
|
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4); |
|
">Select channels/members</h3> |
|
</div> |
|
</body> |
|
</html> |
|
""" |
|
|
|
|
|
st.markdown(html_subject, unsafe_allow_html=True) |
|
selection = st.multiselect("", options) |
|
|
|
html_subject = """ |
|
<html> |
|
<head> |
|
<style> |
|
.button { |
|
display: inline-block; |
|
padding: 10px 20px; |
|
border-radius: 12px; |
|
background: linear-gradient(to bottom, #f8f9fa, #e0e0e0); |
|
box-shadow: |
|
0 6px 12px rgba(0, 0, 0, 0.3), |
|
0 8px 16px rgba(0, 0, 0, 0.2), |
|
inset 0 -2px 4px rgba(255, 255, 255, 0.6); |
|
text-align: center; |
|
position: relative; |
|
transform: translateY(4px); |
|
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out; |
|
cursor: pointer; |
|
user-select: none; |
|
} |
|
.button:hover { |
|
box-shadow: |
|
0 8px 16px rgba(0, 0, 0, 0.3), |
|
0 12px 24px rgba(0, 0, 0, 0.2); |
|
transform: translateY(2px); |
|
} |
|
.button:active { |
|
box-shadow: |
|
0 4px 8px rgba(0, 0, 0, 0.3), |
|
0 6px 12px rgba(0, 0, 0, 0.2); |
|
transform: translateY(0); |
|
} |
|
</style> |
|
</head> |
|
<body> |
|
<div class="button"> |
|
<h3 style=" |
|
font-size: 20px; |
|
color: #ffffff; |
|
background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9); |
|
background-clip: text; |
|
-webkit-background-clip: text; |
|
text-fill-color: transparent; |
|
-webkit-text-fill-color: transparent; |
|
margin: 0; |
|
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4); |
|
">Enter the subject(optional)</h3> |
|
</div> |
|
</body> |
|
</html> |
|
""" |
|
|
|
|
|
st.markdown(html_subject, unsafe_allow_html=True) |
|
subject = st.text_input("", "",key ="subject_text_input") |
|
|
|
|
|
|
|
html_subject = """ |
|
<html> |
|
<head> |
|
<style> |
|
.button { |
|
display: inline-block; |
|
padding: 10px 20px; |
|
border-radius: 12px; |
|
background: linear-gradient(to bottom, #f8f9fa, #e0e0e0); |
|
box-shadow: |
|
0 6px 12px rgba(0, 0, 0, 0.3), |
|
0 8px 16px rgba(0, 0, 0, 0.2), |
|
inset 0 -2px 4px rgba(255, 255, 255, 0.6); |
|
text-align: center; |
|
position: relative; |
|
transform: translateY(4px); |
|
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out; |
|
cursor: pointer; |
|
user-select: none; |
|
} |
|
.button:hover { |
|
box-shadow: |
|
0 8px 16px rgba(0, 0, 0, 0.3), |
|
0 12px 24px rgba(0, 0, 0, 0.2); |
|
transform: translateY(2px); |
|
} |
|
.button:active { |
|
box-shadow: |
|
0 4px 8px rgba(0, 0, 0, 0.3), |
|
0 6px 12px rgba(0, 0, 0, 0.2); |
|
transform: translateY(0); |
|
} |
|
</style> |
|
</head> |
|
<body> |
|
<div class="button"> |
|
<h3 style=" |
|
font-size: 20px; |
|
color: #ffffff; |
|
background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9); |
|
background-clip: text; |
|
-webkit-background-clip: text; |
|
text-fill-color: transparent; |
|
-webkit-text-fill-color: transparent; |
|
margin: 0; |
|
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4); |
|
">Enter the body (optional)</h3> |
|
</div> |
|
</body> |
|
</html> |
|
""" |
|
|
|
|
|
st.markdown(html_subject, unsafe_allow_html=True) |
|
body = st.text_area("", "", key="body_text_area") |
|
|
|
|
|
button_styles = """ |
|
<style> |
|
div.stButton > button { |
|
color: #ffffff; /* Text color */ |
|
font-size: 30px; |
|
background-image: linear-gradient(to right, #800000, #ff0000); /* Maroon to light red gradient */ |
|
border: none; |
|
padding: 10px 20px; |
|
cursor: pointer; |
|
border-radius: 15px; |
|
display: inline-block; |
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 8px 15px rgba(0, 0, 0, 0.1); /* Box shadow */ |
|
transition: all 0.3s ease; /* Smooth transition on hover */ |
|
} |
|
div.stButton > button:hover { |
|
background-color: #00ff00; /* Hover background color */ |
|
color: #ff0000; /* Hover text color */ |
|
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.2), 0 12px 20px rgba(0, 0, 0, 0.2); /* Box shadow on hover */ |
|
} |
|
</style> |
|
""" |
|
st.markdown(button_styles, unsafe_allow_html=True) |
|
|
|
col1, col2 = st.columns([0.125, 0.5]) |
|
with col1: |
|
if st.button("Send to Slack"): |
|
if not message and not uploaded_file: |
|
st.error("Please enter a message or upload a document before sending.") |
|
return |
|
|
|
if not selection: |
|
st.error("Please select at least one channel or member") |
|
return |
|
|
|
for item in selection: |
|
if uploaded_file: |
|
|
|
email_address = Slack_email_addresses.get(item) |
|
if email_address: |
|
success, response_message = send_message_via_email(message, email_address, uploaded_file, subject, body) |
|
|
|
|
|
|
|
|
|
else: |
|
st.error(f"No email address found for {item}.") |
|
elif message: |
|
|
|
webhook_url = Webhook_urls.get(item) |
|
if webhook_url: |
|
success, response_message = send_message_via_webhook(message, webhook_url) |
|
|
|
|
|
|
|
|
|
else: |
|
st.error(f"No webhook URL found for {item}.") |
|
|
|
with col2: |
|
if st.button("Send to Gmail"): |
|
if not message and not uploaded_file: |
|
st.error("Please enter a message or upload a document before sending.") |
|
return |
|
|
|
if not selection: |
|
st.error("Please select at least one channel or member") |
|
return |
|
|
|
for item in selection: |
|
email_address = gmail_addresses.get(item) |
|
if email_address: |
|
success, response_message = send_message_via_email(message, email_address, uploaded_file, subject, body) |
|
|
|
|
|
|
|
|
|
else: |
|
st.error(f"No Gmail address found for {item}.") |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|