@@ -441,7 +441,8 @@ async function sendMessage(
441
441
campaignContactId ,
442
442
message ,
443
443
checkOptOut = true ,
444
- checkAssignment = true
444
+ checkAssignment = true ,
445
+ skipUpdatingMessageStatus = false
445
446
) {
446
447
const record = await r
447
448
. knex ( "campaign_contact" )
@@ -622,15 +623,18 @@ async function sendMessage(
622
623
623
624
const { cc_message_status } = record ;
624
625
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
+ }
634
638
635
639
const contact = await r
636
640
. knex ( "campaign_contact" )
@@ -1504,6 +1508,16 @@ const rootMutations = {
1504
1508
await r . knex ( "campaign_contact_tag" ) . insert ( tagsToInsert )
1505
1509
] ) ;
1506
1510
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
+
1507
1521
if ( tag . message ) {
1508
1522
try {
1509
1523
const checkOptOut = true ;
@@ -1513,7 +1527,8 @@ const rootMutations = {
1513
1527
campaignContactId ,
1514
1528
tag . message ,
1515
1529
checkOptOut ,
1516
- checkAssignment
1530
+ checkAssignment ,
1531
+ currentlyEscalating
1517
1532
) ;
1518
1533
} catch ( error ) {
1519
1534
// Log the sendMessage error, but return successful opt out creation
@@ -1526,16 +1541,10 @@ const rootMutations = {
1526
1541
. whereIn ( "id" , addedTagIds )
1527
1542
. pluck ( "webhook_url" )
1528
1543
. then ( urls => urls . filter ( url => url . length > 0 ) ) ;
1529
- await notifyOnTagConversation ( campaignContactId , user . id , webhookUrls ) ;
1530
1544
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 ) ;
1537
1546
1538
- if ( newlyAssignedTagsThatShouldUnassign . length > 0 ) {
1547
+ if ( currentlyEscalating ) {
1539
1548
await r
1540
1549
. knex ( "campaign_contact" )
1541
1550
. update ( { assignment_id : null } )
0 commit comments