|
|
|
@ -29,7 +29,8 @@ type BotAPI struct { |
|
|
|
|
Client *http.Client `json:"-"` |
|
|
|
|
shutdownChannel chan interface{} |
|
|
|
|
|
|
|
|
|
apiEndpoint string |
|
|
|
|
apiEndpoint string |
|
|
|
|
fileEndpoint string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewBotAPI creates a new BotAPI instance.
|
|
|
|
@ -50,7 +51,33 @@ func NewBotAPIWithClient(token string, client *http.Client) (*BotAPI, error) { |
|
|
|
|
Buffer: 100, |
|
|
|
|
shutdownChannel: make(chan interface{}), |
|
|
|
|
|
|
|
|
|
apiEndpoint: APIEndpoint, |
|
|
|
|
apiEndpoint: APIEndpoint, |
|
|
|
|
fileEndpoint: FileEndpoint, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self, err := bot.GetMe() |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bot.Self = self |
|
|
|
|
|
|
|
|
|
return bot, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewBotAPICustom creates a new BotAPI instance
|
|
|
|
|
// and allows you to pass apiEndpoint, fileEndpoint and http.Client.
|
|
|
|
|
//
|
|
|
|
|
// It requires a token, provided by @BotFather on Telegram.
|
|
|
|
|
func NewBotAPICustom(token, apiEndpoint, fileEndpoint string, client *http.Client) (*BotAPI, error) { |
|
|
|
|
bot := &BotAPI{ |
|
|
|
|
Token: token, |
|
|
|
|
Client: client, |
|
|
|
|
Buffer: 100, |
|
|
|
|
shutdownChannel: make(chan interface{}), |
|
|
|
|
|
|
|
|
|
apiEndpoint: apiEndpoint, |
|
|
|
|
fileEndpoint: fileEndpoint, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self, err := bot.GetMe() |
|
|
|
@ -67,6 +94,10 @@ func (b *BotAPI) SetAPIEndpoint(apiEndpoint string) { |
|
|
|
|
b.apiEndpoint = apiEndpoint |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (b *BotAPI) SetFileEndpoint(fileEndpoint string) { |
|
|
|
|
b.fileEndpoint = fileEndpoint |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// MakeRequest makes a request to a specific endpoint with our token.
|
|
|
|
|
func (bot *BotAPI) MakeRequest(endpoint string, params url.Values) (APIResponse, error) { |
|
|
|
|
method := fmt.Sprintf(bot.apiEndpoint, bot.Token, endpoint) |
|
|
|
@ -242,7 +273,7 @@ func (bot *BotAPI) GetFileDirectURL(fileID string) (string, error) { |
|
|
|
|
return "", err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return file.Link(bot.Token), nil |
|
|
|
|
return file.Link(bot.Token, bot.fileEndpoint), nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetMe fetches the currently authenticated bot.
|
|
|
|
|