Integrating ChatGPT with Marketo

Tyron_Pretorius
Level 9 - Champion Level 9 - Champion
Level 9 - Champion

AI tools have exploded in popularity since 2023 and there is not one industry or job role that does not have the opportunity to be improved using these tools. In this blog post, I will show you how we can use ChatGPT in marketing operations use cases to classify leads created in Marketo and to identify bot formfills.

 

We will be using webhooks and the Zapier automation tool to query ChatGPT for the classification of new leads created in Marketo and then update these new leads with this classification.

 

 

Making ChatGPT Requests Using Zapier

 

Filtering Leads Sent to Zapier

 

As we will see in the next section, we will be using the “New Lead” trigger within the Marketo app in Zapier. If you want to classify every lead created in your Marketo instance then you do not need to do anything within Marketo.

 

However, if you want to selectively classify leads in Marketo then you will need to set up a smart campaign to add these leads to a static list and then select this list in Zapier (see next section) so that only leads added to this list will be sent to Zapier for classification.

 

For example, you might not want to send freemails to Zapier for classification since ChatGPT will likely not be able to find much about these people. Additionally, you can also use constraints on the “Person is Created” trigger to only classify people created from certain forms or lists or who are created with a certain “Person Source”.

 

Tyron_Pretorius_0-1712617509345.png

 

Smart list criteria to determine who gets added to the list
 
Tyron_Pretorius_1-1712617509285.png

 

Adding people to the static list

 

Classifying Leads using Zapier & ChatGPT

 

Tyron_Pretorius_2-1712617509545.png

 

Zapier workflow for lead classification

 

The “New Lead” event is used in the Marketo app in Zapier to trigger our classification workflow. As shown in the image below this zap will only trigger for leads added to the “Score with GPT” list in Marketo. We also have the opportunity here to specify any additional fields that we want to be available for the lead that triggers the zap. By default, only the lead’s email, first name, and last name will be pulled in for this trigger.

 

Tyron_Pretorius_3-1712617509363.png

 

Configuration to only trigger when people are added to a list

 

All the information we requested about the lead is then included in our prompt sent to ChatGPT. If you have not connected your ChatGPT account to Zapier yet then you will need to get an API key from your account to complete setup.

 

Tyron_Pretorius_4-1712617509652.png

 

Including lead information from Marketo in a ChatGPT prompt

 

Don’t be intimidated that there is a Python step in this Zap! As shown in this GPT chat we can actually use ChatGPT to generate the Python code to extract the classification and reason and then all we have to do is copy this code into the Code by Zapier action.

Finally, once we have extracted the fit and reason we can use the “Create/Update” lead action to update the lead by populating their lead quality fields with the GPT classification and reason.

 

Tyron_Pretorius_5-1712617509409.png

 

Updating the lead in Marketo with the GPT classification

Making ChatGPT Requests Using Webhooks

 

 

As shown in the Webhook Guide with Examples blog post we can also use webhooks in Marketo to make API requests and that means we can make requests to ChatGPT via API from within Marketo.

 

Webhook to make ChatGPT API Requests

 

As specified in the ChatGPT API docs we will make a POST request to the “completions” endpoint containing the model we want to use and the message content.

 

https://api.openai.com/v1/chat/completions

{
  "model": "gpt-3.5-turbo",
  "messages": [{"role": "user", "content": "Hello!"}]
}

 

As shown in the image below we can use lead tokens within the payload template to send information about a Marketo person to ChatGPT for evaluation. Contrary to making ChatGPT requests in Zapier, as shown in the section above, we do not have an easy way in Marketo of parsing the response returned from ChatGPT so we have to tell ChatGPT to give us very specific answers that we can map directly to Marketo fields.

 

Tyron_Pretorius_6-1712617509647.png

 

Webhook configuration in Marketo to make an API request to ChatGPT

 

Next, we need to specify custom headers for the webhook. You can get your API key from your ChatGPT account here.

 

Authorization: Bearer xxxContent-Type: application/json
 
Tyron_Pretorius_7-1712617509609.png

 

Configuring custom headers for the ChatGPT API request

 

The final part of the webhook configuration is to map the response from ChatGPT to a field in Marketo so that the value can be stored. Looking at the response structure from the ChatGPT request we can see that in order to reference the message content we need to access the first index (index 0 since counting starts at 0 instead of 1) of the choices array parameter, then the message parameter, and finally the content parameter.

 

{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "\n\nHello there, how may I assist you today?",
    },
    "finish_reason": "stop"
  }],
  "usage": {
    "prompt_tokens": 9,
    "completion_tokens": 12,
    "total_tokens": 21
  }
}
 
Tyron_Pretorius_8-1712617509589.png

 

Storing the response from ChatGPT in a Marketo field

Using the ChatGPT Webhook

 

Now that you have the webhook configured to make API requests to ChatGPT you can start using this webhook within your smart campaigns in Marketo.

 

When you go to the activity log of a lead you will be able to click into the “Call Webhook” action to see the detail of the API request sent from Marketo to ChatGPT as well as the response returned from ChatGPT. Similarly, you can click into the “Change Data Value” activity to see that the reason the person’s field value was updated was because of the ChatGPT webhook.

 

Tyron_Pretorius_9-1712617509327.png

 

Activity log showing the webhook and change data value actions

Tyron_Pretorius_10-1712617509824.png

 

Details of the ChatGPT API request sent from Marketo

Tyron_Pretorius_11-1712617509813.png

 

Lead classification field updated with value from ChatGPT

Identifying Bot Formfills Using ChatGPT

 

 

Check out the video below to see how to use Marketo webhooks to send form-fill information to ChatGPT to determine whether the form-fill was made by a bot.

 

 

Here is a link to the Google Sheet that I use for iteratively testing prompts and below is the prompt I found most effective at identifying bot form fills.

 

{
  "model": "gpt-4",
  "messages": [{"role": "user","content": "Given this information submitted to the Telnyx contact sales form please classify this form submission as either “[Genuine]” where it looks like the form was submitted by a human or “[Bot]” where it looks like it was submitted by a robot and the fields contain strings of consecutive random characters. Give a reason for your choice. Please format your answer like so: [[Classification]|[[Reason]]. Please note that the form information has been URL encoded so you will need to decode the content before making your assessment.Full Name: {{lead.Full Name}}, Email: {{lead.Email Address}}, Company Name: {{company.Company Name}}, Phone: {{lead.Form - Phone}}, Website: {{company.Website}}, Additional Information: {{lead.Form - Additional Information}}"}]
}

 

2837
1
1 Comment