Conversation Service
Learn how to use Nextiva's conversation service
Overview
The ConversationService class provides methods for managing and manipulating conversations in Nextiva. It handles conversation creation, message sending, participant management, and state transitions for omnichannel communications.The BaseConversationService class handles various operations related to conversations, including creating, fetching, messaging, and managing conversation states through API calls.
Summary
- A Conversation represents a thread of related messages, calls, or interactions between two or more participants (such as customers, agents, or systems). Conversations can include chat messages, calls, SMS, or emails, and are identified by a unique
conversationId. - This service enables developers to create, fetch, update, and manage conversations, as well as send and edit messages within those conversations.
- Conversations can be associated with campaigns, tickets, and workitems, and support features like archiving, participant management, and message drafts.
Key Terms:
- Conversation: A persistent thread of communication between participants, identified by a
conversationId. - Participant: A user or entity involved in a conversation (e.g., agent, customer).
- Campaign: A group or context for conversations, often representing a business process or marketing effort.
Basic Usage
At the basic level, the ConversationService class can be used to fetch conversations, create a new conversation, or send a message.
// Fetch conversations
const conversations = await conversationService.fetchConversations();
// Create a new conversation
const newConversation = await conversationService.createConversation({
description: "Support conversation",
name: "Customer Support",
participants: [
{ id: "user123", role: "agent" },
{ phoneNumber: "+15551234567", role: "customer" }
],
phoneNumber: "+15551234567"
});
// Send a message
const response = await conversationService.sendMessage({
campaignId: "campaign123",
conversationId: "conv456",
message: "How can I help you today?",
messageType: "TEXT",
mentionedUsers: [],
fromAddressOption: "support",
to: [{ phoneNumber: "+15551234567" }]
});API Reference
fetchconversation
Fetches a paginated list of conversations.
public async fetchConversations({
rows = 100,
start = 0,
}: {
rows?: number;
start?: number;
}): Promise<ConversationsResponse>Parameters
rowsnumber
The number of items per page, the default is 100.startnumber
The starting index of the pagination, the default is 0.
Returns
Promise<ConversationsResponse>
Promise that resolves with a ConversationsResponse containing the fetched conversationsexport interface PaginatedResponse<T> { count: number; next: string; objects: Workitem[]; previous: string; total: number; }
Example
// Fetch the first page of conversations with 50 items per page
const conversations = await conversationService.fetchConversations({
rows: 50,
start: 0
});Updated 5 months ago