AI Joke Emailer
Click a button and Google Gemini AI generates a funny joke, which lands straight in your Gmail inbox seconds later. Demonstrates the core agentic pattern: Trigger → AI thinks → Action happens.
Architecture
What You Need
| What | Where to get it | Time |
|---|---|---|
| Docker Desktop | docker.com/products/docker-desktop | 5 min |
| Google Account (Gmail) | Already have one | — |
| Gemini API Key | aistudio.google.com/apikey | 2 min |
| Google OAuth Credentials | console.cloud.google.com | 10 min |
Step-by-Step Setup
Install Docker & Run n8n
Open http://localhost:5678 and create your local account — everything stays on your machine. New to Docker? Follow the full Docker & n8n Setup Guide →
Get a Gemini API Key
Go to aistudio.google.com/apikey, click Create API key, and copy it. Treat it like a password.
Set Up Google OAuth for Gmail
Create a Google Cloud project, enable the Gmail API, configure the OAuth consent screen (External, add yourself as a test user), then create an OAuth Client ID (Web application) with redirect URI:
Copy the Client ID and Client Secret.
Import the Workflow
In n8n: + → New Workflow → ... → Import from file → select ai_joke_emailer.json. You should see Manual Trigger → HTTP Request → Code → Gmail.
Configure the Gemini HTTP Request Node
In the Query Parameters, paste your Gemini API key as the key value.
Connect Gmail
On the Gmail node, click Set up credential, paste your Client ID and Secret, sign in with Google, and fill in To / Subject / Message (use {{ $json.joke }} as the message).
Test It
Save, click Execute workflow — all nodes turn green and the joke arrives in Gmail within seconds.
Placeholders & Troubleshooting
Placeholder Reference
| Node | Field | What to put |
|---|---|---|
| HTTP Request | Query Parameters → Value | Your Gemini API key |
| Gmail | Credential | Connect via OAuth (Client ID + Secret) |
| Gmail | To / Subject / Message | Your address, any subject, {{ $json.joke }} |
Troubleshooting
| Problem | Fix |
|---|---|
Access blocked on Google sign-in | Add yourself as a Test User in OAuth Consent Screen → Audience |
Forbidden - project denied access | Get a fresh Gemini API key matching the right project |
Quota exceeded | Wait 1-2 minutes — free tier has rate limits |
| Docker container stops after reboot | Re-run the docker run command — it auto-restarts next time |
Ideas to Extend
- Ask for a joke about a specific topic instead of random
- Swap the Manual Trigger for a Schedule Trigger — a joke every morning
- Send to WhatsApp or Slack instead of Gmail
- Pick a random topic with a Code node before calling Gemini