telegram-bot-api/bot.go

40 lines
973 B
Go
Raw Normal View History

// Package tgbotapi has bindings for interacting with the Telegram Bot API.
package tgbotapi
import (
"net/http"
)
// BotAPI has methods for interacting with all of Telegram's Bot API endpoints.
type BotAPI struct {
2015-07-28 11:18:49 +02:00
Token string `json:"token"`
Debug bool `json:"debug"`
Self User `json:"-"`
Updates chan Update `json:"-"`
Client *http.Client `json:"-"`
}
// NewBotAPI creates a new BotAPI instance.
2015-06-26 08:19:29 +02:00
// Requires a token, provided by @BotFather on Telegram
func NewBotAPI(token string) (*BotAPI, error) {
return NewBotAPIWithClient(token, &http.Client{})
}
2015-07-28 18:14:13 +02:00
// NewBotAPIWithClient creates a new BotAPI instance passing an http.Client.
// Requires a token, provided by @BotFather on Telegram
2015-07-28 18:14:13 +02:00
func NewBotAPIWithClient(token string, client *http.Client) (*BotAPI, error) {
bot := &BotAPI{
Token: token,
2015-07-28 11:18:49 +02:00
Client: client,
}
2015-06-26 06:44:14 +02:00
self, err := bot.GetMe()
if err != nil {
return &BotAPI{}, err
2015-06-26 06:44:14 +02:00
}
bot.Self = self
2015-06-26 06:45:56 +02:00
return bot, nil
}