Skip to content

Commit 8da6526

Browse files
add findByPhoneNumber function so we can query VAN for persons with a specified phone number
1 parent 715ab46 commit 8da6526

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/extensions/action-handlers/ngpvan-action.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,28 @@ export const postCanvassResponse = async (contact, organization, bodyInput) => {
102102
});
103103
};
104104

105+
// Queries VAN on a specific phone number, returning information on
106+
// the owner.
107+
// NOTE: VAN has a limit of 10 queries per second:
108+
// https://docs.ngpvan.com/docs/limitations-and-warnings#billing-and-usage
109+
export async function findByPhoneNumber( phoneNumber, organization ) {
110+
111+
const url = Van.makeUrl("v4/people/findByPhone", organization);
112+
113+
return httpRequest(url, {
114+
method: "POST",
115+
retries: 0, // could we do more?
116+
timeout: Van.getNgpVanTimeout(organization),
117+
headers: {
118+
Authorization: await Van.getAuth(organization),
119+
"Content-Type": "application/json"
120+
},
121+
body: `{ "phoneNumber": "${phoneNumber}" }`,
122+
validStatuses: [204],
123+
compess: false
124+
});
125+
}
126+
105127
// What happens when a texter saves the answer that triggers the action
106128
// This is presumably the meat of the action
107129
export async function processAction({ actionObject, contact, organization }) {

0 commit comments

Comments
 (0)