all repos — telegram-bot-api @ ca40caaa47e6bcb38d5dbf5c85fc87d2f689683e

Golang bindings for the Telegram Bot API

add (untested) function to set webhook with certificate
Syfaro syfaro@foxpaw.in
Mon, 07 Sep 2015 11:44:29 -0500
commit

ca40caaa47e6bcb38d5dbf5c85fc87d2f689683e

parent

87a279827eeea20b1bb05b6e5a2fac4b5ee34679

2 files changed, 40 insertions(+), 7 deletions(-)

jump to
M helpers.gohelpers.go

@@ -237,3 +237,17 @@ URL: u,

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, + } +}
M methods.gomethods.go

@@ -159,8 +159,9 @@ }

// WebhookConfig contains information about a SetWebhook request. type WebhookConfig struct { - Clear bool - URL *url.URL + Clear bool + URL *url.URL + Certificate interface{} } // FileBytes contains information about a set of bytes to upload as a File.

@@ -973,11 +974,29 @@ // SetWebhook sets a webhook.

// If this is set, GetUpdates will not get any data! // // Requires Url OR to set Clear to true. -func (bot *BotAPI) SetWebhook(config WebhookConfig) (APIResponse, error){ - v := url.Values{} - if !config.Clear { - v.Add("url", config.URL.String()) +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) } - 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 }