Conversation workflow criteria based on email body
SOLVE
Hi, I am new to Hubspot, so not sure if Im even setting this up correctly.
I am trying to make a workflow triggered when an email comes into the shared inbox. Based on the email body text, I want to route it to different places.
I can't figure out how to find the keyword in the message body. What Conversations field? I tried Communications field "communication body" and that doesn't work either. I know for sure the test email was "correct" and it fails to recognize my email.
This is unfortunately not possible at this stage. As far as I know, there is no conversation property that can be referenced to filter for the content of an incoming email.
These requests submitted to the HubSpot Ideas section of the community are reviewed by the HubSpot product team, based on their popularity and the assumed demand. I'd recommend commenting and upvoting.
You can also help other HubSpot users find this request more easily (and drive traction) by accepting my reply as a solution. I'd appreciate it, too.
Have a great day!
Karsten Köhler HubSpot Freelancer | RevOps & CRM Consultant | Community Hall of Famer
Conversation workflow criteria based on email body
SOLVE
This is technically doable with a custom code action if you have access to it.
Here's an example where after setting your initial trigger to be Conversation-based and filter to the shared Inbox you want then add a Custom Code action after that and pass in the hs_thread_id (Thread Id) property into it.
Unfortunately, because the message body is usually truncated you then have to do another API call in the action to then get the message body and check if your word or phrase you are looking for is in there.
const hubspot = require('@hubspot/api-client');
exports.main = async (event, callback) => {
const thread_id = event.inputFields['hs_thread_id'];
const hubspotClient = new hubspot.Client({
accessToken: process.env.YourSecretAPIKey // set this in secrets for the action
});
const response = await hubspotClient.apiRequest({
path: '/conversations/v3/conversations/threads/' + thread_id + '/messages',
});
let output_found = false;
let message_id;
const json = await response.json();
json.results.forEach(function(message) {
if (message.type === 'MESSAGE' && message.direction === 'INCOMING') {
message_id = message.id;
}
});
const message_response = await hubspotClient.apiRequest({
path: '/conversations/v3/conversations/threads/' + thread_id + '/messages/' + message_id + '/original-content',
});
const message_json = await message_response.json();
let message_text = message_json.text;
if (message_text.includes("word or phrase you searching for")) {
// Do something here or save to output to use in later actions
// Though HubSpot doesn't allow using the output in a branch action which is disappointing so you have to edit the record with it or do more custom code or such
output_found = true;
}
callback({
outputFields: {
output_found: output_found
}
});
}
This is unfortunately not possible at this stage. As far as I know, there is no conversation property that can be referenced to filter for the content of an incoming email.
These requests submitted to the HubSpot Ideas section of the community are reviewed by the HubSpot product team, based on their popularity and the assumed demand. I'd recommend commenting and upvoting.
You can also help other HubSpot users find this request more easily (and drive traction) by accepting my reply as a solution. I'd appreciate it, too.
Have a great day!
Karsten Köhler HubSpot Freelancer | RevOps & CRM Consultant | Community Hall of Famer