@@ -6,7 +6,6 @@ import _ from "lodash";
66import { gzip , makeTree , getHighestRole } from "../../lib" ;
77import { capitalizeWord , groupCannedResponses } from "./lib/utils" ;
88import httpRequest from "../lib/http-request" ;
9- import ownedPhoneNumber from "./lib/owned-phone-number" ;
109
1110import { getIngestMethod } from "../../extensions/contact-loaders" ;
1211import {
@@ -82,6 +81,7 @@ import { Jobs } from "../../workers/job-processes";
8281import { Tasks } from "../../workers/tasks" ;
8382
8483const uuidv4 = require ( "uuid" ) . v4 ;
84+ const Van = require ( "../../extensions/action-handlers/ngpvan-action.js" ) ;
8585
8686// This function determines whether a field was requested
8787// in a graphql query. Each graphql resolver receives a fourth parameter,
@@ -1292,7 +1292,7 @@ const rootMutations = {
12921292 }
12931293 }
12941294 return finalContacts ;
1295- } ,
1295+ } , //
12961296 createOptOut : async (
12971297 _ ,
12981298 { optOut, campaignContactId, noReply } ,
@@ -1342,7 +1342,45 @@ const rootMutations = {
13421342 const newContact = cacheableData . campaignContact . updateCacheForOptOut (
13431343 contact
13441344 ) ;
1345- return newContact ;
1345+
1346+ if ( ! await Van . available ( organization ) ) return newContact ;
1347+
1348+ // Checking that contact contains a vanId
1349+ // If not, return and skip next steps
1350+ try {
1351+ const c = JSON . stringify ( contact . customFiels ) ;
1352+ if ( c ?. VanID === undefined ) return newContact ;
1353+ } catch ( exception ) {
1354+ console . log ( exception ) ;
1355+ return newContact ;
1356+ }
1357+
1358+ console . log (
1359+ `createOptOut VAN ${ contact . cell } `
1360+ ) ;
1361+
1362+ const body = {
1363+ "canvassContext" : {
1364+ "inputTypeId" : 11 ,
1365+ "phone" : {
1366+ "dialingPrefix" : "1" ,
1367+ "phoneNumber" : contact . cell ,
1368+ "smsOptInStatus" : "O"
1369+ }
1370+ } ,
1371+ "resultCodeId" : 205
1372+ } ;
1373+
1374+ try {
1375+ // I am assuming here that contact has vanID.
1376+ // will need to test
1377+ await Van . postCanvassResponse ( contact , organization , body ) ;
1378+ console . log ( `canvasOptOut VAN success ${ contact . cell } ` )
1379+ } catch ( e ) {
1380+ console . log ( `Error opting out ${ contact . cell } : ${ e } ` ) ;
1381+ } finally {
1382+ return newContact ;
1383+ }
13461384 } ,
13471385 deleteQuestionResponses : async (
13481386 _ ,
0 commit comments