Skip to the documentation
PHP

$client->chats

Every method in this namespace: its signature, its parameters, what it returns and an example.

Methods

The conversations held with the assistant in the app: list and search them, read one, rename it and delete it. Each person reaches only their own.

chats->list

List the assistant chats

Scopesthreads:readPages through results
Signature
list(    ?string $q = null,    ?string $sort = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): Page

Returns one page of the conversations held with the assistant in the app, newest first, as its Chats page lists them, each with its title, how many messages it holds and when it last changed.

Each person reaches only their own chats: an API key reaches the chats of the workspace owner, and an access token reaches the chats of the person who connected it. A key or token limited to particular addresses or domains is 422 capability_unsupported.

Parameters

qstring

Searches the titles.

sortstring

newest (the default) or oldest by the last change, or title, as in Nextmail\Constants\ChatSorts. A cursor carries on in the order it was handed out in.

limitint

Page size, from 1 to 100. The server defaults to 25.

cursorstring

The nextCursor of the previous page. Leave it out for the first page.

apiKeystring

Overrides the client's API key for this call only.

Returns

A Page of arrays with items, hasMore and nextCursor. Each item has id, title, kind, messageCount and updatedAt.

Example

use Nextmail\Constants\ChatSorts; $page = $client->chats->list(q: 'invoices', sort: ChatSorts::NEWEST, limit: 20); foreach ($page as $chat) {    echo $chat['title'], ' (', $chat['messageCount'], ' messages)', PHP_EOL;} if ($page->hasMore) {    $next = $client->chats->list(q: 'invoices', cursor: $page->nextCursor);     echo $next->items[0]['title'] ?? 'nothing more', PHP_EOL;}

Notes

Also available in

API
GET /chats
TypeScript
nextmail.chats.list()
Python
chats.list()
Ruby
chats.list
Go
Chats.List
Java
chats().list
C#
Chats.ListAsync
CLI
openemail chats list

chats->listAll

Collect every chat into one array

Scopesthreads:readPages through results
Signature
listAll(    ?string $q = null,    ?string $sort = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): array

Walks every page of list and returns every chat, in the order sort: names. One request per page, with the same filters on each.

Parameters

qstring

Searches the titles.

sortstring

newest (the default) or oldest by the last change, or title, as in Nextmail\Constants\ChatSorts. A cursor carries on in the order it was handed out in.

limitint

Page size for each request, from 1 to 100. The server defaults to 25.

cursorstring

Starts the walk after this cursor instead of the first page.

apiKeystring

Overrides the client API key for every page of this walk.

Returns

A list of arrays holding every chat.

Example

$chats = $client->chats->listAll(q: 'invoices'); echo implode(PHP_EOL, array_column($chats, 'title')), PHP_EOL;

Notes

  • If any page fails the call throws and the rows already fetched are discarded.

Also available in

API
GET /chats
TypeScript
nextmail.chats.listAll()
Python
chats.list_all()
Ruby
chats.list_all
Go
Chats.ListAll
Java
chats().listAll
C#
Chats.ListAllAsync

chats->iterate

Stream the chats one at a time

Scopesthreads:readPages through results
Signature
iterate(    ?string $q = null,    ?string $sort = null,    ?int $limit = null,    ?string $cursor = null,    ?string $apiKey = null,): Generator

Returns a Generator that yields one chat at a time, in the order sort: names, and requests the next page only once the current one is drained. Nothing is fetched until you consume it, and breaking out of the loop stops the requests.

Parameters

qstring

Searches the titles.

sortstring

newest (the default) or oldest by the last change, or title, as in Nextmail\Constants\ChatSorts. A cursor carries on in the order it was handed out in.

limitint

Page size for each request, from 1 to 100. The server defaults to 25.

cursorstring

Starts the walk after this cursor instead of the first page.

apiKeystring

Overrides the client API key for every page of this walk.

Returns

A Generator that yields one chat array per step.

Example

use Nextmail\Constants\ChatSorts; foreach ($client->chats->iterate(sort: ChatSorts::TITLE) as $chat) {    echo $chat['title'], ' ', $chat['updatedAt'], PHP_EOL;}

Notes

  • Each page is one request, so a long walk makes many.

Also available in

API
GET /chats
TypeScript
nextmail.chats.iterate()
Python
chats.iterate()
Ruby
chats.iterate
Go
Chats.Iterate
Java
chats().iterate
C#
Chats.IterateAsync

chats->get

Retrieve a chat

Scopesthreads:read
Signature
get(string $id, ?string $apiKey = null): array

Returns one chat with the assistant by its id: its title, how many messages it holds and when it last changed.

Each person reaches only their own chats: an API key reaches the chats of the workspace owner, and an access token reaches the chats of the person who connected it. A key or token limited to particular addresses or domains is 422 capability_unsupported.

Parameters

idstringRequired

The chat id from list.

apiKeystring

Overrides the client's API key for this call only.

Returns

An array with id, title, kind, messageCount and updatedAt.

Example

$chat = $client->chats->get('8f3c2a71-5e9d-4b06-a1c4-7d2e9f0b3a65'); echo $chat['title'], ', last changed ', $chat['updatedAt'], PHP_EOL;

Notes

  • An unknown id is a 404.

Also available in

API
GET /chats/{id}
TypeScript
nextmail.chats.get()
Python
chats.get()
Ruby
chats.get
Go
Chats.Get
Java
chats().get
C#
Chats.GetAsync
CLI
openemail chats get

chats->rename

Rename a chat

Scopesthreads:write
Signature
rename(string $id, string $title, ?string $apiKey = null): array

Gives a chat with the assistant a new title, up to 120 characters, and returns the chat as it is now.

Each person reaches only their own chats: an API key reaches the chats of the workspace owner, and an access token reaches the chats of the person who connected it. A key or token limited to particular addresses or domains is 422 capability_unsupported.

Parameters

idstringRequired

The chat id from list.

titlestringRequired

The new title, from 1 to 120 characters.

apiKeystring

Overrides the client's API key for this call only.

Returns

The same array as chats->get, with the new title.

Example

$chat = $client->chats->rename('8f3c2a71-5e9d-4b06-a1c4-7d2e9f0b3a65', 'Quarterly invoices'); echo $chat['title'], PHP_EOL;

Notes

  • An unknown id is a 404.

Also available in

API
PATCH /chats/{id}
TypeScript
nextmail.chats.rename()
Python
chats.rename()
Ruby
chats.rename
Go
Chats.Rename
Java
chats().rename
C#
Chats.RenameAsync
CLI
openemail chats rename

chats->delete

Delete a chat

Scopesthreads:write
Signature
delete(string $id, ?string $apiKey = null): array

Deletes a chat with the assistant and every message in it, for good. Nothing the assistant did in the mailbox is undone.

Each person reaches only their own chats: an API key reaches the chats of the workspace owner, and an access token reaches the chats of the person who connected it. A key or token limited to particular addresses or domains is 422 capability_unsupported.

Parameters

idstringRequired

The chat id from list.

apiKeystring

Overrides the client's API key for this call only.

Returns

An array with object set to chat, the id and deleted set to true.

Example

use Nextmail\Exception\NotFoundException; try {    $client->chats->delete('8f3c2a71-5e9d-4b06-a1c4-7d2e9f0b3a65');} catch (NotFoundException) {    echo 'Already gone', PHP_EOL;}

Notes

  • An unknown id is a 404, and so is a second call for the same chat.

  • The SDK does not retry it.

Also available in

API
DELETE /chats/{id}
TypeScript
nextmail.chats.delete()
Python
chats.delete()
Ruby
chats.delete
Go
Chats.Delete
Java
chats().delete
C#
Chats.DeleteAsync
CLI
openemail chats delete