💩 Added experimental SetWebhook method
This commit is contained in:
parent
b4c01e895c
commit
710a813a57
|
@ -1,6 +1,12 @@
|
|||
package telegram
|
||||
|
||||
import json "github.com/pquerna/ffjson/ffjson"
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
|
||||
json "github.com/pquerna/ffjson/ffjson"
|
||||
http "github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
type SetWebhookParameters struct {
|
||||
// HTTPS url to send updates to. Use an empty string to remove webhook
|
||||
|
@ -40,12 +46,33 @@ type SetWebhookParameters struct {
|
|||
// recommend using a secret path in the URL, e.g. https://www.example.com/<token>.
|
||||
// Since nobody else knows your bot‘s token, you can be pretty sure it’s us.
|
||||
func (bot *Bot) SetWebhook(params *SetWebhookParameters) (bool, error) {
|
||||
var args http.Args
|
||||
|
||||
if params.Certificate != nil {
|
||||
cert := *params.Certificate
|
||||
switch f := cert.(type) {
|
||||
case string:
|
||||
body, err := ioutil.ReadFile(f)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// args.AddBytesV("certificate", body)
|
||||
cert = body
|
||||
case []byte:
|
||||
// args.AddBytesV("certificate", bytes.NewBuffer(f).Bytes())
|
||||
cert = bytes.NewBuffer(f).Bytes()
|
||||
}
|
||||
// params.Certificate = nil
|
||||
params.Certificate = &cert
|
||||
}
|
||||
|
||||
dst, err := json.Marshal(*params)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
resp, err := bot.request(dst, "setWebhook", nil)
|
||||
resp, err := bot.request(dst, "setWebhook", &args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user