Step 1: Obtain Your ChatGPT API Key
Sign Up for OpenAI API:
Visit OpenAI and create an account.
Retrieve API Key:
Navigate to your API keys and generate a new one by following OpenAI's guide on API key generation.
Keep your key secure as you’ll need it in the webhook configuration.
Step 2: Set Up the Webhook in Coho Playbooks
Open or Create a Playbook:
Access the Playbooks page and select an existing playbook or create a new one.
Add a Webhook Action:
In the playbook editor, click the + button to add an action.
Choose HTTP request as the action type.
Configure the Webhook:
Request URL: Enter the ChatGPT API endpoint:
https://api.openai.com/v1/chat/completions
Method: POST
Headers:
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
Body: Use the following JSON payload for a cart abandonment use case:
{
"model": "gpt-4",
"messages": [ {
"role": "system",
"content": "<A set of instructions that define the behavior of ChatGPT. Think of this as a setup guide for the assistant>"
}, {
"role": "user",
"content": "<The specific query or input for ChatGPT. This could include details about the situation or user context>"
} ],
"temperature": 0.6,
"max_tokens": 150
}
Save the Webhook Configuration:
Assign a meaningful name (e.g., "Generate Cart Abandonment Email Content").
Full example for abandoned cart use case:
{
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a marketing assistant. Your goal is to create a concise, engaging email to re-engage a user who abandoned their cart."
},
{
"role": "user",
"content": "Cart Details: T-shirt. User Behavior: Visited pricing page twice. User Metadata: Country - UK, Usual booking duration - 2 hours. Tone: Friendly and professional."
}
],
"temperature": 0.6,
"max_tokens": 100
}
Step 3: Use ChatGPT Responses in Playbooks
Access the content using {{}}
{{ChatGPT_0.choices.[0].message.content}}
Incorporate the Response:
Slack Message Example: Use the ChatGPT response in a Slack notification:
This is a message from ChatGPT: {{ChatGPT_0.choices.[0].message.content}}
Understanding ChatGPT Messages
In the API body, the messages
parameter includes:
System Prompt: A set of instructions that define the behavior of ChatGPT. Think of this as a setup guide for the assistant. For example:
"You are a Marketing expert. Provide concise, engaging email content for user retention."
The system prompt shapes the tone, role, and context of the responses.
User Prompt: The specific query or input for ChatGPT. This could include details about the situation or user context. For example:
"A user has a product in their cart but hasn’t completed the purchase."
Best Practices for ChatGPT Parameters
Temperature (0.0 to 1.0): Controls the creativity of the output.
0.0-0.3: Responses are deterministic and to-the-point. Use for highly specific or technical tasks.
0.4-0.6: Balanced creativity and precision. Use for standard business communication.
0.7-1.0: Highly creative and exploratory. Use for brainstorming or engaging content.
Model: Always use the latest stable version (
gpt-4-0314
) for high-quality outputs.Max Tokens: Define a limit to avoid unnecessarily long outputs.
Short tasks (e.g., generating a sentence): 50-100 tokens.
Medium tasks (e.g., paragraphs): 200-300 tokens.
Prompt Crafting:
System Prompt: Be explicit about the role and task.
User Prompt: Include relevant details for better context.