@@ -85,15 +85,17 @@ func (o ListInboxOptions) ToURLValues() url.Values {
8585 return values
8686}
8787
88- // ListMessagesOptions holds optional filters for listing messages.
88+ // ListMessagesOptions holds optional filters and sorting for listing messages.
89+ // Sorting follows the JSON:API specification (sort parameter).
8990type ListMessagesOptions struct {
90- From * time.Time `query:"from" validate:"omitempty"`
91- To * time.Time `query:"to" validate:"omitempty"`
92- State * string `query:"state" validate:"omitempty,oneof=Pending Cancelling Cancelled Processed Sent Delivered Failed"`
93- DeviceID * string `query:"deviceId" validate:"omitempty,len=21"`
94- Limit * int `query:"limit" validate:"omitempty,min=1,max=100"`
95- Offset * int `query:"offset" validate:"omitempty,min=0"`
96- IncludeContent * bool `query:"includeContent"`
91+ From * time.Time `query:"from"`
92+ To * time.Time `query:"to"`
93+ State * string `query:"state" validate:"omitempty,oneof=Pending Cancelling Cancelled Processed Sent Delivered Failed"`
94+ DeviceID * string `query:"deviceId" validate:"omitempty,len=21"`
95+ Limit * int `query:"limit" validate:"omitempty,min=1,max=100"`
96+ Offset * int `query:"offset" validate:"omitempty,min=0"`
97+ IncludeContent * bool `query:"includeContent"`
98+ Sort * MessagesSortOrder `query:"sort" validate:"omitempty,oneof=created_at -created_at"`
9799}
98100
99101// Validate checks if the ListMessagesOptions are valid.
@@ -129,5 +131,15 @@ func (o ListMessagesOptions) ToURLValues() url.Values {
129131 if o .IncludeContent != nil {
130132 values .Set ("includeContent" , strconv .FormatBool (* o .IncludeContent ))
131133 }
134+ if o .Sort != nil {
135+ values .Set ("sort" , string (* o .Sort ))
136+ }
132137 return values
133138}
139+
140+ type MessagesSortOrder string
141+
142+ const (
143+ CreatedAtAscending MessagesSortOrder = "created_at"
144+ CreatedAtDescending MessagesSortOrder = "-created_at"
145+ )
0 commit comments