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

8
bot.go
View File

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

View File

@ -437,17 +437,15 @@ func TestSetWebhook(t *testing.T) {
t.Fail() t.Fail()
} }
wh := tgbotapi.WebhookConfig{Clear: true} bot.RemoveWebhook()
_, err = bot.SetWebhook(wh)
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) _, err = bot.SetWebhook(wh)
if err != nil { if err != nil {
t.Fail() t.Fail()
} }
wh = tgbotapi.WebhookConfig{Clear: true} bot.RemoveWebhook()
_, err = bot.SetWebhook(wh)
} }
func TestUpdatesChan(t *testing.T) { func TestUpdatesChan(t *testing.T) {

View File

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

View File

@ -206,8 +206,7 @@ func NewWebhook(link string) WebhookConfig {
u, _ := url.Parse(link) u, _ := url.Parse(link)
return WebhookConfig{ return WebhookConfig{
URL: u, URL: u,
Clear: false,
} }
} }
@ -220,7 +219,6 @@ func NewWebhookWithCert(link string, file interface{}) WebhookConfig {
return WebhookConfig{ return WebhookConfig{
URL: u, URL: u,
Clear: false,
Certificate: file, Certificate: file,
} }
} }