@@ -63,11 +63,26 @@ func (r *MessageService) ListAutoPaging(ctx context.Context, query MessageListPa
6363}
6464
6565// Search messages across chats using Beeper's message index
66- func (r * MessageService ) Search (ctx context.Context , query MessageSearchParams , opts ... option.RequestOption ) (res * MessageSearchResponse , err error ) {
66+ func (r * MessageService ) Search (ctx context.Context , query MessageSearchParams , opts ... option.RequestOption ) (res * pagination.Cursor [shared.Message ], err error ) {
67+ var raw * http.Response
6768 opts = append (r .Options [:], opts ... )
69+ opts = append ([]option.RequestOption {option .WithResponseInto (& raw )}, opts ... )
6870 path := "v1/messages/search"
69- err = requestconfig .ExecuteNewRequest (ctx , http .MethodGet , path , query , & res , opts ... )
70- return
71+ cfg , err := requestconfig .NewRequestConfig (ctx , http .MethodGet , path , query , & res , opts ... )
72+ if err != nil {
73+ return nil , err
74+ }
75+ err = cfg .Execute ()
76+ if err != nil {
77+ return nil , err
78+ }
79+ res .SetPageConfig (cfg , raw )
80+ return res , nil
81+ }
82+
83+ // Search messages across chats using Beeper's message index
84+ func (r * MessageService ) SearchAutoPaging (ctx context.Context , query MessageSearchParams , opts ... option.RequestOption ) * pagination.CursorAutoPager [shared.Message ] {
85+ return pagination .NewCursorAutoPager (r .Search (ctx , query , opts ... ))
7186}
7287
7388// Send a text message to a specific chat. Supports replying to existing messages.
@@ -79,37 +94,6 @@ func (r *MessageService) Send(ctx context.Context, body MessageSendParams, opts
7994 return
8095}
8196
82- type MessageSearchResponse struct {
83- // Map of chatID -> chat details for chats referenced in items.
84- Chats map [string ]Chat `json:"chats,required"`
85- // True if additional results can be fetched using the provided cursors.
86- HasMore bool `json:"hasMore,required"`
87- // Messages matching the query and filters.
88- Items []shared.Message `json:"items,required"`
89- // Cursor for fetching newer results (use with direction='after'). Opaque string;
90- // do not inspect.
91- NewestCursor string `json:"newestCursor,required"`
92- // Cursor for fetching older results (use with direction='before'). Opaque string;
93- // do not inspect.
94- OldestCursor string `json:"oldestCursor,required"`
95- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
96- JSON struct {
97- Chats respjson.Field
98- HasMore respjson.Field
99- Items respjson.Field
100- NewestCursor respjson.Field
101- OldestCursor respjson.Field
102- ExtraFields map [string ]respjson.Field
103- raw string
104- } `json:"-"`
105- }
106-
107- // Returns the unmodified JSON received from the API
108- func (r MessageSearchResponse ) RawJSON () string { return r .JSON .raw }
109- func (r * MessageSearchResponse ) UnmarshalJSON (data []byte ) error {
110- return apijson .UnmarshalRoot (data , r )
111- }
112-
11397type MessageSendResponse struct {
11498 // Unique identifier of the chat.
11599 ChatID string `json:"chatID,required"`
0 commit comments