add (untested) function to set webhook with certificate
parent
87a279827e
commit
ca40caaa47
14
helpers.go
14
helpers.go
|
@ -237,3 +237,17 @@ func NewWebhook(link string) WebhookConfig {
|
||||||
Clear: false,
|
Clear: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewWebhookWithCert creates a new webhook with a selfsigned certificate.
|
||||||
|
//
|
||||||
|
// link is the url you wish to get webhooks,
|
||||||
|
// file contains a string to a file, or a FileReader or FileBytes.
|
||||||
|
func NewWebhookWithCert(link string, file interface{}) WebhookConfig {
|
||||||
|
u, _ := url.Parse(link)
|
||||||
|
|
||||||
|
return WebhookConfig{
|
||||||
|
URL: u,
|
||||||
|
Clear: false,
|
||||||
|
Certificate: file,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
21
methods.go
21
methods.go
|
@ -161,6 +161,7 @@ type UpdateConfig struct {
|
||||||
type WebhookConfig struct {
|
type WebhookConfig struct {
|
||||||
Clear bool
|
Clear bool
|
||||||
URL *url.URL
|
URL *url.URL
|
||||||
|
Certificate interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileBytes contains information about a set of bytes to upload as a File.
|
// FileBytes contains information about a set of bytes to upload as a File.
|
||||||
|
@ -973,11 +974,29 @@ func (bot *BotAPI) GetUpdates(config UpdateConfig) ([]Update, error) {
|
||||||
// If this is set, GetUpdates will not get any data!
|
// If this is set, GetUpdates will not get any data!
|
||||||
//
|
//
|
||||||
// Requires Url OR to set Clear to true.
|
// Requires Url OR to set Clear to true.
|
||||||
func (bot *BotAPI) SetWebhook(config WebhookConfig) (APIResponse, error){
|
func (bot *BotAPI) SetWebhook(config WebhookConfig) (APIResponse, error) {
|
||||||
|
if config.Certificate == nil {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
if !config.Clear {
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
params := make(map[string]string)
|
||||||
|
|
||||||
|
resp, err := bot.UploadFile("setWebhook", params, "certificate", config.Certificate)
|
||||||
|
if err != nil {
|
||||||
|
return APIResponse{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiResp APIResponse
|
||||||
|
json.Unmarshal(resp.Result, &apiResp)
|
||||||
|
|
||||||
|
if bot.Debug {
|
||||||
|
log.Printf("sendVideo resp: %+v\n", apiResp)
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiResp, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue