GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - turkmenugur/chatdb: Telegram bot that answers e-commerce store questions with Gemini function calling (Next.js + Supabase)

BranchesTags
Open more actions menu

Latest commit

 

History

1 Commit
1 Commit

Folders and files

NameName
Last commit message
Last commit date
src
src
 
 
supabase
supabase
 
 
.env.example
.env.example
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
eslint.config.mjs
eslint.config.mjs
 
 
next.config.ts
next.config.ts
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
postcss.config.mjs
postcss.config.mjs
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

chatdb

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.

Why

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.

Stack

  • 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/genai with function declarations
  • Supabase (Postgres) for linking a Telegram user to a store API key
  • Telegram Bot API (webhook)

Architecture

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

Run it

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.

Results

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.

Known limitations

  • 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 users with 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_token header yet.

What I learned

  • 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 functionResponse part with an object payload.
  • Keeping secrets out of the prompt has to be a design decision from the start, not a later fix.

License

MIT

About

Telegram bot that answers e-commerce store questions with Gemini function calling (Next.js + Supabase)

Topics

ecommercefunction-callinggeminillmnextjssupabasetelegram-bottypescript

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.