A Telegram bot that lets a shop owner ask about their e-commerce store in plain language ("how much did we sell today?", "what is running low?") and answers using Gemini function calling.
Small sellers on Shopify or Trendyol check the same few numbers every day, and getting them means logging in to a dashboard or exporting to Excel. A chat interface they already have open is faster. The interesting part technically is letting an LLM decide which data call to make, with which arguments, and then summarise the result for a phone screen.
- Next.js 16 (App Router), React 19, TypeScript
- Tailwind CSS 4, Framer Motion for the landing and onboarding pages
- Gemini 2.5 Flash via
@google/genaiwith function declarations - Supabase (Postgres) for linking a Telegram user to a store API key
- Telegram Bot API (webhook)
sequenceDiagram
participant U as Telegram user
participant T as Telegram
participant W as /api/telegram/webhook
participant DB as Supabase
participant G as Gemini
participant S as Store API (mocked)
U->>T: "Bugün ne kadar satış yaptık?"
T->>W: POST update
W->>DB: look up api_key by telegram username
W->>G: message + tool declarations
G-->>W: functionCall get_daily_sales(date, api_key)
W->>S: get_daily_sales
S-->>W: { revenue, currency, orders }
W->>G: functionResponse
G-->>W: short Markdown summary
W->>T: sendMessage
| Path | Role |
|---|---|
src/app/page.tsx |
Landing page |
src/app/dashboard/page.tsx |
Onboarding: Telegram username + store API key + platform, saved to Supabase |
src/app/api/telegram/webhook/route.ts |
Webhook: user lookup, Gemini chat with tools, function execution, reply |
supabase/schema.sql |
users table |
Tools exposed to the model:
| Function | Arguments | Returns |
|---|---|---|
get_daily_sales |
date, api_key |
revenue, currency, order count |
get_low_stock_items |
threshold, api_key |
items below the threshold |
Both functions currently return mock data. Replacing them with real Shopify / Trendyol calls is the next step; the model-facing contract does not change.
Requirements: Node 20+, a Supabase project, a Gemini API key, a Telegram bot token from @BotFather, and a public URL for the webhook (ngrok works).
npm install cp .env.example .env.local # fill in the values # run supabase/schema.sql in the Supabase SQL editor npm run dev ngrok http 3000 curl "https://api.telegram.org/bot<TELEGRAM_BOT_TOKEN>/setWebhook?url=<NGROK_URL>/api/telegram/webhook"
Open /dashboard, register your Telegram username, then message the bot.
The bot is a working prototype against mock data: it picks the right function for sales and stock questions, passes arguments it infers from the message (such as "today" or a threshold), and refuses questions outside e-commerce.
- Store data is mocked (see above).
- The store API key is placed in the system prompt so the model can pass it to tools. A production version should inject it server-side when executing the function and never show it to the model.
- RLS is enabled on
userswith no policies, so the onboarding upsert with the anon key needs a policy (or a server route using the service role). - The webhook does not verify Telegram's
secret_tokenheader yet.
- Function calling turns "chat about data" into a routing problem: tool descriptions matter more than the system prompt.
- The model's function-call turn and the function-response turn are separate round trips; the response has to be wrapped in a
functionResponsepart with an object payload. - Keeping secrets out of the prompt has to be a design decision from the start, not a later fix.
MIT