|
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 |
|
|
|
|
|
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]', |
|
'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]' |
|
} |
|
|
|
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]', |
|
'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]' |
|
|
|
} |
|
|
|
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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', |
|
'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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' |
|
} |
|
|
|
|
|
EMAIL_HOST = 'smtp.gmail.com' |
|
EMAIL_PORT = 587 |
|
EMAIL_HOST_USER = '[email protected]' |
|
EMAIL_HOST_PASSWORD = 'vxay jiss cctw lsdo' |
|
|
|
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() |
|
|