all repos — telegram-bot-api @ fc8cb6e0398c8801c799ebe0a09d26e87ae6f6ce

Golang bindings for the Telegram Bot API

bot.go (view raw)

 1// Package tgbotapi has bindings for interacting with the Telegram Bot API.
 2package tgbotapi
 3
 4import "net/http"
 5
 6// BotAPI has methods for interacting with all of Telegram's Bot API endpoints.
 7type BotAPI struct {
 8	Token   string       `json:"token"`
 9	Debug   bool         `json:"debug"`
10	Self    User         `json:"-"`
11	Updates chan Update  `json:"-"`
12	Client  *http.Client `json:"-"`
13}
14
15// NewBotAPI creates a new BotAPI instance.
16// Requires a token, provided by @BotFather on Telegram
17func NewBotAPI(token string, client *http.Client) (*BotAPI, error) {
18	if client == nil {
19		client = &http.Client{}
20	}
21
22	bot := &BotAPI{
23		Token:  token,
24		Client: client,
25	}
26
27	self, err := bot.GetMe()
28	if err != nil {
29		return &BotAPI{}, err
30	}
31
32	bot.Self = self
33
34	return bot, nil
35}