Skip to main content
All CollectionsTutorials
Create Content Using ChatGPT in Playbooks
Create Content Using ChatGPT in Playbooks

This guide explains how to integrate the ChatGPT API into your Coho playbooks to generate personalized, dynamic content and automate user engagement

Updated this week

Step 1: Obtain Your ChatGPT API Key

  1. Sign Up for OpenAI API:

    • Visit OpenAI and create an account.

  2. Retrieve API Key:


Step 2: Set Up the Webhook in Coho Playbooks

  1. Open or Create a Playbook:

    • Access the Playbooks page and select an existing playbook or create a new one.

  2. Add a Webhook Action:

    • In the playbook editor, click the + button to add an action.

    • Choose HTTP request as the action type.

  3. 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
      }
  4. Save the Webhook Configuration:

    • Assign a meaningful name (e.g., "Generate Cart Abandonment Email Content").

  5. 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

  1. Access the content using {{}}

    {{ChatGPT_0.choices.[0].message.content}}
  2. 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:

  1. 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.

  2. 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

  1. 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.

  2. Model: Always use the latest stable version (gpt-4-0314) for high-quality outputs.

  3. 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.

  4. Prompt Crafting:

    • System Prompt: Be explicit about the role and task.

    • User Prompt: Include relevant details for better context.

Did this answer your question?