2015-06-26 01:53:20 -05:00
|
|
|
// Package tgbotapi has bindings for interacting with the Telegram Bot API.
|
2015-06-25 23:26:24 -05:00
|
|
|
package tgbotapi
|
2015-06-25 00:34:05 -05:00
|
|
|
|
2015-06-26 01:53:20 -05:00
|
|
|
// BotAPI has methods for interacting with all of Telegram's Bot API endpoints.
|
|
|
|
type BotAPI struct {
|
2015-06-25 23:26:24 -05:00
|
|
|
Token string `json:"token"`
|
|
|
|
Debug bool `json:"debug"`
|
2015-06-25 23:44:14 -05:00
|
|
|
Self User `json:"-"`
|
2015-06-25 23:26:24 -05:00
|
|
|
Updates chan Update `json:"-"`
|
2015-06-25 00:34:05 -05:00
|
|
|
}
|
|
|
|
|
2015-06-26 01:53:20 -05:00
|
|
|
// NewBotAPI creates a new BotAPI instance.
|
2015-06-26 01:19:29 -05:00
|
|
|
// Requires a token, provided by @BotFather on Telegram
|
2015-06-26 01:53:20 -05:00
|
|
|
func NewBotAPI(token string) (*BotAPI, error) {
|
|
|
|
bot := &BotAPI{
|
2015-06-25 23:26:24 -05:00
|
|
|
Token: token,
|
2015-06-25 16:15:28 -05:00
|
|
|
}
|
2015-06-25 23:44:14 -05:00
|
|
|
|
|
|
|
self, err := bot.GetMe()
|
|
|
|
if err != nil {
|
2015-06-26 01:53:20 -05:00
|
|
|
return &BotAPI{}, err
|
2015-06-25 23:44:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bot.Self = self
|
|
|
|
|
2015-06-25 23:45:56 -05:00
|
|
|
return bot, nil
|
2015-06-25 16:15:28 -05:00
|
|
|
}
|