File tree Expand file tree Collapse file tree 2 files changed +20
-14
lines changed
extensions/message-handlers/ngpvan-optout Expand file tree Collapse file tree 2 files changed +20
-14
lines changed Original file line number Diff line number Diff line change @@ -28,24 +28,30 @@ export const available = organization =>
2828/* Sends a request to VAN to place an opt out tag to an individual.
2929 */
3030export const postMessageSave = async ( {
31- message ,
31+ _ , // message
3232 contact,
3333 handlerContext,
3434 organization
3535} ) => {
3636 if ( ! exports . available ( organization ) ) return { } ;
3737
38- // customFields is a JSON object
38+ let customField ;
39+ let vanId ;
40+
3941 // Checking for vanID in contact
42+ // While Van.postCanvassResponse will check the customFields,
43+ // we don't want to call that function every time if a vanid
44+ // was never provided in the first place. Example: CSV
4045 try {
41- const c = JSON . stringify ( contact . customFields ) ;
42- if ( c ?. VanID === undefined ) return { }
46+ customField = JSON . parse ( contact . customFields ) ;
47+ vanId = customField . VanID || customField . vanid ;
48+ if ( ! vanId ) return { }
4349 } catch ( exception ) {
4450 console . log ( "message-handlers | ngpvan-optout ERROR" , exception ) ;
51+ return { } ;
4552 }
4653
4754 if (
48- message . is_from_contact ||
4955 ! contact ||
5056 ! handlerContext . autoOptOutReason
5157 ) return { } ;
Original file line number Diff line number Diff line change @@ -1348,8 +1348,9 @@ const rootMutations = {
13481348 // Checking that contact contains a vanId
13491349 // If not, return and skip next steps
13501350 try {
1351- const c = JSON . stringify ( contact . customFiels ) ;
1352- if ( c ?. VanID === undefined ) return newContact ;
1351+ const c = JSON . parse ( contact . customFields ) ;
1352+ const vanId = c . VanId || c . vanid
1353+ if ( ! vanId ) return newContact ;
13531354 } catch ( exception ) {
13541355 console . log ( exception ) ;
13551356 return newContact ;
@@ -1359,25 +1360,24 @@ const rootMutations = {
13591360 `createOptOut VAN ${ contact . cell } `
13601361 ) ;
13611362
1363+ const cell = contact . cell . replace ( / \D / g, '' ) ;
1364+
13621365 const body = {
13631366 "canvassContext" : {
1364- "inputTypeId" : 11 ,
1367+ "inputTypeId" : 11 , // API Input
13651368 "phone" : {
13661369 "dialingPrefix" : "1" ,
1367- "phoneNumber" : contact . cell ,
1368- "smsOptInStatus" : "O"
1370+ "phoneNumber" : cell ,
1371+ "smsOptInStatus" : "O" // opt out status
13691372 }
13701373 } ,
13711374 "resultCodeId" : 205
13721375 } ;
13731376
13741377 try {
1375- // I am assuming here that contact has vanID.
1376- // will need to test
13771378 await Van . postCanvassResponse ( contact , organization , body ) ;
1378- console . log ( `canvasOptOut VAN success ${ contact . cell } ` )
13791379 } catch ( e ) {
1380- console . log ( `Error opting out ${ contact . cell } : ${ e } ` ) ;
1380+ console . log ( `Error manually opting out ${ contact . cell } : ${ e } ` ) ;
13811381 } finally {
13821382 return newContact ;
13831383 }
You can’t perform that action at this time.
0 commit comments