conversation

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2026 License: AGPL-3.0 Imports: 43 Imported by: 0

Documentation

Overview

Package conversation manages conversations and messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles the operations related to conversations

func New

func New(
	wsHub *ws.Hub,
	i18n *i18n.I18n,
	slaStore slaStore,
	statusStore statusStore,
	priorityStore priorityStore,
	inboxStore inboxStore,
	userStore userStore,
	teamStore teamStore,
	mediaStore mediaStore,
	settingsStore settingsStore,
	csatStore csatStore,
	automation *automation.Engine,
	template *template.Manager,
	webhook webhookStore,
	dispatcher *notifier.Dispatcher,
	opts Opts) (*Manager, error)

New initializes a new conversation Manager.

func (*Manager) ActiveUserConversationsCount

func (c *Manager) ActiveUserConversationsCount(userID int) (int, error)

ActiveUserConversationsCount returns the count of active conversations for a user. i.e. conversations not closed or resolved status.

func (*Manager) ApplyAction

func (m *Manager) ApplyAction(action amodels.RuleAction, conv models.Conversation, user umodels.User) error

ApplyAction applies an action to a conversation, this can be called from multiple packages across the app to perform actions on conversations. all actions are executed on behalf of the provided user if the user is not provided, system user is used.

func (*Manager) ApplySLA

func (m *Manager) ApplySLA(conversation models.Conversation, policyID int, actor umodels.User) error

ApplySLA applies the SLA policy to a conversation.

func (*Manager) BroadcastConversationUpdate

func (m *Manager) BroadcastConversationUpdate(conversationUUID, prop string, value any)

BroadcastConversationUpdate broadcasts a conversation update to all users.

func (*Manager) BroadcastMessageUpdate

func (m *Manager) BroadcastMessageUpdate(conversationUUID, messageUUID, prop string, value any)

BroadcastMessageUpdate broadcasts a message update to all users.

func (*Manager) BroadcastNewMessage

func (m *Manager) BroadcastNewMessage(message *cmodels.Message)

BroadcastNewMessage broadcasts a new message to all users.

func (*Manager) Close

func (m *Manager) Close()

Close signals the Manager to stop processing messages, closes channels, and waits for all worker goroutines to finish processing.

func (*Manager) CreateContactMessage

func (m *Manager) CreateContactMessage(media []mmodels.Media, contactID int, conversationUUID, content, contentType string) (models.Message, error)

CreateContactMessage creates a contact message in a conversation.

func (*Manager) CreateConversation

func (c *Manager) CreateConversation(contactID, contactChannelID, inboxID int, lastMessage string, lastMessageAt time.Time, subject string, appendRefNumToSubject bool) (int, string, error)

CreateConversation creates a new conversation and returns its ID and UUID.

func (*Manager) DeleteConversation

func (m *Manager) DeleteConversation(uuid string) error

DeleteConversation deletes a conversation.

func (*Manager) DeleteConversationDraft

func (m *Manager) DeleteConversationDraft(conversationID int, uuid string, userID int) error

DeleteConversationDraft deletes a draft for a conversation by ID or UUID.

func (*Manager) DeleteStaleDrafts

func (m *Manager) DeleteStaleDrafts(ctx context.Context, retentionPeriod time.Duration) error

DeleteStaleDrafts deletes drafts older than the specified retention period.

func (*Manager) EnqueueIncoming

func (m *Manager) EnqueueIncoming(message models.IncomingMessage) error

EnqueueIncoming enqueues an incoming message for inserting in db.

func (*Manager) GetAllConversationsList

func (c *Manager) GetAllConversationsList(viewingUserID int, order, orderBy, filters string, page, pageSize int) ([]models.ConversationListItem, error)

GetAllConversationsList retrieves all conversations with optional filtering, ordering, and pagination.

func (*Manager) GetAllUserDrafts

func (m *Manager) GetAllUserDrafts(userID int) ([]models.ConversationDraft, error)

GetAllUserDrafts retrieves all drafts for a user.

func (*Manager) GetAssignedConversationsList

func (c *Manager) GetAssignedConversationsList(viewingUserID, userID int, order, orderBy, filters string, page, pageSize int) ([]models.ConversationListItem, error)

GetAssignedConversationsList retrieves conversations assigned to a specific user with optional filtering, ordering, and pagination.

func (*Manager) GetContactPreviousConversations

func (c *Manager) GetContactPreviousConversations(contactID int, limit int) ([]models.PreviousConversation, error)

GetContactPreviousConversations retrieves previous conversations for a contact with a configurable limit.

func (*Manager) GetConversation

func (c *Manager) GetConversation(id int, uuid, refNum string) (models.Conversation, error)

GetConversation retrieves a conversation by its ID or UUID.

func (*Manager) GetConversationByMessageID

func (m *Manager) GetConversationByMessageID(id int) (models.Conversation, error)

GetConversationByMessageID returns conversation by message id.

func (*Manager) GetConversationMessages

func (m *Manager) GetConversationMessages(conversationUUID string, page, pageSize int, private *bool, msgTypes []string) ([]models.Message, int, error)

GetConversationMessages retrieves messages for a specific conversation.

func (*Manager) GetConversationParticipants

func (c *Manager) GetConversationParticipants(uuid string) ([]models.ConversationParticipant, error)

GetConversationParticipants retrieves the participants of a conversation.

func (*Manager) GetConversationUUID

func (c *Manager) GetConversationUUID(id int) (string, error)

GetConversationUUID retrieves the UUID of a conversation by its ID.

func (*Manager) GetConversations

func (c *Manager) GetConversations(viewingUserID, userID int, teamIDs []int, listTypes []string, order, orderBy, filters string, page, pageSize int) ([]models.ConversationListItem, error)

GetConversations retrieves conversations list based on user ID, type, and optional filtering, ordering, and pagination. viewingUserID is used to calculate per-agent unread counts.

func (*Manager) GetConversationsCreatedAfter

func (c *Manager) GetConversationsCreatedAfter(time time.Time) ([]models.Conversation, error)

GetConversationsCreatedAfter retrieves conversations created after the specified time.

func (*Manager) GetMentionedConversationsList

func (c *Manager) GetMentionedConversationsList(viewingUserID int, order, orderBy, filters string, page, pageSize int) ([]models.ConversationListItem, error)

GetMentionedConversationsList retrieves conversations where the user is mentioned (directly or via team).

func (*Manager) GetMessage

func (m *Manager) GetMessage(uuid string) (models.Message, error)

GetMessage retrieves a message by UUID.

func (*Manager) GetMessageSourceIDs

func (m *Manager) GetMessageSourceIDs(conversationID, limit int) ([]string, error)

GetMessageSourceIDs retrieves source IDs for messages in a conversation in descending order. So the oldest message will be the last in the list.

func (*Manager) GetTeamUnassignedConversationsList

func (c *Manager) GetTeamUnassignedConversationsList(viewingUserID, teamID int, order, orderBy, filters string, page, pageSize int) ([]models.ConversationListItem, error)

GetTeamUnassignedConversationsList retrieves conversations assigned to a team with optional filtering, ordering, and pagination.

func (*Manager) GetUnassignedConversations

func (c *Manager) GetUnassignedConversations() ([]models.Conversation, error)

GetUnassignedConversations retrieves unassigned conversations.

func (*Manager) GetUnassignedConversationsList

func (c *Manager) GetUnassignedConversationsList(viewingUserID int, order, orderBy, filters string, page, pageSize int) ([]models.ConversationListItem, error)

GetUnassignedConversationsList retrieves conversations assigned to a team the user is part of with optional filtering, ordering, and pagination.

func (*Manager) GetViewConversationsList

func (c *Manager) GetViewConversationsList(viewingUserID, userID int, teamIDs []int, listType []string, order, orderBy, filters string, page, pageSize int) ([]models.ConversationListItem, error)

func (*Manager) IncomingMessageWorker

func (m *Manager) IncomingMessageWorker(ctx context.Context)

IncomingMessageWorker processes incoming messages from the incoming message queue.

func (*Manager) InsertConversationActivity

func (m *Manager) InsertConversationActivity(activityType, conversationUUID, newValue string, actor umodels.User) error

InsertConversationActivity inserts an activity message.

func (*Manager) InsertMentions

func (c *Manager) InsertMentions(conversationID, messageID, mentionedByUserID int, mentions []models.MentionInput) error

InsertMentions inserts mentions for a message.

func (*Manager) InsertMessage

func (m *Manager) InsertMessage(message *models.Message) error

InsertMessage inserts a message and attaches the media to the message.

func (*Manager) MarkAsUnread

func (c *Manager) MarkAsUnread(uuid string, userID int) error

MarkAsUnread marks a conversation as unread for a specific user by setting last_seen to before the last message.

func (*Manager) MarkMessageAsPending

func (m *Manager) MarkMessageAsPending(uuid string) error

MarkMessageAsPending updates message status to `Pending`, enqueuing it for sending.

func (*Manager) MessageExists

func (m *Manager) MessageExists(messageID string) (bool, error)

MessageExists checks if a message with the given messageID exists.

func (*Manager) MessageSenderWorker

func (m *Manager) MessageSenderWorker(ctx context.Context)

MessageSenderWorker sends outgoing pending messages.

func (*Manager) NotifyAssignment

func (m *Manager) NotifyAssignment(userIDs []int, conversation models.Conversation) error

NotifyAssignment sends notifications (in-app, WebSocket, email) for an assigned conversation.

func (*Manager) NotifyMention

func (m *Manager) NotifyMention(conversationUUID string, message models.Message, mentions []models.MentionInput, mentionedByUserID int)

NotifyMention sends notifications (in-app, WebSocket, email) for mentions. For team mentions, expands to all team members.

func (*Manager) QueueReply

func (m *Manager) QueueReply(media []mmodels.Media, inboxID, senderID int, conversationUUID, content string, to, cc, bcc []string, meta map[string]interface{}) (models.Message, error)

QueueReply queues a reply message in a conversation.

func (*Manager) ReOpenConversation

func (c *Manager) ReOpenConversation(conversationUUID string, actor umodels.User) error

ReOpenConversation reopens a conversation if it's snoozed, resolved or closed.

func (*Manager) RecordAssigneeTeamChange

func (m *Manager) RecordAssigneeTeamChange(conversationUUID string, teamID int, actor umodels.User) error

RecordAssigneeTeamChange records an activity for a team assignee change.

func (*Manager) RecordAssigneeUserChange

func (m *Manager) RecordAssigneeUserChange(conversationUUID string, assigneeID int, actor umodels.User) error

RecordAssigneeUserChange records an activity for a user assignee change.

func (*Manager) RecordPriorityChange

func (m *Manager) RecordPriorityChange(priority, conversationUUID string, actor umodels.User) error

RecordPriorityChange records an activity for a priority change.

func (*Manager) RecordSLASet

func (m *Manager) RecordSLASet(conversationUUID string, slaName string, actor umodels.User) error

RecordSLASet records an activity for an SLA set.

func (*Manager) RecordStatusChange

func (m *Manager) RecordStatusChange(status, conversationUUID string, actor umodels.User) error

RecordStatusChange records an activity for a status change.

func (*Manager) RecordTagAddition

func (m *Manager) RecordTagAddition(conversationUUID string, tag string, actor umodels.User) error

RecordTagAddition records an activity for a tag addition.

func (*Manager) RecordTagRemoval

func (m *Manager) RecordTagRemoval(conversationUUID string, tag string, actor umodels.User) error

RecordTagRemoval records an activity for a tag removal.

func (*Manager) RemoveConversationAssignee

func (m *Manager) RemoveConversationAssignee(uuid, typ string, actor umodels.User) error

RemoveConversationAssignee removes assigned user from a conversation.

func (*Manager) RenderMessageInTemplate

func (m *Manager) RenderMessageInTemplate(channel string, message *models.Message) error

RenderMessageInTemplate renders message content in template.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context, incomingQWorkers, outgoingQWorkers, scanInterval time.Duration)

Run starts a pool of worker goroutines to handle message dispatching via inbox's channel and processes incoming messages. It scans for pending outgoing messages at the specified read interval and pushes them to the outgoing queue to be sent.

func (*Manager) RunDraftCleaner

func (c *Manager) RunDraftCleaner(ctx context.Context, retentionPeriod time.Duration)

RunDraftCleaner runs the draft cleanup routine every 2 hours.

func (*Manager) RunUnsnoozer

func (c *Manager) RunUnsnoozer(ctx context.Context, unsnoozeInterval time.Duration)

RunUnsnoozer runs the conversation unsnoozer.

func (*Manager) SendCSATReply

func (m *Manager) SendCSATReply(actorUserID int, conversation models.Conversation) error

SendCSATReply sends a CSAT reply message to a conversation.

func (*Manager) SendPrivateNote

func (m *Manager) SendPrivateNote(media []mmodels.Media, senderID int, conversationUUID, content string, mentions []models.MentionInput) (models.Message, error)

SendPrivateNote inserts a private message in a conversation.

func (*Manager) SetConversationTags

func (c *Manager) SetConversationTags(uuid string, action string, tagNames []string, actor umodels.User) error

SetConversationTags sets the tags associated with a conversation.

func (*Manager) UnassignOpen

func (m *Manager) UnassignOpen(userID int) error

UnassignOpen unassigns all open conversations belonging to a user. i.e conversations without status `Closed` and `Resolved`.

func (*Manager) UpdateAssignee

func (c *Manager) UpdateAssignee(uuid string, assigneeID int, assigneeType string) error

UpdateAssignee updates the assignee of a conversation.

func (*Manager) UpdateConversationCustomAttributes

func (c *Manager) UpdateConversationCustomAttributes(uuid string, customAttributes map[string]any) error

UpdateConversationCustomAttributes updates the custom attributes of a conversation.

func (*Manager) UpdateConversationFirstReplyAt

func (c *Manager) UpdateConversationFirstReplyAt(conversationUUID string, conversationID int, at time.Time) error

UpdateConversationFirstReplyAt updates the first reply timestamp for a conversation.

func (*Manager) UpdateConversationLastMessage

func (c *Manager) UpdateConversationLastMessage(conversation int, conversationUUID, lastMessage, lastMessageSenderType, messageType string, private bool, lastMessageAt time.Time) error

UpdateConversationLastMessage updates the last message details for a conversation. Also conditionally updates last_interaction fields if messageType != 'activity' and !private.

func (*Manager) UpdateConversationLastReplyAt

func (c *Manager) UpdateConversationLastReplyAt(conversationUUID string, conversationID int, at time.Time) error

UpdateConversationLastReplyAt updates the last reply timestamp for a conversation.

func (*Manager) UpdateConversationPriority

func (c *Manager) UpdateConversationPriority(uuid string, priorityID int, priority string, actor umodels.User) error

UpdateConversationPriority updates the priority of a conversation.

func (*Manager) UpdateConversationStatus

func (c *Manager) UpdateConversationStatus(uuid string, statusID int, status, snoozeDur string, actor umodels.User) error

UpdateConversationStatus updates the status of a conversation.

func (*Manager) UpdateConversationTeamAssignee

func (c *Manager) UpdateConversationTeamAssignee(uuid string, teamID int, actor umodels.User) error

UpdateConversationTeamAssignee sets the assignee of a conversation to a specific team and sets the assigned user id to NULL.

func (*Manager) UpdateConversationUserAssignee

func (c *Manager) UpdateConversationUserAssignee(uuid string, assigneeID int, actor umodels.User) error

UpdateConversationUserAssignee sets the assignee of a conversation to a specifc user.

func (*Manager) UpdateConversationWaitingSince

func (c *Manager) UpdateConversationWaitingSince(conversationUUID string, at *time.Time) error

UpdateConversationWaitingSince updates the waiting since timestamp for a conversation.

func (*Manager) UpdateMessageStatus

func (m *Manager) UpdateMessageStatus(messageUUID string, status string) error

UpdateMessageStatus updates the status of a message.

func (*Manager) UpdateUserLastSeen

func (c *Manager) UpdateUserLastSeen(uuid string, userID int) error

UpdateUserLastSeen updates the last seen timestamp for a specific user on a conversation.

func (*Manager) UpsertConversationDraft

func (m *Manager) UpsertConversationDraft(conversationID, userID int, content string, meta json.RawMessage) (models.ConversationDraft, error)

UpsertConversationDraft saves or updates a draft for a conversation.

type Opts

type Opts struct {
	DB                       *sqlx.DB
	Lo                       *logf.Logger
	OutgoingMessageQueueSize int
	IncomingMessageQueueSize int
}

Opts holds the options for creating a new Manager.

Directories

Path Synopsis
Package priority handles the management of conversation priorities.
Package priority handles the management of conversation priorities.
Package status handles the management of conversation statuses.
Package status handles the management of conversation statuses.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL