Leveraging artificial intelligence (AI) in your HubSpot workflows can revolutionize the way you manage and engage with your contacts. By integrating AI, particularly using OpenAI's API, you can automate complex tasks such as analyzing contact data to categorize and segment it more effectively. In this tutorial, we will walk through the benefits of using AI in HubSpot workflows, how to add custom code actions to interact with OpenAI's API, and how to save the AI-generated responses into a HubSpot custom property.
Artificial Intelligence (AI) has revolutionized various industries, and HubSpot workflows are no exception. By incorporating AI into your workflows, you can unlock a range of benefits that can enhance your marketing and sales processes.
One of the key benefits of using AI in HubSpot workflows is the ability to automate repetitive tasks. With AI-powered automation, you can save time and resources by letting the system handle mundane tasks such as data entry, lead qualification, and follow-ups. This frees up your team to focus on more strategic and high-value activities.
Integrating AI into your HubSpot workflows offers numerous advantages:
By embedding AI within your workflows, you can transform raw data into actionable insights, enhancing your marketing, sales, and service efforts.
One of the powerful use cases of AI in HubSpot workflows is analyzing contact data to gain valuable insights. By using AI algorithms, you can extract meaningful information from your contact data and use it to optimize your marketing and sales strategies.
To integrate OpenAI API with HubSpot, you'll need to use custom code actions within your workflows. Follow these steps to set up and use the API.
const axios = require('axios');
exports.main = async (event, callback) => {
// Input
const contactEmail = event.inputFields['email'];
// Open AI
const OpenAIApiURL = "https://api.openai.com/v1/chat/completions";
const OpenAIApiKey = "YOUR_OPENAI_API_KEY";
// Modify "content" with your desired prompt
const data = {
model: "gpt-3.5-turbo",
messages: [
{
role: "user",
content: `Analyze the contact's data and
provide a category for the email ${contactEmail}.
The categories to choose from are "Business" and "Personal".`
}
],
max_tokens: 50,
temperature: 0.7
};
try {
// Call OpenAI API
const response = await axios.post(OpenAIApiURL, data, {
headers: {
'Authorization': `Bearer ${OpenAIApiKey}`,
'Content-Type': 'application/json'
}
});
// Save the OpenAI response
const aiCategory = response.data.choices[0].message.content;
// Save the response to our aiCategory output variable
callback({
outputFields: {
aiCategory: aiCategory
}
});
} catch (error) {
console.error('Error communicating with OpenAI:', error);
callback({
outputFields: {
aiCategory: 'Error'
}
});
}
};
Replace YOUR_OPENAI_API_KEY
with your actual OpenAI API key.
Also, remember to change the prompt in content inside the messages array for the want you need. You can test your prompt first in ChatGPT and give an example, this way you can optimize it and find the best one that suits your needs.
Map the input fields to match the data you want to send to the OpenAI API. In this example, we are using the contact's email address:
After mapping the input fields, define how the output from the OpenAI API will be handled.
Once you have the AI-generated category, you need to save it to a custom property in HubSpot. Follow these steps:
Congratulations! 🎉 You have successfully implemented AI in your HubSpot workflows. By following this guide, you have:
This achievement not only enhances your workflow efficiency but also paves the way for more personalized and effective marketing strategies. By automating data analysis and categorization, you can now focus on crafting targeted campaigns that resonate with your audience, ultimately driving better engagement and results.
Feel free to experiment further with different AI prompts and custom properties to continue optimizing your workflows. The possibilities are endless, and the impact on your business can be truly transformative.