Skip to content
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
63 changes: 63 additions & 0 deletions env-variables.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
"contentKey": null
}
],
"send-receive-sms-messages": [],
"stripe-payment-link-sms": [
{
"key": "STRIPE_SECRET_KEY",
Expand Down Expand Up @@ -1949,6 +1950,68 @@
"configurable": true,
"contentKey": null
}
],
"sms-spam-scam-filter": [
{
"key": "OPENAI_API_KEY",
"required": true,
"format": "secret",
"description": "API key used to call OpenAI for SMS spam and scam classification",
"link": null,
"default": null,
"configurable": true,
"contentKey": null
},
{
"key": "OPENAI_MODEL",
"required": false,
"format": "text",
"description": "OpenAI model used for SMS classification",
"link": null,
"default": "gpt-5.6-luna",
"configurable": true,
"contentKey": null
},
{
"key": "FORWARD_WEBHOOK_URL",
"required": true,
"format": "url",
"description": "Webhook URL that should receive inbound SMS requests classified as genuine",
"link": null,
"default": null,
"configurable": true,
"contentKey": null
},
{
"key": "FORWARD_WEBHOOK_METHOD",
"required": false,
"format": "text",
"description": "HTTP method used when redirecting genuine SMS requests to the forwarding webhook",
"link": null,
"default": "POST",
"configurable": true,
"contentKey": null
},
{
"key": "OPENAI_TIMEOUT_MS",
"required": false,
"format": "number",
"description": "Timeout in milliseconds for OpenAI classification requests",
"link": null,
"default": "7000",
"configurable": true,
"contentKey": null
},
{
"key": "TWILIO_SMS_WEBHOOK_URL",
"required": true,
"format": "text",
"description": "The path to the webhook",
"link": null,
"default": "/sms-spam-scam-filter",
"configurable": false,
"contentKey": null
}
]
}
}
58 changes: 57 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
"ai-assistants-samples",
"mcp-server",
"email-events-sms",
"send-receive-sms-messages"
"send-receive-sms-messages",
"sms-spam-scam-filter"
]
}
1 change: 1 addition & 0 deletions sms-spam-scam-filter/.owners
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
danohn
9 changes: 9 additions & 0 deletions sms-spam-scam-filter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

## [Unreleased]

## [1.0.0]

### Added

- Initial release.
93 changes: 93 additions & 0 deletions sms-spam-scam-filter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# SMS Spam and Scam Filter

This application filters inbound SMS messages before they reach your downstream webhook. Incoming messages are classified with OpenAI as either `spam_scam` or `genuine`. Spam and scam messages are ignored with an empty TwiML response. Genuine messages are redirected to your webhook with TwiML `<Redirect>`.

## Pre-requisites

- A [Twilio account](https://www.twilio.com/try-twilio) with an active phone number that can receive SMS
- An OpenAI API key
- A webhook URL that should receive genuine inbound SMS requests

### Environment variables

`.env` is included with placeholder values. Update the values before running. Never commit real secrets in `.env`.

| Variable | Description | Required |
| :------- | :---------- | :------- |
| `OPENAI_API_KEY` | API key used to call OpenAI for SMS spam and scam classification | Yes |
| `OPENAI_MODEL` | OpenAI model used for SMS classification. Defaults to `gpt-5.6-luna` | No |
| `FORWARD_WEBHOOK_URL` | Webhook URL that should receive inbound SMS requests classified as genuine | Yes |
| `FORWARD_WEBHOOK_METHOD` | HTTP method used when redirecting genuine SMS requests. Defaults to `POST` | No |
| `OPENAI_TIMEOUT_MS` | Timeout in milliseconds for OpenAI classification requests. Defaults to `7000` | No |
| `TWILIO_SMS_WEBHOOK_URL` | The webhook path — pre-set to `/sms-spam-scam-filter`, do not change | Yes |

## Running the project

1. Install the [Twilio CLI](https://www.twilio.com/docs/twilio-cli/quickstart#install-twilio-cli)
1. Install the [serverless toolkit](https://www.twilio.com/docs/labs/serverless-toolkit/getting-started)

```shell
twilio plugins:install @twilio-labs/plugin-serverless
```

1. Initialize the project from the template

```shell
twilio serverless:init example --template=sms-spam-scam-filter --skip-credentials && cd example
```

1. Edit `.env` and set `OPENAI_API_KEY` and `FORWARD_WEBHOOK_URL`
1. Start the server

```shell
twilio serverless:start
```

Check the developer console and terminal for any errors, and make sure you've set your environment variables.

### Configuring your Twilio phone number

You can configure the webhook via the Twilio CLI (recommended) or the Console.

**Via CLI:**

Find your phone number SID:

```shell
twilio api:core:incoming-phone-numbers:list
```

Then update the SMS webhook:

```shell
twilio api:core:incoming-phone-numbers:update \
--sid <your-phone-number-sid> \
--sms-url https://<your-ngrok-id>.ngrok.app/sms-spam-scam-filter \
--sms-method POST
```

**Via Console:**

1. Go to your [Twilio Console Phone Numbers](https://console.twilio.com/us1/develop/phone-numbers/manage/incoming)
2. Select the phone number you want to use
3. Under "Messaging Configuration":
- Set "A Message Comes In" to **Webhook**
- Enter your URL: `https://<your-ngrok-id>.ngrok.app/sms-spam-scam-filter` (or your deployed URL)
- Set HTTP method to **POST**
4. Click **Save**

## Cost estimate

This estimate covers only the OpenAI classification request. It does not include Twilio messaging, carrier, phone number, or webhook hosting costs.

Using `gpt-5.6-luna` pricing of `$0.20` per 1M input tokens and `$1.20` per 1M output tokens, a typical one-segment SMS classification costs about `$0.0001` per checked message.

## Deploying

Deploy your functions and assets with the following command. Note: you must run this command from inside your project folder. [More information about the serverless toolkit is available in the docs.](https://www.twilio.com/docs/labs/serverless-toolkit)

With the [Twilio CLI](https://www.twilio.com/docs/twilio-cli/quickstart):

```shell
twilio serverless:deploy --service-name sms-spam-scam-filter
```
Loading