> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Method name: listMessages(conversationId: string, visibility: MessageVisibility, options: ListMessagesOptions)

# Method package: wixInboxV2

# Method menu location: wixInboxV2 --> messages --> listMessages

# Method Link: https://dev.wix.com/docs/velo/apis/wix-inbox-v2/messages/list-messages.md

# Method Description:

Retrieves messages between the business and participant.


Up to 30 messages are returned per request. If the number of messages in a conversation is larger than 30,
`pagingMetadata.cursors` is returned in the response, indicating that another page of results is available.
To retrieve the next page of messages, pass the `next` cursor value
in the next request's `paging.cursor` parameter.

To ensure you'll always retrieve the next record,
use the same visibility and sorting
in the first request and all subsequent requests.

By default,
30 messages are retrieved and sorted by `sequence` in descending order
(the most recent messages are first in the list).



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## View a list of sent messages (dashboard page code)

```javascript
import { messages } from 'wix-inbox.v2';

/* Sample conversationId value: '9ac410b1-17f8-3b10-a3f4-0dd5c295d510'
 * 
 * Sample visibility value: 'BUSINESS_AND_PARTICIPANT'
 */

export async function myListMessagesFunction(conversationId, visibility) {
  
  try {
    const messageList = await messages.listMessages(conversationId, visibility);
    const firstSender = messageList.messages[0].sender;
    
    return messageList;
  } catch(error) {
    console.error(error);
    // Handle the error
  }
}

/* Promise resolves to:
 * {
 *   "messages": [
 *     {
 *       "_createdDate": "2023-12-28T09:41:06.660Z",
 *       "_id": "1703756466660667",
 *       "appId": "14517e1a-3ff0-af98-408e-2bd6953c36a2",
 *       "badges": [],
 *       "content": {
 *         "previewText": "thanks for the content",
 *         "basic": {
 *           "items": [
 *             {
 *               "text": "thanks for the content"
 *             }
 *           ]
 *         },
 *       },
 *       "direction": "PARTICIPANT_TO_BUSINESS",
 *       "sender": {
 *         "anonymousVisitorId": "3c06d38d-1433-4889-b303-1ff1779176e6"
 *       },
 *       "sequence": "1703756466660667",
 *       "sourceChannel": "UNKNOWN_CHANNEL_TYPE",
 *       "targetChannels": [],
 *       "visibility": "BUSINESS_AND_PARTICIPANT",
 *     },
 *     {
 *       "_createdDate": "2023-12-27T16:16:07.816Z",
 *       "_id": "1703693767816923",
 *       "badges": [],
 *       "content": {
 *         "previewText": "Thanks for the like :)",
 *         "basic": {
 *           "items": [
 *             {
 *               "text": "Thanks for the like :)"
 *             }
 *           ]
 *         },
 *       },
 *       "direction": "BUSINESS_TO_PARTICIPANT",
 *       "sender": {
 *         "wixUserId": "b17c523c-6ec9-4b56-9d9d-123cc6978bdf"
 *       },
 *       "sequence": "1703693767816923",
 *       "sourceChannel": "UNKNOWN_CHANNEL_TYPE",
 *       "targetChannels": [
 *         "CHAT"
 *       ],
 *       "visibility": "BUSINESS_AND_PARTICIPANT",
 *     }
 *   ],
 *   "pagingMetadata": {
 *     "tooManyToCount": true
 *   }
 * }
 */
```

## View a list of sent messages (export from backend code)

```javascript
import { Permissions, webMethod } from 'wix-web-module';
import { messages } from 'wix-inbox.v2';
import { elevate } from 'wix-auth';

/* Sample conversationId value: '9ac410b1-17f8-3b10-a3f4-0dd5c295d510'
 * 
 * Sample visibility value: 'BUSINESS_AND_PARTICIPANT'
 */

export const myListMessagesFunction = webMethod(Permissions.Anyone, async (conversationId, visibility) => {
  try {
    const elevatedListMessages = elevate(messages.listMessages);
    const messageList = await elevatedListMessages(conversationId, visibility);
    const firstSender = messageList.messages[0].sender;
    
    return messageList;
  } catch(error) {
    console.error(error);
    // Handle the error
  }
});

/* Promise resolves to:
 * {
 *   "messages": [
 *     {
 *       "_createdDate": "2023-12-28T09:41:06.660Z",
 *       "_id": "1703756466660667",
 *       "appId": "14517e1a-3ff0-af98-408e-2bd6953c36a2",
 *       "badges": [],
 *       "content": {
 *         "previewText": "thanks for the content",
 *         "basic": {
 *           "items": [
 *             {
 *               "text": "thanks for the content"
 *             }
 *           ]
 *         },
 *       },
 *       "direction": "PARTICIPANT_TO_BUSINESS",
 *       "sender": {
 *         "anonymousVisitorId": "3c06d38d-1433-4889-b303-1ff1779176e6"
 *       },
 *       "sequence": "1703756466660667",
 *       "sourceChannel": "UNKNOWN_CHANNEL_TYPE",
 *       "targetChannels": [],
 *       "visibility": "BUSINESS_AND_PARTICIPANT",
 *     },
 *     {
 *       "_createdDate": "2023-12-27T16:16:07.816Z",
 *       "_id": "1703693767816923",
 *       "badges": [],
 *       "content": {
 *         "previewText": "Thanks for the like :)",
 *         "basic": {
 *           "items": [
 *             {
 *               "text": "Thanks for the like :)"
 *             }
 *           ]
 *         },
 *       },
 *       "direction": "BUSINESS_TO_PARTICIPANT",
 *       "sender": {
 *         "wixUserId": "b17c523c-6ec9-4b56-9d9d-123cc6978bdf"
 *       },
 *       "sequence": "1703693767816923",
 *       "sourceChannel": "UNKNOWN_CHANNEL_TYPE",
 *       "targetChannels": [
 *         "CHAT"
 *       ],
 *       "visibility": "BUSINESS_AND_PARTICIPANT",
 *     }
 *   ],
 *   "pagingMetadata": {
 *     "tooManyToCount": true
 *   }
 * }
 */

```

---