Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/data/modules/flow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const checkIfIsCondition = (condition: IFlowActionValueCondition, content: strin
};

const handleMessage = async (msg: IMessageDocument) => {
if (msg.isGroupMsg || !msg.content) return;
if (msg.isGroupMsg || !msg.content || !msg.customerId) return;

let conversation = await Conversations.getConversation(msg.conversationId);

Expand Down
26 changes: 26 additions & 0 deletions src/data/modules/integrations/receiveMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,32 @@ export const receiveRpcMessage = async msg => {
}

if (action === 'create-conversation-message') {
if (doc.isMe) {
let conversation = await Conversations.findById(doc.conversationId);

let userId = conversation?.assignedUserId;

if (!userId) {
const integration = await Integrations.findOne({ _id: doc.integrationId });

userId = integration?.defaultSenderId || integration?.createdUserId;

if (!userId) {
const user = await Users.findOne({ isOwner: true });

userId = user?._id;
}

if (userId && conversation) {
conversation.assignedUserId = userId;

await Conversations.updateOne({ _id: conversation._id }, { assignedUserId: conversation.assignedUserId });
}
}

doc.userId = userId;
}

const message = await ConversationMessages.createMessage(doc);

const conversationDoc: {
Expand Down
3 changes: 2 additions & 1 deletion src/db/models/definitions/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export interface IIntegration {
export interface IIntegrationDocument extends IIntegration, Document {
_id: string;
createdUserId: string;
defaultSenderId: string;
// TODO remove
formData?: ILeadData;
leadData?: ILeadDataDocument;
Expand Down Expand Up @@ -301,7 +302,7 @@ const webhookDataSchema = new Schema(
export const integrationSchema = new Schema({
_id: field({ pkey: true }),
createdUserId: field({ type: String, label: 'Created by' }),

defaultSenderId: field({ type: String, label: 'Default sender' }),
kind: field({
type: String,
enum: KIND_CHOICES.ALL,
Expand Down