Created
November 1, 2024 13:26
-
-
Save taf2/74c9583fe166d2b86440cfc8d7575f18 to your computer and use it in GitHub Desktop.
Using the PossibleNow API to filter who can be dialed or not based on Flags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://staging.dncsolution.com/Rest/Help | |
exports.handler = async (event, context) => { | |
const apihashkey = process.env['apihashkey']; | |
const clientid = process.env['clientid']; | |
const userid = process.env['userid']; | |
const profileid = process.env['profileid']; | |
const call = event.activity; // call, text, chat, form, video, fax, etc... | |
const url = `https://staging.dncsolution.com/Rest/${clientid}/Quickcheck/${userid}/${profileid}/${call.caller_number_bare}`; | |
// const url = `https://staging.dncsolution.com/Rest/${clientid}/Quickcheck/${userid}/${profileid}/3057604895`; | |
// const url = `https://staging.dncsolution.com/Rest/${clientid}/Quickcheck/${userid}/${profileid}/5550100489`; | |
console.log("check:", url); | |
const {request, response, data} = await context.http_get(url); | |
console.log("data:", data); | |
try { | |
const dnc = JSON.parse(data); | |
// sample response for a do not call | |
// data: Invalid AreaCode/Exchange "kkkk" passed in request | |
// data: {"TimeZone":"-4","CallCurfewWindow":{"Start":" ","End":" ","WithinCallCurfewWindow":"","WithinCallWindow":""}, | |
// "PhoneNumber":"yyy","Status":"DNC","Filters":[{"FilterName":"Florida","Flag":"FL1","IsWireless":false},{"FilterName":"Area Code Not Check","Flag":"ANC","IsWireless":false}]} | |
// sample should be safe to dial | |
// data: {"TimeZone":"-4","CallCurfewWindow":{"Start":" ","End":" ","WithinCallCurfewWindow":"","WithinCallWindow":""}, | |
// "PhoneNumber":"xyz","Status":"DNC","Filters":[{"FilterName":"Area Code Not Check","Flag":"ANC","IsWireless":false}]} | |
// data: {"TimeZone":"-4","CallCurfewWindow":{"Start":" ","End":" ","WithinCallCurfewWindow":"","WithinCallWindow":""}, | |
// "PhoneNumber":"nyz","Status":"DNC","Filters":[{"FilterName":"Wireless","Flag":"WIR","IsWireless":true}, | |
//. {"FilterName":"MARYLAND 410","Flag":"NMD","IsWireless":true}, | |
//. {"FilterName":"Maryland Wireless","Flag":"WMD","IsWireless":true}]} | |
// data: {"TimeZone":"-4","CallCurfewWindow":{"Start":" ","End":" ","WithinCallCurfewWindow":"","WithinCallWindow":""}, | |
// "PhoneNumber":"nnn","Status":"DNC","Filters":[{"FilterName":"Wireless","Flag":"WIR","IsWireless":true}, | |
//. {"FilterName":"Maryland Wireless","Flag":"WMD","IsWireless":true}]} | |
// const canDial = (dnc?.Status == 'DNC' || dnc?.Status == ''); | |
const noDialFlags = dnc?.Filters?.some( (filter) => { | |
return filter.Flag == 'NMD'; | |
}); | |
const canDial = !!noDialFlags.length; | |
context.done(null, {canDial}); | |
} catch (e) { | |
console.log("error verifying :", e.message) | |
context.done(null, {canDial:false}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment