How to improve Smartlead email reply Slack notifications
Introduction #
Smartlead is a popular tool used for sending outbound email campaigns. They provide an out-of-the-box integration to send key event notifications (e.g. email replies) to your Slack channels.
However, some key features are missing such as:
- Tagging the owner of the original email in Slack.
- The ability to filter out any out-of-office replies.
This guide will walk you through creating an enhanced Slack system for Smartlead email reply notifications.
By the end of this tutorial, you'll have a custom notification system that tags the appropriate team member and filters out out-of-office replies using AI.
Getting Started #
To begin, fork this template by clicking "Use Template" below:
Slack Webhook URL
First, you will need a Slack Webhook URL in order to send messages to your Slack channels.
- Go to your Slack workspace apps: https://api.slack.com/apps/
- Create a new app (or use an existing one).
- In the app Settings, navigate to Incoming Webhooks and activate the feature. You might need a workspace admin to approve the permissions.
- Finally, scroll to the bottom and create a new Webhook URL.
- Connect as many channels as you need and copy the Webhook URL.
After that, head to Replit to add this URL into your Replit Secrets.
- Open Secrets by entering Cmd + K and searching for "Secrets"
- For the key SLACK_WEBHOOK, paste the Webhook URL as the value
OpenAI API Key
- Log in to the OpenAI developer platform.
- Navigate to API keys and create a new secret key.
- Copy the secret key and add it to Replit's Secrets tab as OPENAI_API_KEY.
Updating and Understanding the Code #
Update Slack User Mapping
In utils.py, modify the map_burner_emails_to_slack_users function to match your team's Smartlead burner emails with their Slack user IDs:
Replace the example email snippets and Slack user IDs with your team's actual information. To find the the Slack user IDs of your team members:
- Go to your Slack workspace
- Select your team member to open their profile view
- Click on the dots to open Settings and click on Copy member ID
- Replace the user IDs in the return statements of the map_burner_emails_to_slack_users function with the member ID copied from Slack.
The Out-of-Office AI Function
The is_ooo_reply function in utils.py uses OpenAI's gpt-4o-mini model to determine if an email reply is an out-of-office or leave of absence message.
The gpt-4o-mini model is incredibly cost-effective for this use case. At $0.15 per million tokens and the average email reply containing 300 characters, you could process ~13,000 emails before incurring a cost of $0.15.
This function sends the email reply text to the GPT-4o-mini model and asks it to determine if the message is an out-of-office reply. The model responds with either 'True' or 'False', which the function then returns.
Connecting to Smartlead #
Deploying the endpoint
In order for Smartlead to send the events to your function, you need to deploy and host your endpoint on Replit.
Open a new tab in the Replit Workspace and search for “Deployments” or open the control console by typing ⌘ + K (or Ctrl + K) and type "deploy".
In your Repl, open the Deploy tab. Choose "Autoscale" as your deployment type.
Keep the default deployment settings. They should be more than enough resources for now and you can always come back and edit the settings later.
Click the blue Deploy button to start your Autoscale deployment.
Let it run until it is complete and you get a new, production URL.
Your API is now deployed and ready to handle the webhook traffic.
Integrating with Smartlead
With your API deployed, we now have an endpoint for Smartlead to send notifications to. But we need,
- Head to Smartlead Webhook settings
- Set the following webhook configuration settings
- Be sure to replace https://YOUR_PROD_URL.replit.app/smartlead-email-reply/slack-alert with the actual URL of your deployed Repl.
After clicking the purple Add button, Smartlead should begin sending email reply notifications to your new Replit API, including the endpoints name at the end (e.g. /smartlead-email-reply/slack-alert).
Conclusion #
You now have a smarter Slack notification system for Smartlead that tags the appropriate team member and filters out out-of-office replies. This setup will help your team respond more efficiently to important email replies while reducing noise from automated responses.
What's next?
You can now add any other customization or logic to this endpoint to route or interact with any replies that come in from your Smartlead email campaigns.
Consider:
- Adding a call to the Smartlead API that marks a reply as Out of Office in the Master Inbox.
- Adding buttons to the Slack message for quick actions (e.g. "Mark as Interested")
If you’d like to bring this project and similar templates into your team, set some time here with the Replit team for a quick demo.
Happy coding!