DIU Cover Page Bot

Automated assignment and lab report cover-page generation through Telegram, Google Sheets relational data lookup, and Google Docs templating.

n8n Telegram Bot API JavaScript Google Sheets Google Docs Google Drive
Telegram Bot • Google Sheets DB • Docs Template • PDF Engine Automated End-to-End Execution Flow

Project Overview

The DIU Cover Page Bot is an automated system designed for Daffodil International University students. Instead of manually editing Microsoft Word or Google Docs files to format title pages for every assignment and laboratory submission, students interact with a guided Telegram bot.

The workflow tracks conversational state in Google Sheets, takes user inputs (such as student ID digits, course selections, topic titles, and dates), queries pre-configured databases for full student demographics and course teacher details, injects the values into standard document templates on Google Drive, converts the document into a publication-ready PDF, and returns the finished file to the student on Telegram within seconds.

Primary Input
Telegram Chat & Inline Callbacks
Primary Output
Exported DIU Cover Page PDF
State Storage
Google Sheets (BOT Memory)
Services Used
Telegram Bot API, Sheets, Drive, Docs

Problem & Solution

The Challenge

University students must create and format individual cover pages for every assignment and lab report across multiple courses every semester. Doing this on mobile or desktop involves opening heavy document editors, manually looking up course teacher designations and course codes, re-aligning logos, and fixing formatting shifts.

The Automation

A centralized n8n workflow operates as an automated document compiler. By pulling student names and sections from a verified database using just the last 3 digits of their ID, and course info via inline keyboard taps, the bot completely eliminates repetitive typography and layout work.

How It Works

1

Start Conversation & Receive Webhook

Telegram Trigger

The workflow listens for incoming messages, text inputs, and inline button click callbacks from Telegram users.

2

Retrieve Session Memory

Google Sheets (BOT Memory)

The bot uses the sender's Telegram Chat ID to look up their existing conversation row in the BOT Memory sheet, retrieving their active step and previously selected inputs.

3

Process Input & Advance State

Code in JavaScript

A custom JavaScript node handles conversation routing logic. If the user sent /start, all parameters reset to step 0. It parses typed text (extracting last 3 ID digits, experiment numbers, or topic names) and callback data (Doc_Assignment, Doc_LabReport, Course_*, Date_*, Design_*). If a Lab Report is chosen, step 3 directs to step 4 (Ask Experiment No), while assignments jump straight to step 5 (Ask Date).

4

Route by Conversation Step

Switch Node (Steps 0–7)

A Switch node with 8 rules evaluates $json.step and directs execution to the appropriate step branch. Each step persists updated state back into Google Sheets before prompting the user with the next interactive keyboard.

5

Query Student & Course Records

Google Sheets Relational Lookups

Once all prompts are answered (Step 7), the workflow splits by document type (If3 node). It queries the Student sheet using Last 3 Digit to obtain full Name, Student ID, Section, and Semester, and queries either Course Theory or Course Lab to obtain Course Title, Course Teacher, and Teacher Designation.

6

Document Generation & PDF Delivery

Drive → Docs → Telegram

The workflow copies the master Google Docs cover template to a target folder in Google Drive, replaces all placeholder tags ({{Student Name}}, {{ID}}, {{CourseCode}}, {{Teacher Name}}, {{Topic}}, {{Date}}, and {{No}} for lab experiments), exports the modified file as a PDF, and sends the final document directly to the student via Telegram.

Workflow Architecture Diagram

Core Execution Pipeline & Dual-Path Generation Source: DIU Cover Page BOT copy copy.json
Trigger
Telegram Trigger
Catches messages & callback queries
→
Lookup
Get row(s) in sheet2
Pulls memory by Chat ID
→
State Controller
Code in JavaScript
Parses input & advances step
→
Router
Switch (Steps 0–7)
Branches to interactive prompts
STEP 7 SPLIT: Document Generation Engine (If3 Condition on DocType)
Branch: Assignment →
Relational Fetch
Get row (Student + Course Theory)
→
Google Drive / Docs
Copy & Update Assignment Template
→
PDF Delivery
Download & Send Document (Telegram)
Branch: Lab Report →
Relational Fetch
Get row (Student + Course Lab)
→
Google Drive / Docs
Copy & Update Lab Template (with Exp No)
→
PDF Delivery
Download & Send Document1 (Telegram)

Technical Implementation Highlights

Conversational Memory in Sheets

State is persisted across discrete webhook executions by keying each Telegram Chat ID to columns for step, ID, course, topic, date, and document type.

JavaScript Normalization Logic

The Code node sanitizes text inputs, parses student ID suffixes (e.g. converting 242-15-964 or 964 to lookup keys), and routes callback queries.

Dual Document Templating

Assignments and Lab Reports map to separate Google Drive template files (replacing standard variables like {{Student Name}}, {{CourseCode}}, and experiment numbers).

Relational Course Catalog Separation

Distinguishes between theory courses and lab courses by querying distinct Google Sheets tabs (Course Theory vs. Course Lab) to fetch accurate teacher designations.

Technical Notes & Scope

Workflow Observations from Source JSON
  • Sheet Memory Concurrency: Google Sheets is used as the state store; rapid concurrent messages from the same user before a row update finishes could cause state race conditions.
  • Template Drive Dependencies: The document engine relies on existing Google Drive template file IDs. If the master document is moved or permissions are modified, template duplication fails.
  • Student Catalog Lookup: Student names and sections are dependent on the spreadsheet containing the matching last 3 digits of the student ID. Unregistered IDs require administrative update in the sheet.
  • Disconnected Debug Nodes: The workflow JSON contains two auxiliary If condition nodes from prior revisions that are disconnected from active execution paths; the primary pipeline flows cleanly through Switch and If3.