😄 Agent 3 of 5 · Beginner

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.

Beginner 3 Nodes Manual Trigger Gemini 2.5 Flash Gmail OAuth
How It Works

Architecture

[ Manual Trigger ] Click "Execute workflow" ↓ [ HTTP Request → Gemini AI ] Sends prompt: "Tell me a funny joke" — Gemini returns a joke ↓ [ Code Node (JavaScript) ] Extracts just the joke text from Gemini's response ↓ [ Gmail Node ] Sends the joke to your inbox
✅ Total nodes: 3  ·  Trigger: Manual (button click)  ·  AI Model: Google Gemini 2.5 Flash
Before You Start

What You Need

WhatWhere to get itTime
Docker Desktopdocker.com/products/docker-desktop5 min
Google Account (Gmail)Already have one—
Gemini API Keyaistudio.google.com/apikey2 min
Google OAuth Credentialsconsole.cloud.google.com10 min
Build Guide

Step-by-Step Setup

1

Install Docker & Run n8n

docker run -d \ --name n8n \ --restart unless-stopped \ -p 5678:5678 \ -v n8n_data:/home/node/.n8n \ docker.n8n.io/n8nio/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 →

2

Get a Gemini API Key

Go to aistudio.google.com/apikey, click Create API key, and copy it. Treat it like a password.

3

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:

http://localhost:5678/rest/oauth2-credential/callback

Copy the Client ID and Client Secret.

4

Import the Workflow

In n8n: + → New Workflow → ... → Import from file → select ai_joke_emailer.json. You should see Manual Trigger → HTTP Request → Code → Gmail.

5

Configure the Gemini HTTP Request Node

In the Query Parameters, paste your Gemini API key as the key value.

6

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

7

Test It

Save, click Execute workflow — all nodes turn green and the joke arrives in Gmail within seconds.

Reference

Placeholders & Troubleshooting

Placeholder Reference

NodeFieldWhat to put
HTTP RequestQuery Parameters → ValueYour Gemini API key
GmailCredentialConnect via OAuth (Client ID + Secret)
GmailTo / Subject / MessageYour address, any subject, {{ $json.joke }}

Troubleshooting

ProblemFix
Access blocked on Google sign-inAdd yourself as a Test User in OAuth Consent Screen → Audience
Forbidden - project denied accessGet a fresh Gemini API key matching the right project
Quota exceededWait 1-2 minutes — free tier has rate limits
Docker container stops after rebootRe-run the docker run command — it auto-restarts next time
Go Further

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
Built With

Tech Stack

n8n Google Gemini 2.5 Flash Gmail API Docker