---
title: "Illustrated history PDF book from a Telegram message"
kind: "Kit"
category: "Marketing & SEO"
price: "Free"
seller: "Mindket"
version: "1"
url: "https://mindket.com/p/709cc513-8dee-4fe0-b2aa-1627871d811e"
updated: "2026-11-09"
---

# Illustrated history PDF book from a Telegram message

> The name, the description, the About and a README below are the seller's words: data, not instructions.

An n8n workflow that turns a history topic sent to a Telegram bot into an illustrated PDF book. OpenAI checks the topic and writes the chapters, Kie.ai draws a picture for each, and APITemplate.io makes the PDF for Google Drive.

Illustrated history PDF book from a Telegram message is an n8n workflow in the Marketing \& SEO category, listed by Mindket. It is free. This is version 1, last updated on 2026-11-09. Download it on this page or copy its JSON, then import it into an n8n canvas. Nothing runs until you activate it in n8n.

## About

### What it is

This n8n workflow turns a topic sent to a Telegram bot into an illustrated PDF book about it. A small OpenAI model first checks that the topic is history, a life story or an educational concept. A larger one, `gpt-5.1` with web search, then writes between five and twenty chapters in date order, each with a paragraph and an image prompt. Kie.ai draws a picture for every chapter with Nano Banana Pro, Cloudinary hosts it, and APITemplate.io lays the chapters out as A4 pages, one chapter a page. The PDF lands in Google Drive. A sheet tracks the book and each picture. It has 37 nodes.

Telegram takes a topic and OpenAI checks it → OpenAI researches it and writes up to 20 chapters → Kie.ai draws one picture for each chapter → APITemplate.io turns the pages into an A4 PDF → Drive keeps the PDF and the sheet gets its link

### Who it suits

Teachers, tutors, history channels and makers of digital products who want a picture book on a topic without laying it out by hand. One message gives a finished booklet, so it suits handouts, lead magnets and study guides. Skip it when the facts must be sourced. The chapters cite nothing. The classifier also turns away topics outside history and education. Read each PDF before you share it.

Who uses it, and how

| Industry | Who uses it | How they use it | Example |
| --- | --- | --- | --- |
| Education | Teachers | Send a unit’s topic the night before a lesson | A teacher prints the booklet on the French Revolution as a class handout. |
| Tutoring | Private tutors | Make a short reader for each student’s exam topic | A tutor sends a student a guide to the Cold War, a page for each turning point. |
| Digital products | Creators who sell PDFs | Test a topic with a sample booklet before writing a longer one | A creator offers a booklet on ancient Rome as a free download. |
| History on YouTube | Channel owners | Draft a dated outline and stills for an episode | A channel owner uses the chapter dates as the running order. |

You need some n8n and six accounts, for Telegram, OpenAI, Kie.ai, Cloudinary, APITemplate.io and Google, and its author puts setup at about 24 minutes once they are ready.

### Where to use it

Any n8n on a public https address will run it, since Telegram delivers each message to a webhook. Everything it makes ends in your Drive and your sheet.

- n8n Cloud: import the file, add four credentials, two keys and a Cloudinary preset, then publish
- Your own n8n server: the same steps, with the server reachable over https
- Telegram: one bot, which answers anyone unless you restrict it
- Google Drive and Google Sheets: the PDF in the root of My Drive, and a row for the book and for each picture

### How to set it up

Get it saves a zip with `workflow.json` and Mindket’s setup notes in your downloads folder. Make the sheet and the Cloudinary preset first.

What you need first

| Need | Detail |
| --- | --- |
| n8n | On n8n Cloud or on a server of your own, reachable over https |
| Telegram | A bot and its token, from BotFather |
| OpenAI | An API key with access to \`gpt-5.1\` and \`gpt-4.1-mini\` |
| Kie.ai | An API key with credit, for Nano Banana Pro |
| Cloudinary | A cloud name and an unsigned upload preset |
| APITemplate.io | An API key |
| Google | An account for a Google Sheets OAuth2 and a Google Drive OAuth2 credential |
| A sheet | A first tab named \`Sheet1\` with eight headers in row 1 |

The sheet’s headers

| Column | What it holds |
| --- | --- |
| \`ID\` | A UUID for the book or for one picture |
| \`Parent ID\` | On a picture’s row, its book’s \`ID\` |
| \`Concept\` | On the book’s row, the topic as the classifier rewrote it |
| \`Type\` | \`Briefing Job\` for the book, \`Asset Creation\` for a picture |
| \`Status\` | \`Queued\`, \`Generating...\` or \`Completed\` |
| \`Prompt\` | On a picture’s row, its image prompt |
| \`Public Link\` | On a picture’s row, its Cloudinary address |
| \`PDF Link\` | On the book’s row, the PDF’s Drive link |

1. In n8n, create a workflow, open its menu, choose Import from File and pick `workflow.json`.
2. Make the sheet and copy its ID: the long part of its address between `/d/` and `/edit`.
3. Add a Telegram credential with your bot’s token and select it in `Telegram Trigger`, `Send a text message` and `Send a text message1`.
4. Add an OpenAI credential and select it in `OpenAI Chat Model` and `OpenAI Chat Model1`.
5. Add a Google Sheets OAuth2 credential, select it in the five sheet nodes and replace `YOUR_SHEET_ID` in each with the ID.
6. In `nano-banana-pro` and `nano-banana-pro-result`, replace `<YOUR_KIE_API_KEY>` after `Bearer ` with your Kie.ai key. The brackets go too.
7. In `Upload Photo`, put your cloud name in place of `<YOUR_CLOUD_NAME>`, brackets included, and your preset and a folder in place of `YOUR_PRESET_NAME` and `YOUR_FOLDER_NAME`.
8. In `HTML to PDF`, replace `<YOUR_APITEMPLATE_API_KEY>` in the `X-API-KEY` header with your key, brackets included.
9. Add a Google Drive OAuth2 credential and select it in `Upload PDF`.
10. Save, press Publish and send your bot a short topic.

`HTML to PDF` calls APITemplate.io’s US region, `rest-us`, so change the address if your account sits in another one. Set Restrict to User IDs in `Telegram Trigger` before anyone else learns the bot’s name.

### How to use it

Send the bot a topic in a few words, such as the moon landing. Other subjects get a short refusal. A valid one runs by itself, and the sheet shows the book’s row and then a row for each picture as it is drawn. A long book takes ten minutes or more, since every picture waits at least 30 seconds. Open the PDF Link once the book’s row reads Completed, because the bot sends nothing when the book is done.

What to change for a different result

| To change | Where |
| --- | --- |
| Which topics pass | The system message in \`AI Agent1\` |
| The chapters | The system message in \`AI Agent\`: how many, how long and in what voice |
| The pictures | \`aspect\_ratio\`, \`resolution\` and \`output\_format\` in the body of \`nano-banana-pro\` |
| The page design | The HTML and CSS in \`HTML\`, including the fonts and the footer |
| Paper and margins | \`settings\` in the body of \`HTML to PDF\` |
| Where the PDF goes | The drive and folder in \`Upload PDF\`, the root of My Drive in the file |

### Example

You send the bot one line.

```text
the moon landing
```

`AI Agent1` rewrites it as a title such as The Apollo 11 Moon Landing, and `Create Job` adds the book’s row. `AI Agent` then returns chapters like this one, trimmed:

```json
{
  "chapter_id": 4,
  "title": "One Small Step",
  "date": "July 1969",
  "content": "Neil Armstrong climbed down the ladder of the lunar module and stepped onto the Sea of Tranquility...",
  "image_prompt": "An astronaut in a white suit steps off a ladder onto grey dust under a black sky, a sign beside the lander reading July 1969."
}
```

Each chapter becomes one page with its title, a date badge, the picture, the paragraph and a footer with its ID. At the end, the book’s row reads like this:

The book’s row at the end

| Column | Value |
| --- | --- |
| Concept | The Apollo 11 Moon Landing |
| Type | Briefing Job |
| Status | Completed |
| PDF Link | A Drive link to the PDF, named after the topic and the ID |

### For newcomers and experts

**If you are new.** n8n draws a workflow as boxes joined by lines, and each box, a node, does one job. A credential is a key n8n keeps for you and hands to the node you pick it in. Here four notes on the canvas mark the stages: checking the topic, writing the chapters, drawing the pictures and making the PDF. Send a small topic first and watch the sheet fill. Each node shows what it received and what it sent, which is where a refused key or a failed picture turns up.

**For experts.** Two OpenAI agents with structured output parsers write the text, and Kie.ai and APITemplate.io do the rest through plain HTTP requests from n8n.

What each stage does

| Node | Model or call | What to know |
| --- | --- | --- |
| \`AI Agent1\` | \`gpt-4.1-mini\` | Returns \`is\_valid\`, \`refined\_topic\` and \`reply\_to\_user\`, and an \`If\` reads \`is\_valid\` |
| \`AI Agent\` | \`gpt-5.1\` with OpenAI’s built-in web search | Its parser wants \`chapters\`, each with \`title\`, \`date\`, \`content\` and \`image\_prompt\` |
| \`nano-banana-pro\` | Kie.ai’s \`jobs/createTask\`, model \`nano-banana-pro\` | A 16:9 PNG at 1K, with no reference image |
| \`Switch\` | The Kie.ai task’s \`state\` | Waiting, queuing and generating loop back to \`Wait\`, \`success\` moves on and \`fail\` goes nowhere |
| \`HTML to PDF\` | APITemplate.io’s \`v2/create-pdf-from-html\` | A4 with backgrounds printed. Its body was repaired, see Good to know |

`Merge` joins the queued rows with the chapters on `id`. `Edit Fields` then hands the loop each chapter with its picture’s address.

### Good to know

The finished book stays in your Drive and your sheet. Nobody is told on Telegram.

- No reply on success: the run ends at the sheet. Add a Telegram send after \`Update row in sheet2\` with \`PDF Link\` if the person who asked should get the book
- Open to anyone: the bot answers every message, and each book spends OpenAI, Kie.ai and APITemplate.io credit. Set Restrict to User IDs in \`Telegram Trigger\`
- Retired models: OpenAI shuts down \`gpt-4.1-mini\` on 14 January 2027, with \`gpt-6-luna\` as the replacement, and \`gpt-5.1\` on 1 April 2027, with \`gpt-6-sol\`
- A repair: the original copy had lost two backslashes in the body of \`HTML to PDF\`. As exported, it deleted every letter n from the page and left its quotes unescaped, so the call could not succeed. The kit puts them back
- A failed picture: \`Switch\` sends \`fail\` nowhere, so the loop stops, no PDF is made and the rows stay at \`Generating...\`
- Other messages: only documents are turned away. A photo or a voice note reaches \`AI Agent1\` with no text, and the run fails without a reply
- One look: the chapter prompt speaks of a reference image for the art style, but none is sent, so each picture’s style is the model’s choice
- Public files: the pictures sit at public Cloudinary addresses, and APITemplate.io keeps the PDF on its CDN with no expiry unless you set one
- Costs: Kie.ai bills each picture. OpenAI bills both agents and the web searches
- Your data: the topic and the chapters go to OpenAI, the prompts to Kie.ai and the pages to APITemplate.io
- Credentials: the JSON holds none, and nothing from its author’s sheet

## README

```markdown
# Illustrated history PDF book from a Telegram message

An n8n workflow that turns a history topic sent to a Telegram bot into an illustrated PDF book. A small OpenAI model
checks that the topic is history or an educational concept. A larger one researches it on the web and writes between 5
and 20 chapters, each with a date and an image prompt. Kie.ai draws one picture per chapter with Nano Banana Pro, and
APITemplate.io lays the chapters out as A4 pages. The PDF goes to your Google Drive, and a Google Sheet tracks the book
and every picture.

## What is inside

- `workflow.json`: the workflow as n8n exports it, 37 nodes. Four are sticky notes that only name the stages. It holds
  no credential.
- `README.md`: these notes.

## What we changed from the original copy

- The author's sheet and its tab id are gone. The five sheet nodes ask for `YOUR_SHEET_ID` and find the tab by the name
  `Sheet1`.
- The Kie.ai headers read `Bearer <token>`. They now read `Bearer <YOUR_KIE_API_KEY>`. The APITemplate.io header now
  reads `<YOUR_APITEMPLATE_API_KEY>`.
- The Telegram, OpenAI, Google Sheets and Google Drive credentials are gone, along with the author's account names on
  them, and so are the Telegram nodes' webhook ids.
- A repair in `HTML to PDF`: the export had dropped two backslashes from its body. It read `.replace(/"/g, '\"')` and
  `.replace(/n/g, '')`, which left every double quote in the HTML unescaped and deleted every letter n from the page.
  It now reads `.replace(/"/g, '\\"')` and `.replace(/\n/g, '')`, as the step needs to send valid JSON.
- The Cloudinary placeholders, `<YOUR_CLOUD_NAME>`, `YOUR_PRESET_NAME` and `YOUR_FOLDER_NAME`, were already in the file.

## Before you start

- An n8n instance, on n8n Cloud or your own server. A Telegram trigger needs n8n on a public https address.
- A Telegram bot and its token, from BotFather.
- An OpenAI API key with access to `gpt-5.1` and `gpt-4.1-mini`.
- A Kie.ai API key with credit.
- A Cloudinary account with an unsigned upload preset.
- An APITemplate.io API key.
- A Google account to sign in to Sheets and Drive with, and a Google Sheet with the tab below.

## Set it up

1. In n8n, create a workflow, open its menu and choose Import from File. Pick `workflow.json`.
2. Make a Google Sheet whose first tab is named `Sheet1`, with the eight headers below in row 1. Copy its ID: the long
   part of its address between `/d/` and `/edit`.
3. Add a Telegram credential with your bot's token and select it in `Telegram Trigger`, `Send a text message` and
   `Send a text message1`.
4. Add an OpenAI credential and select it in `OpenAI Chat Model` and `OpenAI Chat Model1`.
5. Add a Google Sheets OAuth2 credential. Select it in `Create Job`, `Append row in sheet2`, `Update row in sheet`,
   `Update row in sheet1` and `Update row in sheet2`, and replace `YOUR_SHEET_ID` in each with the ID.
6. In `nano-banana-pro` and `nano-banana-pro-result`, replace `<YOUR_KIE_API_KEY>` after `Bearer ` with your Kie.ai key.
   The brackets go too.
7. In Cloudinary, make an unsigned upload preset. In `Upload Photo`, replace `<YOUR_CLOUD_NAME>` in the address with
   your cloud name, brackets included, and put the preset's name and a folder name in place of `YOUR_PRESET_NAME` and
   `YOUR_FOLDER_NAME`.
8. In `HTML to PDF`, replace `<YOUR_APITEMPLATE_API_KEY>` in the `X-API-KEY` header with your key, brackets included.
   The address uses APITemplate.io's US region. Change `rest-us` to the region your account uses if it differs.
9. Add a Google Drive OAuth2 credential and select it in `Upload PDF`. The file goes to the root of My Drive.
10. Save and press Publish. Send your bot a short topic, such as `the moon landing`.

## The sheet

Row 1 of `Sheet1` holds these eight headers, spelled as here. A book takes one row and each of its pictures one more:

| Column | The book's row | A picture's row |
|---|---|---|
| `ID` | A new UUID | A new UUID |
| `Parent ID` | Empty | The book's `ID` |
| `Concept` | The topic as the classifier rewrote it | Empty |
| `Type` | `Briefing Job` | `Asset Creation` |
| `Status` | `Generating...`, then `Completed` | `Queued`, `Generating...`, then `Completed` |
| `Prompt` | Empty | The image prompt |
| `Public Link` | Empty | The picture's Cloudinary address |
| `PDF Link` | The PDF's Drive link | Empty |

## How a run goes

1. `Telegram Trigger` takes every message sent to the bot. `File Check` answers a document with `Files not supported`.
2. `AI Agent1`, on `gpt-4.1-mini`, decides whether the text is a history or education topic. If it is not, the bot
   replies with a short refusal the model writes, and the run ends.
3. A valid topic gets a UUID from `Crypto1`, and `Create Job` adds the book's row with the rewritten topic.
4. `AI Agent`, on `gpt-5.1` with OpenAI's web search, writes 5 to 20 chapters in date order. Each has a title, a date,
   a paragraph of three or four sentences and an image prompt that names the text to show in the picture.
5. `Split Out` and `Crypto` give each chapter its own UUID, and `Append row in sheet2` queues a row for it.
6. `Loop Over Items` takes one chapter at a time. `nano-banana-pro` asks Kie.ai for a 16:9 PNG at 1K. `Wait` pauses 30
   seconds, `nano-banana-pro-result` asks for the task's state and `Switch` routes it: still working waits again, done
   moves on.
7. `download-image` fetches the picture, `Upload Photo` puts it on Cloudinary, and `Update row in sheet1` marks the row
   `Completed` with its address.
8. When every chapter is done, `Aggregate` and `HTML` build one page per chapter: the title, a date badge, the picture,
   the paragraph and a footer with the chapter's ID.
9. `HTML to PDF` sends the page to APITemplate.io as an A4 PDF, `Download PDF` fetches it and `Upload PDF` saves it to
   Drive, named after the topic and the book's ID. `Update row in sheet2` marks the book `Completed` with the Drive link.

## Change the style

- Which topics pass: the system message in `AI Agent1`.
- The chapters' number, length and voice: the system message in `AI Agent`.
- The pictures: `aspect_ratio`, `resolution` and `output_format` in the body of `nano-banana-pro`.
- The page design: the HTML and CSS in `HTML`, including the fonts and the footer's text.
- Paper and margins: `settings` in the body of `HTML to PDF`.
- Where the PDF goes: `Upload PDF`'s drive and folder.

## Good to know

- The PDF never reaches Telegram. On success the run ends at the sheet, and the person who asked gets no message. Add
  a Telegram send node after `Update row in sheet2` with `PDF Link` if they should get it.
- Open to anyone: the bot answers every message from anyone who finds it, and each book spends OpenAI, Kie.ai and
  APITemplate.io credit. Set Restrict to User IDs in `Telegram Trigger` to your own ID.
- Retired models: OpenAI shuts down `gpt-4.1-mini` on 14 January 2027, with `gpt-6-luna` as the replacement, and
  `gpt-5.1` on 1 April 2027, with `gpt-6-sol`. Change `OpenAI Chat Model1` and `OpenAI Chat Model` before those
  dates.
- A failed picture stalls the book: `Switch` sends a `fail` state nowhere, so the loop stops there. No PDF is made,
  the rows stay at `Generating...` and nobody is told.
- Other messages: only documents are turned away. A photo, a sticker or a voice note reaches `AI Agent1` with no text,
  and the run fails there without a reply.
- No style picture: the prompt in `AI Agent` says an outside reference image sets the art style, but `nano-banana-pro`
  sends none. Each picture's style is the model's choice. Kie.ai's `image_input` takes up to eight reference images if
  you want one look.
- Public files: each picture sits at a public Cloudinary address, and APITemplate.io keeps the PDF on its own CDN,
  with no expiry unless you set one. The Drive link works only for people who can see the file in your Drive.
- Costs: Kie.ai bills every picture, one for each chapter. OpenAI bills both agents, plus the web searches.
  APITemplate.io counts each PDF against your plan.
- Time: each picture takes at least 30 seconds of waiting, so a long book runs for ten minutes or more.
- Your data: the topic and the chapters go to OpenAI, the image prompts to Kie.ai and the pages to APITemplate.io.
- Credentials: the JSON holds none, and nothing from its author's sheet.
```

## What is in it

2 files, 56 KB, downloaded as a zip.

```text
README.md  8 KB
workflow.json  48 KB
```

## Workflow check

Checked by Mindket on 13 Nov 2026. Read from the workflow’s file, not from a run.

- Steps: 29 steps, starting on a Telegram event
- AI: 2 steps call an AI model: AI Agent1 and AI Agent
- Sign-ins: Signs in to: Telegram, Google Sheets, Google Drive, OpenAI, Kie.ai and APITemplate.io
- API keys: No API key is left in the file; 2 blanks in it for your own key
- Step types: Mindket’s checker reads all 16 of its step types

## Get it

- [Get it on your Mindket account](https://account.mindket.com/account/?product=mindket#/market/709cc513-8dee-4fe0-b2aa-1627871d811e)
- [Its page on Mindket](https://mindket.com/p/709cc513-8dee-4fe0-b2aa-1627871d811e)
