https://github.com/yi-jiayu/ted
Go bindings for the Telegram Bot API
https://github.com/yi-jiayu/ted
go telegram
Last synced: 5 months ago
JSON representation
Go bindings for the Telegram Bot API
- Host: GitHub
- URL: https://github.com/yi-jiayu/ted
- Owner: yi-jiayu
- Created: 2020-03-13T10:17:07.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-03-21T09:24:38.000Z (over 5 years ago)
- Last Synced: 2025-04-25T14:59:27.620Z (about 1 year ago)
- Topics: go, telegram
- Language: Go
- Size: 95.7 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

# ted
Go bindings for the Telegram Bot API
## Usage
Ted's API is loosely based on the Go standard library's `net/http` package.
Create a `ted.Bot` with your bot token and HTTP client, then build your request and send it:
```go
bot := ted.Bot{
Token: "BOT_TOKEN",
HTTPClient: http.DefaultClient,
}
req := ted.SendMessageRequest{
ChatID: 123,
Text: "*Hello, World*",
ParseMode: "Markdown",
}
res, err := bot.Do(req)
if err != nil {
if response, ok := err.(ted.Response); ok {
// handle Telegram error
}
// handle HTTP error
}
```
The bot also handles making multiple requests concurrently:
```go
answerCallbackQueryRequest := ted.AnswerCallbackQueryRequest{
CallbackQueryID: "abc",
}
sendMessageRequest := ted.SendMessageRequest{
ChatID: 123,
Text: "*Hello, World*",
ParseMode: "Markdown",
}
// err will be nil if all requests were successful
responses, err := bot.DoMulti(answerCallbackQueryRequest, sendMessageRequest)
```
To use the result, unmarshal it just as you would a HTTP response body:
```go
getMe := GetMeRequest{}
res, err := bot.Do(getMe)
if err != nil {
panic(err)
}
var me User
err = json.Unmarshal(res.Result, &me)
if err != nil {
panic(err)
}
```