https://github.com/nduyhai/go-zalo-bot-api
Go client for the Zalo Bot API
https://github.com/nduyhai/go-zalo-bot-api
bot zalo
Last synced: 5 months ago
JSON representation
Go client for the Zalo Bot API
- Host: GitHub
- URL: https://github.com/nduyhai/go-zalo-bot-api
- Owner: nduyhai
- License: mit
- Created: 2025-10-09T13:13:41.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-10-19T10:06:28.000Z (8 months ago)
- Last Synced: 2026-01-12T04:12:39.377Z (5 months ago)
- Topics: bot, zalo
- Language: Go
- Homepage:
- Size: 24.4 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-zalo-bot-api
A batteries-included Go client for the [Zalo Bot API](https://bot.zapps.me/docs). It wraps the HTTP endpoints with typed request/response models, retry-aware transports, and ergonomic helpers so you can focus on your bot logic instead of wiring.
## Features
- ✅ Lightweight, concurrency-safe `Client` abstraction with configurable base URL, custom HTTP client, and user agent.
- ✅ Ready-made endpoint helpers for common actions (get bot info, manage webhooks, send messages, stickers, and chat actions).
- ✅ Iterator-based long-polling helper that smooths over pagination and transient failures.
- ✅ Pluggable logging interface with structured logging support out of the box.
## Installation
```bash
go get github.com/nduyhai/go-zalo-bot-api
```
## Quick start
Create a client with your bot token and call any endpoint helper. Each request accepts per-call options such as timeouts so you can control retry and cancellation behaviour.
```go
package main
import (
"context"
"log/slog"
"time"
zalobotapi "github.com/nduyhai/go-zalo-bot-api"
"github.com/nduyhai/go-zalo-bot-api/endpoints"
)
func main() {
botToken := ""
chatID := ""
logger := zalobotapi.NewSlogLogger(slog.Default())
client := zalobotapi.New(botToken,
zalobotapi.WithLogger(logger),
zalobotapi.WithUserAgent("my-bot/1.0"),
)
ctx := context.Background()
// Call any endpoint helper. This example sends a message with a per-call timeout.
_, err := endpoints.SendMessage(ctx, client, endpoints.SendMessageReq{
ChatID: chatID,
Text: "Xin chào từ go-zalo-bot-api!",
}, zalobotapi.WithTimeout(5*time.Second))
if err != nil {
logger.Error("send message", map[string]any{"err": err})
}
}
```
Looking for a more complete example (with retries, custom transports, and long-polling for updates)? Check out [`cmd/example/main.go`](cmd/example/main.go).
## Environment variables
The example program expects:
- `BOT_TOKEN` – the access token of your Official Account bot.
- `CHAT_ID` – the identifier of the conversation you want to send messages to.
You can use a `.env` file together with [`godotenv`](https://github.com/joho/godotenv) to load these values during development.
## Development
1. Export the required environment variables (or create a `.env` file) with values for `BOT_TOKEN` and `CHAT_ID`.
2. Run the example bot:
```bash
make run
```
This executes `go run ./cmd/example` so you can verify connectivity and explore the iterator-based long-polling helpers.
## License
Distributed under the [MIT License](LICENSE).