removeWebhook method added.
parent
53dd9f6367
commit
9644984dae
8
bot.go
8
bot.go
|
@ -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())
|
||||
}
|
||||
v.Add("url", config.URL.String())
|
||||
|
||||
return bot.MakeRequest("setWebhook", v)
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -436,7 +436,6 @@ type UpdateConfig struct {
|
|||
|
||||
// WebhookConfig contains information about a SetWebhook request.
|
||||
type WebhookConfig struct {
|
||||
Clear bool
|
||||
URL *url.URL
|
||||
Certificate interface{}
|
||||
}
|
||||
|
|
|
@ -206,8 +206,7 @@ func NewWebhook(link string) WebhookConfig {
|
|||
u, _ := url.Parse(link)
|
||||
|
||||
return WebhookConfig{
|
||||
URL: u,
|
||||
Clear: false,
|
||||
URL: u,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -220,7 +219,6 @@ func NewWebhookWithCert(link string, file interface{}) WebhookConfig {
|
|||
|
||||
return WebhookConfig{
|
||||
URL: u,
|
||||
Clear: false,
|
||||
Certificate: file,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue