feat: add telegram proxy support (#1764)

* Add support for reverse proxy of telegram API

* Add Telegram API proxy hint

---------

Co-authored-by: Athurg Feng <athurg@gooth.org>
This commit is contained in:
Athurg Gooth
2023-05-29 13:29:21 +08:00
committed by GitHub
parent beb4d8ccb9
commit ce64894abe
7 changed files with 48 additions and 16 deletions

View File

@@ -3,23 +3,19 @@ package telegram
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"net/url"
)
var ErrNoToken = errors.New("token is empty")
func (r *Robot) postForm(ctx context.Context, apiPath string, formData url.Values, result any) error {
token := r.handler.RobotToken(ctx)
if token == "" {
return ErrNoToken
apiURL, err := r.apiURL(ctx)
if err != nil {
return err
}
uri := "https://api.telegram.org/bot" + token + apiPath
resp, err := http.PostForm(uri, formData)
resp, err := http.PostForm(apiURL+apiPath, formData)
if err != nil {
return fmt.Errorf("fail to http.PostForm: %s", err)
}