Skip to content

Commit

Permalink
After some brief testing, there were some bad assumptions made about …
Browse files Browse the repository at this point in the history
…how to update a users opt in status.

Result code id changed from 205 to 130 (Do not text result code).
Cell is checked later down the call chain, so don't need to worry here.
customFields >> custom_fields.
Test is updated to reflect these changes.
  • Loading branch information
engelhartrueben committed Dec 10, 2024
1 parent c76587f commit 7d0bbf4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
10 changes: 5 additions & 5 deletions __test__/extensions/message-handlers/ngpvan-optout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ describe("extensions.message-handlers.ngpvan-optout", () => {

contact = {
message_status: "needsMessage",
customFields: '{"vanid": 12345}',
cell: "(123)-456-7891"
custom_fields: '{"vanid": 12345}',
cell: "123-456-7891"
};

organization = {
Expand All @@ -39,11 +39,11 @@ describe("extensions.message-handlers.ngpvan-optout", () => {
"inputTypeId": 11, // API input
"phone": {
"dialingPrefix": "1",
"phoneNumber": "1234567891",
"phoneNumber": "123-456-7891",
"smsOptInStatus": "O" // opt out status
}
},
"resultCodeId": 205
"resultCodeId": 130
};

jest.spyOn(Config, "getConfig").mockReturnValue(undefined);
Expand Down Expand Up @@ -102,7 +102,7 @@ describe("extensions.message-handlers.ngpvan-optout", () => {
beforeEach(async () => {
contact = {
...contact,
customFields: '{}'
custom_fields: '{}'
};
});

Expand Down
9 changes: 3 additions & 6 deletions src/extensions/message-handlers/ngpvan-optout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,25 @@ export const postMessageSave = async ({
// we don't want to call that function every time if a vanid
// was never provided in the first place. Example: CSV
try {
customField = JSON.parse(contact.customFields);
customField = JSON.parse(contact.custom_fields);
vanId = customField.VanID || customField.vanid;
if (!vanId) return {}
} catch (exception) {
console.log("message-handlers | ngpvan-optout ERROR", exception);
return {};
}

// Testing shows that "-" , "(", and ")" break this request
const cell = contact.cell.replace(/\D/g,'')

// https://docs.ngpvan.com/reference/peoplevanidcanvassresponses
const body = {
"canvassContext": {
"inputTypeId": 11, // API input
"phone": {
"dialingPrefix": "1",
"phoneNumber": cell,
"phoneNumber": contact.cell,
"smsOptInStatus": "O" // opt out status
}
},
"resultCodeId": 205
"resultCodeId": 130 // Do Not Text result code
};

return Van.postCanvassResponse(contact, organization, body)
Expand Down

0 comments on commit 7d0bbf4

Please sign in to comment.