From 98b3e1da4cab5c048383fa9d9ee5617f2643066a Mon Sep 17 00:00:00 2001 From: Huanan Date: Tue, 29 Apr 2025 19:07:40 +0800 Subject: [PATCH] use InputPeerUser by custom username to 'user[%d]' --- internal/tg/draft.go | 4 ++-- internal/tg/helpers.go | 2 +- internal/tg/history.go | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/tg/draft.go b/internal/tg/draft.go index e934597..3ff566c 100644 --- a/internal/tg/draft.go +++ b/internal/tg/draft.go @@ -35,12 +35,12 @@ func (c *Client) SendDraft(args DraftArguments) (*mcp.ToolResponse, error) { Message: args.Text, }) if err != nil { - return fmt.Errorf("failed to get history: %w", err) + return fmt.Errorf("failed to send draft: %w", err) } return nil }); err != nil { - return nil, errors.Wrap(err, "failed to get history") + return nil, errors.Wrap(err, "failed to send draft") } jsonData, err := json.Marshal(DraftResponse{Success: ok}) diff --git a/internal/tg/helpers.go b/internal/tg/helpers.go index 8fe2258..0a158fc 100644 --- a/internal/tg/helpers.go +++ b/internal/tg/helpers.go @@ -30,7 +30,7 @@ func getUsername(source any) string { var username string switch u := source.(type) { case *tg.User: - username = u.Username + username = fmt.Sprintf("user[%d]", u.ID) case *tg.Chat: username = fmt.Sprintf("cht[%d]", u.ID) case *tg.Channel: diff --git a/internal/tg/history.go b/internal/tg/history.go index 1a2319c..c43bb44 100644 --- a/internal/tg/history.go +++ b/internal/tg/history.go @@ -89,6 +89,14 @@ func getInputPeerFromName(ctx context.Context, api *tg.Client, name string) (tg. } return &chatPeer, nil + case strings.HasPrefix(name, "user") && isCustom: + var userPeer tg.InputPeerUser + _, err := fmt.Sscanf(name, "user[%d]", &userPeer.UserID) + if err != nil { + return nil, errors.Wrapf(err, "scan user peer(%q)", name) + } + + return &userPeer, nil default: sender := message.NewSender(api) inputPeer, err := sender.Resolve(name).AsInputPeer(ctx)