1
0

🚑 Fixed invalid types in NewInputMedia args and rewrite requestURI

This commit is contained in:
Maxim Lebedev 2017-11-21 15:15:03 +05:00
parent e0ba1a1b93
commit 2dc679a0a1
No known key found for this signature in database
GPG Key ID: F8978F46FF0FFA4F
2 changed files with 11 additions and 6 deletions

View File

@ -326,17 +326,17 @@ func NewInputContactMessageContent(phoneNumber, firstName string) *InputContactM
} }
} }
func NewInputMediaPhoto(media InputFile) *InputMediaPhoto { func NewInputMediaPhoto(media string) *InputMediaPhoto {
return &InputMediaPhoto{ return &InputMediaPhoto{
Type: TypePhoto, Type: TypePhoto,
Media: media, Media: media,
} }
} }
func NewInputMediaVideo(media InputFile) *InputMediaVideo { func NewInputMediaVideo(media string) *InputMediaVideo {
return &InputMediaVideo{ return &InputMediaVideo{
Type: TypeVideo, Type: TypeVideo,
Media: file, Media: media,
} }
} }

View File

@ -3,15 +3,20 @@ package telegram
import ( import (
"errors" "errors"
"fmt" "fmt"
"net/url"
json "github.com/pquerna/ffjson/ffjson" json "github.com/pquerna/ffjson/ffjson"
http "github.com/valyala/fasthttp" http "github.com/valyala/fasthttp"
) )
func (bot *Bot) request(dst []byte, method string, args *http.Args) (*Response, error) { func (bot *Bot) request(dst []byte, method string, args *http.Args) (*Response, error) {
requestURI := fmt.Sprintf(APIEndpoint, bot.AccessToken, method) requestURI := &url.URL{
Scheme: "https",
Host: "api.telegram.org",
Path: fmt.Sprint("/bot", bot.AccessToken, "/", method),
}
if args != nil { if args != nil {
requestURI += fmt.Sprint("?", args.String()) requestURI.RawQuery = args.String()
} }
var req http.Request var req http.Request
@ -19,7 +24,7 @@ func (bot *Bot) request(dst []byte, method string, args *http.Args) (*Response,
req.Header.SetMethod("POST") req.Header.SetMethod("POST")
req.Header.SetContentType("application/json") req.Header.SetContentType("application/json")
req.SetRequestURI(requestURI) req.SetRequestURI(requestURI.String())
req.SetBody(dst) req.SetBody(dst)
if err := http.Do(&req, &resp); err != nil { if err := http.Do(&req, &resp); err != nil {