Skip to content

Commit

Permalink
add findByPhoneNumber function so we can query VAN for persons with a…
Browse files Browse the repository at this point in the history
… specified phone number
  • Loading branch information
engelhartrueben committed Nov 13, 2024
1 parent 715ab46 commit 8da6526
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/extensions/action-handlers/ngpvan-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,28 @@ export const postCanvassResponse = async (contact, organization, bodyInput) => {
});
};

// Queries VAN on a specific phone number, returning information on
// the owner.
// NOTE: VAN has a limit of 10 queries per second:
// https://docs.ngpvan.com/docs/limitations-and-warnings#billing-and-usage
export async function findByPhoneNumber( phoneNumber, organization ) {

const url = Van.makeUrl("v4/people/findByPhone", organization);

return httpRequest(url, {
method: "POST",
retries: 0, // could we do more?
timeout: Van.getNgpVanTimeout(organization),
headers: {
Authorization: await Van.getAuth(organization),
"Content-Type": "application/json"
},
body: `{ "phoneNumber": "${phoneNumber}" }`,
validStatuses: [204],
compess: false
});
}

// What happens when a texter saves the answer that triggers the action
// This is presumably the meat of the action
export async function processAction({ actionObject, contact, organization }) {
Expand Down

0 comments on commit 8da6526

Please sign in to comment.