@@ -45,8 +45,8 @@ func NewChatService(opts ...option.RequestOption) (r ChatService) {
4545 return
4646}
4747
48- // Create a single or group chat on a specific account using participant IDs and
49- // optional title .
48+ // Create a single/ group chat (mode='create') or start a direct chat from merged
49+ // user data (mode='start') .
5050func (r * ChatService ) New (ctx context.Context , body ChatNewParams , opts ... option.RequestOption ) (res * ChatNewResponse , err error ) {
5151 opts = slices .Concat (r .Options , opts )
5252 path := "v1/chats"
@@ -93,14 +93,15 @@ func (r *ChatService) ListAutoPaging(ctx context.Context, query ChatListParams,
9393
9494// Archive or unarchive a chat. Set archived=true to move to archive,
9595// archived=false to move back to inbox
96- func (r * ChatService ) Archive (ctx context.Context , chatID string , body ChatArchiveParams , opts ... option.RequestOption ) (res * ChatArchiveResponse , err error ) {
96+ func (r * ChatService ) Archive (ctx context.Context , chatID string , body ChatArchiveParams , opts ... option.RequestOption ) (err error ) {
9797 opts = slices .Concat (r .Options , opts )
98+ opts = append ([]option.RequestOption {option .WithHeader ("Accept" , "*/*" )}, opts ... )
9899 if chatID == "" {
99100 err = errors .New ("missing required chatID parameter" )
100101 return
101102 }
102103 path := fmt .Sprintf ("v1/chats/%s/archive" , chatID )
103- err = requestconfig .ExecuteNewRequest (ctx , http .MethodPost , path , body , & res , opts ... )
104+ err = requestconfig .ExecuteNewRequest (ctx , http .MethodPost , path , body , nil , opts ... )
104105 return
105106}
106107
@@ -134,6 +135,10 @@ type Chat struct {
134135 ID string `json:"id,required"`
135136 // Account ID this chat belongs to.
136137 AccountID string `json:"accountID,required"`
138+ // Display-only human-readable network name (e.g., 'WhatsApp', 'Messenger').
139+ //
140+ // Deprecated: deprecated
141+ Network string `json:"network,required"`
137142 // Chat participants information.
138143 Participants ChatParticipants `json:"participants,required"`
139144 // Display title of the chat as computed by the client/server.
@@ -160,6 +165,7 @@ type Chat struct {
160165 JSON struct {
161166 ID respjson.Field
162167 AccountID respjson.Field
168+ Network respjson.Field
163169 Participants respjson.Field
164170 Title respjson.Field
165171 Type respjson.Field
@@ -216,9 +222,15 @@ const (
216222type ChatNewResponse struct {
217223 // Newly created chat ID.
218224 ChatID string `json:"chatID,required"`
225+ // Only returned in start mode. 'existing' means an existing chat was reused;
226+ // 'created' means a new chat was created.
227+ //
228+ // Any of "existing", "created".
229+ Status ChatNewResponseStatus `json:"status"`
219230 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
220231 JSON struct {
221232 ChatID respjson.Field
233+ Status respjson.Field
222234 ExtraFields map [string ]respjson.Field
223235 raw string
224236 } `json:"-"`
@@ -230,6 +242,15 @@ func (r *ChatNewResponse) UnmarshalJSON(data []byte) error {
230242 return apijson .UnmarshalRoot (data , r )
231243}
232244
245+ // Only returned in start mode. 'existing' means an existing chat was reused;
246+ // 'created' means a new chat was created.
247+ type ChatNewResponseStatus string
248+
249+ const (
250+ ChatNewResponseStatusExisting ChatNewResponseStatus = "existing"
251+ ChatNewResponseStatusCreated ChatNewResponseStatus = "created"
252+ )
253+
233254type ChatListResponse struct {
234255 // Last message preview for this chat, if available.
235256 Preview shared.Message `json:"preview"`
@@ -248,26 +269,29 @@ func (r *ChatListResponse) UnmarshalJSON(data []byte) error {
248269 return apijson .UnmarshalRoot (data , r )
249270}
250271
251- type ChatArchiveResponse struct {
252- // Indicates the operation completed successfully
272+ type ChatNewParams struct {
273+
253274 //
254- // Any of true.
255- Success bool `json:"success,required"`
256- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
257- JSON struct {
258- Success respjson.Field
259- ExtraFields map [string ]respjson.Field
260- raw string
261- } `json:"-"`
275+ // Request body variants
276+ //
277+
278+ // This field is a request body variant, only one variant field can be set.
279+ OfObject * ChatNewParamsBodyObject `json:",inline"`
280+ // This field is a request body variant, only one variant field can be set.
281+ OfChatNewsBodyObject * ChatNewParamsBodyObject `json:",inline"`
282+
283+ paramObj
262284}
263285
264- // Returns the unmodified JSON received from the API
265- func (r ChatArchiveResponse ) RawJSON () string { return r .JSON .raw }
266- func (r * ChatArchiveResponse ) UnmarshalJSON (data []byte ) error {
286+ func (u ChatNewParams ) MarshalJSON () ([]byte , error ) {
287+ return param .MarshalUnion (u , u .OfObject , u .OfChatNewsBodyObject )
288+ }
289+ func (r * ChatNewParams ) UnmarshalJSON (data []byte ) error {
267290 return apijson .UnmarshalRoot (data , r )
268291}
269292
270- type ChatNewParams struct {
293+ // The properties AccountID, ParticipantIDs, Type are required.
294+ type ChatNewParamsBodyObject struct {
271295 // Account to create the chat on.
272296 AccountID string `json:"accountID,required"`
273297 // User IDs to include in the new chat.
@@ -276,30 +300,34 @@ type ChatNewParams struct {
276300 // supports multiple participants and optional title.
277301 //
278302 // Any of "single", "group".
279- Type ChatNewParamsType `json:"type,omitzero,required"`
303+ Type string `json:"type,omitzero,required"`
280304 // Optional first message content if the platform requires it to create the chat.
281305 MessageText param.Opt [string ] `json:"messageText,omitzero"`
282306 // Optional title for group chats; ignored for single chats on most platforms.
283307 Title param.Opt [string ] `json:"title,omitzero"`
308+ // Create mode. Defaults to 'create' when omitted.
309+ //
310+ // Any of "create".
311+ Mode string `json:"mode,omitzero"`
284312 paramObj
285313}
286314
287- func (r ChatNewParams ) MarshalJSON () (data []byte , err error ) {
288- type shadow ChatNewParams
315+ func (r ChatNewParamsBodyObject ) MarshalJSON () (data []byte , err error ) {
316+ type shadow ChatNewParamsBodyObject
289317 return param .MarshalObject (r , (* shadow )(& r ))
290318}
291- func (r * ChatNewParams ) UnmarshalJSON (data []byte ) error {
319+ func (r * ChatNewParamsBodyObject ) UnmarshalJSON (data []byte ) error {
292320 return apijson .UnmarshalRoot (data , r )
293321}
294322
295- // Chat type to create: 'single' requires exactly one participantID; 'group'
296- // supports multiple participants and optional title.
297- type ChatNewParamsType string
298-
299- const (
300- ChatNewParamsTypeSingle ChatNewParamsType = "single"
301- ChatNewParamsTypeGroup ChatNewParamsType = "group"
302- )
323+ func init () {
324+ apijson . RegisterFieldValidator [ ChatNewParamsBodyObject ](
325+ " type" , "single" , "group" ,
326+ )
327+ apijson . RegisterFieldValidator [ ChatNewParamsBodyObject ] (
328+ "mode" , "create" ,
329+ )
330+ }
303331
304332type ChatGetParams struct {
305333 // Maximum number of participants to return. Use -1 for all; otherwise 0–500.
0 commit comments