How to Build an AI Sales Development Representative (SDR) in Slack - Part 1: AI-Powered Lead Generation
Introduction #
In this guide, we'll create an AI sales assistant that allows you to request leads using natural language in Slack. The assistant will then translate those queries into valid API calls to the Apollo.io API to fetch a list of leads that fit your request.
This guide is Part 1 of a six-part series for how to build your own AI SDR (Sales Development Representative) in Slack. The subsequent guides are linked at the bottom of this post.
Getting Started #
To begin building your AI sales assistant, fork this template below:
To power your AI for lead generation, you'll need to set up API keys for Slack, Apollo.io, and OpenAI. Here's how to obtain each:
Slack App
- Go to the Slack Apps dashboard and create a new app.
- In your app's settings, navigate to the "Basic Information" page.
- Scroll down to the "App-Level Tokens" section.
- Click on "Generate Token and Scopes" to create a new app-level token.
- Provide a name for your token.
- Add the following scopes for your app:
- connections:write (for Socket Mode)
- Click "Generate" to create the token. This is your SLACK_APP_TOKEN: Your app token - it should start with xapp
- Navigate to "OAuth & Permissions" and find your "Bot User OAuth Token". This is your SLACK_BOT_TOKEN: Your bot user OAuth token - it should start with xoxb
- For your Bot Token, set the following permissions. You can also add these in the "oauth_config" section in your App Manifest JSON
In Replit, go to the Secrets tab (Tools > Secrets) and add the credentials to your secrets within SLACK_APP_TOKEN and SLACK_BOT_TOKEN respectively.
If you want a character for your new Slack App, feel free to download this little guy:
Apollo API Key
- Log in to your Apollo account and navigate to your Account Settings - Integrations.
- Click on API Keys in the list of integrations
- This will take you to the API keys section of your account
- Click on the Create new key button and name your new API key.
- Create the new API key and copy the value
- Head to your Replit project and open the Secrets tool (shortcut: Cmd + K and search for "Secrets").
- Paste in your Apollo API key into the APOLLO_API_KEY value.
If you do not see API selection options, you may need to upgrade your account to Apollo’s Basic tier.
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.
Breaking Down the AI Sales Assistant Code #
Query Analysis with OpenAI
The analyze_query function in query_analyzer.py uses OpenAI's GPT-4o-mini model to interpret natural language queries and convert them into structured search parameters, enhancing the AI's lead generation capabilities:
This function is crucial for the AI sales assistant to understand and process natural language queries, translating them into actionable search parameters for lead generation.
Apollo.io API Integration for AI-Powered Lead Generation
The utils.py file contains functions for interacting with the Apollo.io API, allowing our AI SDR to fetch relevant leads:
These functions enable the AI sales assistant to perform targeted searches for organizations and individuals, forming the core of its lead generation capabilities.
Slack Bot Integration for Your AI SDR
The main.py file sets up the Slack bot, allowing your AI sales assistant to interact with users and deliver lead generation results:
This code allows the AI SDR to listen for mentions in Slack, process user queries, generate leads, and deliver results, showcasing the practical application of AI for lead generation in a familiar communication platform.
Deploying Your AI SDR #
In order to keep your AI SDR running 24/7 and receive requests whenever someone mentions it in Slack, you'll need to deploy it on a hosted server.
Open a new tab in the Workspace and search for “Deployments” or open the control console by typing ⌘ + K (or Ctrl + K) and type "deploy". You should find a screen like this.
For bots like this that need always need to be up listening to requests, we recommend using a Reserved VM. On the next screen, click Approve and configure build settings most internal bots work fine with the default machine settings but if you need more power later, you can always come back and change these settings later. You can monitor your usage and billing at any time at: replit.com/usage.
On the next screen, you’ll be able to set your primary domain and edit the Secrets that will be in your production deployment. Usually, we keep these settings as they are.
Finally, click Deploy and watch your bot go live!
What's Next for Your AI Sales Assistant #
In the next part of this series, we'll be adding the ability for the assistant to enrich the lead list with email addresses using Clay. The other parts of the series include:
- AI SDR - Part 1 (this guide) - Lead List Creation
- AI SDR - Part 2 - Lead Enrichment
- AI SDR - Part 3 - Draft Email Copy
- AI SDR - Part 4 - Create Smartlead campaign
- AI SDR - Part 5 - Add Leads to HubSpot
- AI SDR - Part 6 (Final) - Agent Mode
If you'd like to discuss how to enable your team to build and implement tools like these, feel free to schedule some time with the Replit team for a quick demo of our product.
Happy coding and selling!