many-controller-54194
10/06/2025, 10:11 PMtall-airline-16756
10/06/2025, 10:11 PMtall-airline-16756
10/06/2025, 10:11 PMmany-controller-54194
10/07/2025, 2:54 PMtall-airline-16756
10/07/2025, 2:55 PMmany-controller-54194
10/07/2025, 3:06 PMtall-airline-16756
10/07/2025, 3:06 PMsmtplib library to set up and send emails. Here's a simple example to help you out:
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_email(subject, body, to_emails):
smtp_server = "your.smtp.server"
smtp_port = 587
smtp_user = "your_username"
smtp_password = "your_password"
msg = MIMEMultipart()
msg['From'] = smtp_user
msg['To'] = ", ".join(to_emails)
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
with smtplib.SMTP(smtp_server, smtp_port) as server:
server.starttls()
server.login(smtp_user, smtp_password)
server.sendmail(smtp_user, to_emails, msg.as_string())
1. Then, integrate this function into your LiveKit Agent’s workflow so it triggers right when a session ends.
2. Using an External Backend Service:
1. You can also set up a backend service using something like Flask or Node.js that listens for session-end events from LiveKit.
2. Configure your LiveKit Agent to send session data to this backend through a webhook or API call when a session finishes.
3. In your backend, use an SMTP library or a third-party email service (like AWS SES or SendGrid) to send the email. Here's a simple Flask example to illustrate:
from flask import Flask, request
import smtplib
app = Flask(__name__)
@app.route('/send-email', methods=['POST'])
def send_email():
data = request.json
subject = data['subject']
body = data['body']
to_emails = data['to_emails']
# Use the same smtplib code as above to send the email
return "Email sent!", 200
if __name__ == '__main__':
app.run(port=5000)
1. Just a quick reminder to make sure your backend is secure and properly handles authentication and error handling.
If you have any questions or need more details on either method, please don’t hesitate to ask—I’m here to help!many-controller-54194
10/07/2025, 3:55 PMtall-airline-16756
10/07/2025, 3:56 PMimport smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_email(subject, body, to_emails):
smtp_server = "your.smtp.server"
smtp_port = 587
smtp_user = "your_username"
smtp_password = "your_password"
msg = MIMEMultipart()
msg['From'] = smtp_user
msg['To'] = ", ".join(to_emails)
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
with smtplib.SMTP(smtp_server, smtp_port) as server:
server.starttls()
server.login(smtp_user, smtp_password)
server.sendmail(smtp_user, to_emails, msg.as_string())
2. Modify the SummaryAgent:
In your SummaryAgent, once you've summarized the responses, you can call the send_email function like this:
class SummaryAgent(BaseAgent):
def __init__(self, job_context: JobContext) -> None:
super().__init__(
job_context=job_context,
instructions="Summarize all responses and end the survey."
)
async def on_enter(self) -> None:
sd: SurveyData = self.session.userdata
summary = "Thank you for completing the survey! Here are your responses:\n"
for q, a in sd.responses.items():
summary += f"- {q}: {a}\n"
await self.session.say(summary)
logger.info("Survey complete. Closing session.")
# Send email with survey summary
try:
send_email(
subject="Survey Summary",
body=summary,
to_emails=["recipient1@example.com", "recipient2@example.com"]
)
logger.info("Email sent successfully.")
except Exception as e:
logger.error(f"Error sending email: {e}")
await self.session.aclose()
try:
await self.job_context.api.room.delete_room(
api.DeleteRoomRequest(room=self.job_context.room.name)
)
except Exception as e:
logger.error(f"Error deleting room: {e}")
3. Test the Workflow:
1. Double-check that your SMTP credentials and server details are all set correctly.
2. Run your agent and complete a session to make sure the email with the session summary is sent smoothly.
If you have any questions or run into any issues, please don't hesitate to reach out—I'm here to help!many-controller-54194
10/07/2025, 6:43 PMtall-airline-16756
10/07/2025, 6:44 PMSummaryAgent or the final stage of your workflow to trigger the email function. Here’s a friendly guide on how to do it:
1. Add the Email Function:
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_email(subject, body, to_emails):
smtp_server = "your.smtp.server"
smtp_port = 587
smtp_user = "your_username"
smtp_password = "your_password"
msg = MIMEMultipart()
msg['From'] = smtp_user
msg['To'] = ", ".join(to_emails)
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
with smtplib.SMTP(smtp_server, smtp_port) as server:
server.starttls()
server.login(smtp_user, smtp_password)
server.sendmail(smtp_user, to_emails, msg.as_string())
2. Update the Final Agent (e.g., SummaryAgent):
In your SummaryAgent, right after summarizing the responses, you can call the send_email function like this:
class SummaryAgent(BaseAgent):
def __init__(self, job_context: JobContext) -> None:
super().__init__(
job_context=job_context,
instructions="Summarize all responses and end the survey."
)
async def on_enter(self) -> None:
sd: SurveyData = self.session.userdata
summary = "Thank you for completing the survey! Here are your responses:\n"
for q, a in sd.responses.items():
summary += f"- {q}: {a}\n"
await self.session.say(summary)
logger.info("Survey complete. Closing session.")
# Send email with survey summary
try:
send_email(
subject="Survey Summary",
body=summary,
to_emails=["recipient1@example.com", "recipient2@example.com"]
)
logger.info("Email sent successfully.")
except Exception as e:
logger.error(f"Error sending email: {e}")
await self.session.aclose()
try:
await self.job_context.api.room.delete_room(
api.DeleteRoomRequest(room=self.job_context.room.name)
)
except Exception as e:
logger.error(f"Error deleting room: {e}")
3. Test the Updated Flow:
1. Make sure your SMTP credentials and server details are accurate.
2. Run the agent and complete a session to confirm that the email with the session summary is sent successfully.
If you have any questions or need help tweaking this further, please don’t hesitate to reach out—I’m here to help!