add telegram bot

This commit is contained in:
2026-02-12 17:36:57 +03:00
parent 9ca2e67805
commit 9d374a97cd
7 changed files with 451 additions and 0 deletions
+37
View File
@@ -67,6 +67,43 @@ func (c *Client) ListMemos(ctx context.Context, filter string, pageSize int, pag
return &result, nil
}
// DownloadAttachment downloads the attachment data as bytes.
func (c *Client) DownloadAttachment(ctx context.Context, att Attachment) ([]byte, error) {
var reqURL string
var needsAuth bool
if att.ExternalLink != "" {
reqURL = att.ExternalLink
} else {
reqURL = fmt.Sprintf("%s/file/%s/%s", c.baseURL, att.Name, att.Filename)
needsAuth = true
}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, reqURL, nil)
if err != nil {
return nil, fmt.Errorf("create request: %w", err)
}
if needsAuth {
req.Header.Set("Authorization", "Bearer "+c.token)
}
resp, err := c.httpClient.Do(req)
if err != nil {
return nil, fmt.Errorf("do request: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("download attachment %s: status %d", att.Name, resp.StatusCode)
}
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("read body: %w", err)
}
return data, nil
}
// GetRandomMemo fetches a single memo without any filter (for full fallback).
func (c *Client) GetRandomMemo(ctx context.Context) (*Memo, error) {
resp, err := c.ListMemos(ctx, "", 1, "")