usememos / memos

An open-source, lightweight note-taking solution. The pain-less way to create your meaningful notes. Your Notes, Your Way.
https://usememos.com
MIT License
34.16k stars 2.47k forks source link

[Done/Wait for live]Could you please support proxy configuration for telegram bot #1786

Closed 520hacker closed 1 year ago

520hacker commented 1 year ago

Is your feature request related to a problem?

as you know, sometimes we need deploy our service on the big Lan, we have no chose to directly visit telegram, proxy is the only option .

so , Could you please support it , and add configuration on the settings.

please notice , this proxy should only use for TG not for OSS .etc .

may thanks .

Describe the solution you'd like

Additional context

https://github.com/usememos/memos/blob/main/plugin/telegram/request.go#L18

sample codes:

func (b *Bot) postForm(ctx context.Context, apiPath string, formData url.Values, result any, proxy string) error { apiURL, err := b.apiURL(ctx) if err != nil { return err }

// Create an http.Client with a custom transport that includes the proxy configuration client := &http.Client{ Transport: &http.Transport{ Proxy: http.ProxyURL(proxyURL(proxy)), }, }

resp, err := client.PostForm(apiURL+apiPath, formData) if err != nil { return fmt.Errorf("fail to http.PostForm: %s", err) } defer resp.Body.Close()

body, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("fail to ioutil.ReadAll: %s", err) }

var respInfo struct { Ok bool json:"ok" ErrorCode int json:"error_code" Description string json:"description" Result any json:"result" }

respInfo.Result = result

err = json.Unmarshal(body, &respInfo) if err != nil { return fmt.Errorf("fail to json.Unmarshal: %s", err) }

if !respInfo.Ok { return fmt.Errorf("api error: [%d]%s", respInfo.ErrorCode, respInfo.Description) }

return nil }

// Helper function to create a URL for the proxy func proxyURL(proxy string) *url.URL { // Use http:// scheme for simplicity, but you can modify it to handle different schemes return &url.URL{ Scheme: "http", Host: proxy, } }

520hacker commented 1 year ago

image

Issues-translate-bot commented 1 year ago

Issue is not in English. It has been translated automatically.


image