Skip to content

Commit 361e16f

Browse files
Basic introduction to opting out a contact in VAN when manually opted out by the texter.
Runs similar to the proposed ngp-optout message handler. May need to add additional checks to ensure that the contact has a vanid
1 parent 715ab46 commit 361e16f

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/server/api/schema.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import _ from "lodash";
66
import { gzip, makeTree, getHighestRole } from "../../lib";
77
import { capitalizeWord, groupCannedResponses } from "./lib/utils";
88
import httpRequest from "../lib/http-request";
9-
import ownedPhoneNumber from "./lib/owned-phone-number";
109

1110
import { getIngestMethod } from "../../extensions/contact-loaders";
1211
import {
@@ -82,6 +81,7 @@ import { Jobs } from "../../workers/job-processes";
8281
import { Tasks } from "../../workers/tasks";
8382

8483
const 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

Comments
 (0)