From 26a45ad1bab200a72e50a7b7c8973b8506939b0c Mon Sep 17 00:00:00 2001 From: kchresfield Date: Thu, 19 Dec 2024 13:42:38 -0800 Subject: [PATCH] Updating README and function files to include comments and deployment instructions --- blocklist-call/README.md | 46 ++++++++++++++++++- .../functions/blocklist-call.protected.js | 18 ++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/blocklist-call/README.md b/blocklist-call/README.md index c4f837b6..9f7c5ab1 100644 --- a/blocklist-call/README.md +++ b/blocklist-call/README.md @@ -12,4 +12,48 @@ This Function expects one environment variable to be set. ### Parameters -This Function expects the incoming request to be a voice webhook. The parameters that will be used are `From` and `blocklist`. +This Function expects the incoming request to be a [voice webhook](https://www.twilio.com/docs/voice/api/call-resource?code-sample=code-fetch-a-call-resource&code-language=Node.js&code-sdk-version=3.x). The parameters that will be used are `From` and `blocklist`. + +## Create a new project with the template + +1. Install the [Twilio CLI](https://www.twilio.com/docs/twilio-cli/quickstart#install-twilio-cli) +2. Install the [serverless toolkit](https://www.twilio.com/docs/labs/serverless-toolkit/getting-started) + +```shell +twilio plugins:install @twilio-labs/plugin-serverless +``` + +3. Initiate a new project +``` +twilio serverless:init blocklist-call --template=blocklist-call && cd blocklist-call +``` + +4. Add your environment variables to `.env`: + +Make sure variables are populated in your `.env` file. See [Environment variables](#environment-variables). + +5. Start the server : + +``` +twilio serverless:start +``` + +5. Open the web page at https://localhost:3000/index.html and enter the required fields to send a challenge + +ℹ️ Check the developer console and terminal for any errors, make sure you've set your environment variables. + + +## Deploying + +Deploy your functions and assets with either of the following commands. Note: you must run these commands from inside your project folder. [More details in the docs.](https://www.twilio.com/docs/labs/serverless-toolkit) + +With the [Twilio CLI](https://www.twilio.com/docs/twilio-cli/quickstart): + +``` +twilio serverless:deploy +``` + +Connect your Twilio phone number to your callback URL: +Replace the phone number with your Twilio Number and the voice-url with your deployed URL. You can also do this in the console settings page for the phone number. + +twilio api:core:phone-numbers:update +11111111111 --voice-url https://YOUR_URL_HERE/twil.io/blocklist-call \ No newline at end of file diff --git a/blocklist-call/functions/blocklist-call.protected.js b/blocklist-call/functions/blocklist-call.protected.js index 3e649a84..273a9816 100644 --- a/blocklist-call/functions/blocklist-call.protected.js +++ b/blocklist-call/functions/blocklist-call.protected.js @@ -1,3 +1,21 @@ +/* + * Reject Calls with Blocklist + * + * Description: Block inbound calls from specific, individual numbers. + * + * Contents: + * 1. Main Handler + */ + +/* + * 1. Main Handler + * + * This is the entry point to the function. The function expects the incoming request to be a voice webhook. + * When an incoming call is made, the code detects the incoming phone number and compares it to the list of blocked numbers specified in /.env + * If the call is from a blocked phone number, the call is rejected and the call ends for the caller. + * If the incoming call is not on the blocked list, the call is accepted and the script will redirect to another URL for TwiML. + */ + exports.handler = function (context, event, callback) { const blocklist = event.blocklist || context.BLOCKLIST || ''; const blocklistArray = blocklist