removeWebhook method added.

bot-api-6.1
Gleb Sinyavsky 2015-11-21 14:26:39 +03:00
parent 53dd9f6367
commit 9644984dae
4 changed files with 9 additions and 12 deletions

6
bot.go
View File

@ -345,6 +345,10 @@ func (bot *BotAPI) GetUpdates(config UpdateConfig) ([]Update, error) {
return updates, nil
}
func (bot *BotAPI) RemoveWebhook() (APIResponse, error) {
return bot.MakeRequest("setWebhook", url.Values{})
}
// SetWebhook sets a webhook.
// If this is set, GetUpdates will not get any data!
//
@ -352,9 +356,7 @@ func (bot *BotAPI) GetUpdates(config UpdateConfig) ([]Update, error) {
func (bot *BotAPI) SetWebhook(config WebhookConfig) (APIResponse, error) {
if config.Certificate == nil {
v := url.Values{}
if !config.Clear {
v.Add("url", config.URL.String())
}
return bot.MakeRequest("setWebhook", v)
}

View File

@ -437,17 +437,15 @@ func TestSetWebhook(t *testing.T) {
t.Fail()
}
wh := tgbotapi.WebhookConfig{Clear: true}
_, err = bot.SetWebhook(wh)
bot.RemoveWebhook()
wh = tgbotapi.NewWebhookWithCert("https://example.com/tgbotapi-test/" + bot.Token, "tests/cert.pem")
wh := tgbotapi.NewWebhookWithCert("https://example.com/tgbotapi-test/"+bot.Token, "tests/cert.pem")
_, err = bot.SetWebhook(wh)
if err != nil {
t.Fail()
}
wh = tgbotapi.WebhookConfig{Clear: true}
_, err = bot.SetWebhook(wh)
bot.RemoveWebhook()
}
func TestUpdatesChan(t *testing.T) {

View File

@ -436,7 +436,6 @@ type UpdateConfig struct {
// WebhookConfig contains information about a SetWebhook request.
type WebhookConfig struct {
Clear bool
URL *url.URL
Certificate interface{}
}

View File

@ -207,7 +207,6 @@ func NewWebhook(link string) WebhookConfig {
return WebhookConfig{
URL: u,
Clear: false,
}
}
@ -220,7 +219,6 @@ func NewWebhookWithCert(link string, file interface{}) WebhookConfig {
return WebhookConfig{
URL: u,
Clear: false,
Certificate: file,
}
}