This repository contains the source code for a serverless architecture that monetizes MindStudio AI Agents using WordPress and Lemon Squeezy.
It allows users to sign up for free on a WordPress site, but requires an active Lemon Squeezy subscription to access the AI interface. Authentication and logic are handled securely via Pipedream, ensuring no API keys are exposed to the client.
- Frontend (WordPress): Checks the current logged-in user and sends their email to the backend via a secure POST request.
- Middleware (Pipedream):
- Validates the request origin (CORS).
- Queries the Lemon Squeezy API to verify if the user has an
activeoron_trialsubscription. - If active: Requests a Signed URL from MindStudio.
- If inactive: Returns a
403status.
- User Interface:
- Success: Renders the AI Agent inside an
<iframe>. - Failure: Displays a "Subscription Required" paywall with a dynamic checkout link.
- Success: Renders the AI Agent inside an
.
├── backend/
│ └── pipedream-workflow.js # Node.js code for the Pipedream component
├── frontend/
│ └── wordpress-snippet.php # PHP/JS code for WPCode (Insert Headers & Footers)
└── README.md
- WordPress Site: With the Ultimate Member plugin (for user auth) and WPCode (to insert the snippet).
- Pipedream Account: To host the backend logic.
- Lemon Squeezy: A store with a product created and an API Key (Settings > API).
- MindStudio: A published AI Agent, its Agent ID, and an API Key.
- Create a new Workflow in Pipedream.
- Add a Trigger: Select HTTP / Webhook.
- Important: In the trigger settings, change HTTP Response to "Return a custom response from your workflow".
- Add a Step: Select Node.js > Run Node Code.
- Copy the code from
backend/pipedream-workflow.jsand paste it into the step. - Configure the Props (Variables) in the Pipedream UI:
lsApiKey: Your Lemon Squeezy API Key.mindstudioApiKey: Your MindStudio API Key.defaultAgentId: (Optional) Your main Agent ID.
- Security (CORS): Inside the code, locate the
headersobject and changeAccess-Control-Allow-Originfrom*to your actual domain (e.g.,https://your-site.com) for production. - Deploy the workflow and copy the endpoint URL.
- Install the WPCode plugin in WordPress.
- Go to Code Snippets > + Add Snippet > PHP Snippet.
- Copy the code from
frontend/wordpress-snippet.phpand paste it into the editor. - Update the configuration variables at the top of the PHP file:
$pipedream_endpoint = "YOUR_PIPEDREAM_URL_HERE"; $lemon_checkout_url = "YOUR_LEMON_SQUEEZY_PRODUCT_URL"; $agent_ID = "YOUR_MINDSTUDIO_AGENT_ID";
- Set the Insertion Method to Shortcode.
- Save and Activate the snippet.
- Copy the shortcode (e.g.,
[wpcode id="123"]). - Paste the shortcode into the WordPress Page where you want the agent to appear.
- Go to your Product settings in Lemon Squeezy.
- Enable Redirect after purchase.
- Set the URL to your WordPress Agent page (e.g.,
https://yoursite.com/agent).
- A user logs into your WordPress site.
- They visit the Agent page.
- Scenario A (No Subscription): The system detects no active plan. A "Subscription Required" message appears. The user clicks "Activate Subscription," which takes them to checkout with their email pre-filled.
- Scenario B (Subscribed): The system validates the subscription via Pipedream. The AI Agent loads immediately, preserving the user's chat history.
- CORS Error in Console: Ensure you selected "Return a custom response" in the Pipedream Trigger settings.
- SyntaxError (Unexpected token <): This usually means Pipedream is returning the default HTML success page instead of JSON. Check the trigger settings again.
- 403 Forbidden: The integration is working, but the user does not have an active subscription in Lemon Squeezy associated with their WordPress email.
- Never paste your API Keys into the
frontend/wordpress-snippet.phpfile. - API Keys should only exist in the Pipedream environment variables (Props).
- The
signed-urlgenerated is temporary (1 hour) and specific to the logged-in user.