Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bot config
GEMINI_API_KEY=<your-gemini-api-key>
ADDR=:8080

# Telegram client config
BOT_TOKEN=<telegram-bot-token>
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ go.work.sum
history-gemini/*
!history-gemini/.gitkeep
bot-context/*
!bot-context/.gitkeep
!bot-context/.gitkeep
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ Required env variable(s):

Optional env variable(s):
- `ADDR` - Listen address for the server (Default: `:8080`)
- `GEMINI_MODEL` - Model to use (Default: `gemini-2.5-flash-preview-04-17`)
- `GEMINI_MODEL` - Model to use (Default: `gemini-2.5-flash`)
- `MCP_SERVERS` - MCP HTTP stream server for external function calls (Eg.: `http://localhost:8081/sse`), this could be a comma separated list for multiple servers
- `SEARCH_ENABLE` - Allow to use Google search for the AI service (Default: `false`, it won't work together with MCP servers)
- `HISTORY_SUMMARY` - After how many messages the history should be summarized (Default: `20`, `0` means no summary, both model and user messages counts)

All the history will be stored under the `history-gemini` folder.

Expand Down Expand Up @@ -83,6 +84,14 @@ If you have a user id, you can use it in the call.
curl -v -H "X-User-ID: someuserid1" -X POST http://127.0.0.1:8080/message -d "message=Hi there"
```

### Use docker

There is a provided docker compose file.
First make a copy of the `.env.example` file and rename it to `.env` and set your Gemini api key, then you can run the following command to start the server:
```
docker-compose up
```


### Client examples

Expand Down Expand Up @@ -132,7 +141,6 @@ Optional env variables:
- `GRAPHQL_URL` - GraphQL base url (Default: `https://graph.facebook.com/v22.0`)
- `ADDR` - Server listening address (Default: `:8082`)
- `AI_SERVICE` - AI service (the server-bot's) address (Default: `http://127.0.0.1:8080`)
- `HISTORY_SUMMARY` - After how many messages the history should be summarized (Default: `20`, `0` means no summary, both model and user messages counts)

Then you can start chatting with the bot via sending a message to the page.
(If you configured an MCP in the AI service it will be called too.)
Expand Down
3 changes: 2 additions & 1 deletion cmd/server-bot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (
func main() {

logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelDebug, // TODO: set to configurable level
// Level: slog.LevelDebug, // TODO: set to configurable level
Level: slog.LevelInfo,
}))

addr := os.Getenv("ADDR")
Expand Down
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# docker-compose.yml
version: '3.4'
services:
bot:
build:
context: .
dockerfile: docker/Dockerfile-bot
target: production
env_file:
- .env
ports:
- "8080:8080"
volumes:
- bot-data:/app

client-telegram:
build:
context: .
dockerfile: docker/Dockerfile-client-telegram
target: production
environment:
AI_SERVICE: http://bot:8080
env_file:
- .env
depends_on:
- bot

volumes:
bot-data:
16 changes: 16 additions & 0 deletions docker/Dockerfile-bot
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM golang:1.25 AS build

WORKDIR /go/src/app
COPY . .

RUN go mod download
RUN CGO_ENABLED=0 go build -o /go/bin/server-bot -ldflags '-w -s' cmd/server-bot/main.go


FROM gcr.io/distroless/static as production
WORKDIR /app
COPY --from=build /go/bin/server-bot server-bot
COPY --from=build /go/src/app/history-gemini history-gemini
COPY --from=build /go/src/app/bot-context bot-context
COPY --from=build /go/src/app/personality.json personality.json
ENTRYPOINT ["./server-bot"]
12 changes: 12 additions & 0 deletions docker/Dockerfile-client-telegram
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:1.25 AS build

WORKDIR /go/src/app
COPY . .

RUN go mod download
RUN CGO_ENABLED=0 go build -o /go/bin/client-telegram -ldflags '-w -s' cmd/client-telegram/main.go


FROM gcr.io/distroless/static as production
COPY --from=build /go/bin/client-telegram /client-telegram
ENTRYPOINT ["/client-telegram"]