This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Retrieves a conversation by the specified visitor, contact, or member ID. If the conversation does not exist for the provided visitor, contact, or member, the function creates a new conversation.
This function requires elevated permissions and runs only on the backend and on dashboard pages.
function getOrCreateConversation(
participantId: ParticipantId,
): Promise<GetOrCreateConversationResponse>;
ID of the visitor, contact, or member chatting with the business.
import { conversations } from "wix-inbox.v2";
import { elevate } from "wix-auth";
/* Sample participantId value:
* {
* memberId: 'b17c523c-6ec9-4b56-9d9d-123cc6978bdf'
* }
*/
export async function myGetOrCreateConversationFunction(participantId) {
try {
const elevatedGetOrCreateConversation = elevate(
conversations.getOrCreateConversation,
);
const conversationObject =
await elevatedGetOrCreateConversation(participantId);
const id = conversationObject.conversation._id;
const channels = conversationObject.conversation.channels;
const siteName = conversationObject.conversation.businessDisplayData.name;
return conversationObject;
} catch (error) {
console.error(error);
// Handle the error
}
}
/* Promise resolves to:
* {
* "conversation": {
* "_id": "092d1135-99cf-3ca9-a0bf-378e1df4539b",
* "businessDisplayData": {
* "name": "Classic Cars"
* },
* "channels": [
* "CHAT",
* EMAIL
* ],
* "participant": {
* "memberId": "b17c523c-6ec9-4b56-9d9d-123cc6978bdf"
* },
* "participantDisplayData": {
* "name": "alevine@email.com"
* }
* "newConversation": false
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.