@@ -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,35 @@ 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+ console . log (
1349+ "createOptOut VAN"
1350+ ) ;
1351+
1352+ const body = {
1353+ "canvassContext" : {
1354+ "inputTypeId" : 11 ,
1355+ "phone" : {
1356+ "dialingPrefix" : "1" ,
1357+ "phoneNumber" : contact . cell ,
1358+ "smsOptInStatus" : "O"
1359+ }
1360+ } ,
1361+ "resultCodeId" : 205
1362+ }
1363+
1364+ try {
1365+ // I am assuming here that contact has vanID.
1366+ // will need to test
1367+ await Van . postCanvassResponse ( contact , organization , body ) ;
1368+ console . log ( `canvasOptOut VAN success ${ contact } ` )
1369+ } catch ( e ) {
1370+ console . log ( `Error opting out ${ contact . cell } : ${ e } ` ) ;
1371+ } finally {
1372+ return newContact ;
1373+ }
13461374 } ,
13471375 deleteQuestionResponses : async (
13481376 _ ,
0 commit comments