The moment it happens
Ask a Telegram bot questions about your documents
Send a PDF to your bot and it is added to your library; ask a question and you get an answer drawn from those documents.
- Runs
- The moment it happens
- Apps
- Pinecone, Telegram
- AI
- Yes, uses the built-in AI allowance
- Access
- Telegram bot token; Pinecone read+write
Send this to your assistant
Create a ClickRuntime automation: when I send a PDF to my Telegram bot, add it to my Pinecone index. When I ask a question, answer from those documents and say which file the answer came from.
First time? Adding ClickRuntime to your assistant takes about two minutes.
Why use it
Why teams use this automation
A small property management company keeps its tenancy agreements, building rules and contractor contracts as PDFs in a shared drive. When a tenant or a site manager asks something like "who pays for boiler repairs at Elm Court?", someone has to find the right file and read through twenty pages. The answer is usually in there, but finding it takes longer than the question deserves.
With a Telegram bot connected to a Pinecone index, staff send each PDF to the bot once. After that anyone on the team can ask a question in plain words, from their phone, and get an answer taken from the documents along with the file it came from.
What you get out of it
Answers in seconds, not page by page
The bot finds the passages that match the question and answers from them. Staff stop scrolling through long PDFs for a single clause, and simple questions stop interrupting the one person who knows where everything is.
Works from the phone people already carry
Site managers and field staff are rarely at a desk. Telegram is on their phone, so they can check a contract detail while standing in the building it covers.
Every answer names its source
Each reply says which document the answer came from. People can open the file to check the wording before quoting it to a tenant or a supplier.
Adding a document is one message
Send a new PDF and it is searchable a moment later. The library grows as the business does, without anyone maintaining a separate wiki.
Answers stay inside your documents
The bot is told to answer only from what it finds in your index and to say when it does not know. That keeps it from guessing on questions where a wrong answer costs money.
How it works
What happens, step by step
When you send your Telegram bot a PDF, ClickRuntime downloads it, splits the text into short passages and stores them in your Pinecone index with the file name.
When you send a question instead, it searches the index for the passages closest in meaning to what you asked.
AI writes a short answer using only those passages and notes which file they came from.
The answer is sent back to you in the same Telegram chat, usually within a few seconds.
Before it runs live
- Connect Pinecone
- Connect Telegram
- Paste your automation's link into the other app's webhook settings
What you get
Build your own
Need it to work differently?
Your own rules
Conditions, thresholds, filters and exceptions, written the way you'd explain them to a colleague.
Any number of apps
One automation can read from one app and update several others. Over 248 apps are ready, and anything with an API works too.
AI where it helps
Summaries, classification, extraction and drafts use ClickRuntime's built-in AI, with no extra key.
On a schedule or on each event
Runs as often as every 5 minutes, or the moment an app sends an event, and keeps track of what it already handled.
Changes you can ask for
- Act only on the items that match your own rules, and skip the rest
- Change what the AI looks for, or how it writes the result
- Add another app, for example also send it to Slack
- Combine it with other Pinecone and Telegram steps into one automation
Under the hood
The code that runs this automation
import io
from pypdf import PdfReader
from clickruntime import on_event, credentials, http, ai
def embed(texts):
r = http.post("https://api.pinecone.io/embed", headers={"Api-Key": credentials.secret("PINECONE_API_KEY"), "X-Pinecone-API-Version": "2025-01"},
json={"model": "multilingual-e5-large", "inputs": [{"text": t} for t in texts]})
return [e["values"] for e in r.json()["data"]]
@on_event
def handle(event):
msg = (event.json or {}).get("message") or {}
tg = f"https://api.telegram.org/bot{credentials.secret('TELEGRAM_BOT_TOKEN')}"
index = credentials.secret("PINECONE_HOST")
pc = {"Api-Key": credentials.secret("PINECONE_API_KEY")}
if msg.get("document"):
path = http.get(f"{tg}/getFile", params={"file_id": msg["document"]["file_id"]}).json()["result"]["file_path"]
pdf = http.get(f"https://api.telegram.org/file/bot{credentials.secret('TELEGRAM_BOT_TOKEN')}/{path}").content
text = " ".join(p.extract_text() or "" for p in PdfReader(io.BytesIO(pdf)).pages)
chunks = [text[i:i + 1000] for i in range(0, len(text), 1000)][:90]
name = msg["document"].get("file_name", "document")
vectors = [{"id": f"{msg['document']['file_unique_id']}-{i}", "values": v, "metadata": {"text": c, "file": name}} for i, (c, v) in enumerate(zip(chunks, embed(chunks)))]
http.post(f"https://{index}/vectors/upsert", headers=pc, json={"vectors": vectors})
reply = f"Added {name} ({len(chunks)} passages)."
else:
matches = http.post(f"https://{index}/query", headers=pc, json={"vector": embed([msg.get("text", "")])[0], "topK": 5, "includeMetadata": True}).json()["matches"]
context = "\n\n".join(f"[{m['metadata']['file']}] {m['metadata']['text']}" for m in matches)
reply = ai.generate(f"Question: {msg.get('text')}\n\nPassages:\n{context}", system="Answer only from the passages and name the file. If they do not contain the answer, say so.", max_output_tokens=400).text
http.post(f"{tg}/sendMessage", json={"chat_id": msg["chat"]["id"], "text": reply})
return {"ok": True}FAQ
Common questions
Which files can I send?
How long can a document be?
What happens if the answer is not in my documents?
What permissions does it need?
Does it need AI?
How many runs does it use?
Can I change how it works?
Related
You might also like
A Telegram assistant that remembers what you tell it
Tell your bot facts worth keeping and it recalls them later when you ask, even months afterwards.
See how it worksStore new reviews in Pinecone and flag bad ones on Telegram
Every new review of your business is saved for later analysis, and you get a Telegram message the same day about any one- or two-star review.
See how it worksGet error alerts with a plain-English explanation
When one of your jobs or systems fails, #ops gets the error and a one-line guess at the cause, without the same error twice in an hour.
See how it worksKeep exploring
Set up “Ask a Telegram bot questions about your documents” from your assistant
Copy the prompt above, or connect your assistant first. Free plan, no credit card.