2015-06-26 08:19:29 +02:00
|
|
|
// Methods for interacting with the Telegram Bot API.
|
2015-06-26 06:26:24 +02:00
|
|
|
package tgbotapi
|
2015-06-25 07:34:05 +02:00
|
|
|
|
2015-06-26 06:26:24 +02:00
|
|
|
type BotApi struct {
|
|
|
|
Token string `json:"token"`
|
|
|
|
Debug bool `json:"debug"`
|
2015-06-26 06:44:14 +02:00
|
|
|
Self User `json:"-"`
|
2015-06-26 06:26:24 +02:00
|
|
|
Updates chan Update `json:"-"`
|
2015-06-25 07:34:05 +02:00
|
|
|
}
|
|
|
|
|
2015-06-26 08:19:29 +02:00
|
|
|
// Creates a new BotApi instance.
|
|
|
|
// Requires a token, provided by @BotFather on Telegram
|
2015-06-26 06:44:14 +02:00
|
|
|
func NewBotApi(token string) (*BotApi, error) {
|
|
|
|
bot := &BotApi{
|
2015-06-26 06:26:24 +02:00
|
|
|
Token: token,
|
2015-06-25 23:15:28 +02:00
|
|
|
}
|
2015-06-26 06:44:14 +02:00
|
|
|
|
|
|
|
self, err := bot.GetMe()
|
|
|
|
if err != nil {
|
2015-06-26 06:45:56 +02:00
|
|
|
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
|
2015-06-25 23:15:28 +02:00
|
|
|
}
|