Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating README and function files to include comments and deployment… #584

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion blocklist-call/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions blocklist-call/functions/blocklist-call.protected.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down