Skip to content

Commit c087da3

Browse files
committed
fix: dont change message status when escalating
1 parent 2bf21cf commit c087da3

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/server/api/schema.js

+28-19
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,8 @@ async function sendMessage(
441441
campaignContactId,
442442
message,
443443
checkOptOut = true,
444-
checkAssignment = true
444+
checkAssignment = true,
445+
skipUpdatingMessageStatus = false
445446
) {
446447
const record = await r
447448
.knex("campaign_contact")
@@ -622,15 +623,18 @@ async function sendMessage(
622623

623624
const { cc_message_status } = record;
624625
const contactSavePromise = (async () => {
625-
await r
626-
.knex("campaign_contact")
627-
.update({
628-
message_status:
629-
cc_message_status === "needsResponse" || cc_message_status === "convo"
630-
? "convo"
631-
: "messaged"
632-
})
633-
.where({ id: record.cc_id });
626+
if (!skipUpdatingMessageStatus) {
627+
await r
628+
.knex("campaign_contact")
629+
.update({
630+
message_status:
631+
cc_message_status === "needsResponse" ||
632+
cc_message_status === "convo"
633+
? "convo"
634+
: "messaged"
635+
})
636+
.where({ id: record.cc_id });
637+
}
634638

635639
const contact = await r
636640
.knex("campaign_contact")
@@ -1504,6 +1508,16 @@ const rootMutations = {
15041508
await r.knex("campaign_contact_tag").insert(tagsToInsert)
15051509
]);
15061510

1511+
// See if any of the newly applied tags are is_assignable = false
1512+
const newlyAssignedTagsThatShouldUnassign = await r
1513+
.knex("tag")
1514+
.select("id")
1515+
.whereIn("id", addedTagIds)
1516+
.where({ is_assignable: false });
1517+
1518+
const currentlyEscalating =
1519+
newlyAssignedTagsThatShouldUnassign.length > 0;
1520+
15071521
if (tag.message) {
15081522
try {
15091523
const checkOptOut = true;
@@ -1513,7 +1527,8 @@ const rootMutations = {
15131527
campaignContactId,
15141528
tag.message,
15151529
checkOptOut,
1516-
checkAssignment
1530+
checkAssignment,
1531+
currentlyEscalating
15171532
);
15181533
} catch (error) {
15191534
// Log the sendMessage error, but return successful opt out creation
@@ -1526,16 +1541,10 @@ const rootMutations = {
15261541
.whereIn("id", addedTagIds)
15271542
.pluck("webhook_url")
15281543
.then(urls => urls.filter(url => url.length > 0));
1529-
await notifyOnTagConversation(campaignContactId, user.id, webhookUrls);
15301544

1531-
// See if any of the newly applied tags are is_assignable = false
1532-
const newlyAssignedTagsThatShouldUnassign = await r
1533-
.knex("tag")
1534-
.select("id")
1535-
.whereIn("id", addedTagIds)
1536-
.where({ is_assignable: false });
1545+
await notifyOnTagConversation(campaignContactId, user.id, webhookUrls);
15371546

1538-
if (newlyAssignedTagsThatShouldUnassign.length > 0) {
1547+
if (currentlyEscalating) {
15391548
await r
15401549
.knex("campaign_contact")
15411550
.update({ assignment_id: null })

0 commit comments

Comments
 (0)