> ## Documentation Index
> Fetch the complete documentation index at: https://docs-staging.auth0-mintlify.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Configure a Custom Phone Provider with Twilio Verify

> Use a custom-phone-provider Action to integrate Twilio Verify into Auth0 and route MFA and passwordless SMS codes through the Twilio Verify API.

**1. Prerequisites**

* You must have a [Twilio](https://twilio.com/) account with a valid SMS and/or phone delivery option.

* You must create a [Twilio Verify](https://www.twilio.com/docs/verify) service through the [Twilio Console](https://www.twilio.com/console/verify/services) or the [Verify REST API](https://www.twilio.com/docs/verify/api/service#create-a-verification-service).

**2. Set up a custom phone message provider**

From [Dashboard > Branding > Phone Provider](https://manage.auth0.com/dashboard/#/phone/templates/phone/provider), under **Phone Provider**, choose **Custom**.

Under **Provider Configuration**, add the following code sample to allow the Twilio API to send phone messages to a user's phone number:

```javascript lines expandable theme={null}
/**
* Handler to be executed while sending a phone notification
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {CustomPhoneProviderAPI} api - Methods and utilities to help change the behavior of sending a phone notification.
*/
exports.onExecuteCustomPhoneProvider = async (event, api) => {
 const { TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_VERIFY_SID } = event.secrets;

  const client = require('twilio')(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN);

  // map auth0 voice value to call
  const messageType = event.notification.delivery_method === 'voice' ? 'call' : 'sms';

  const { recipient, code } = event.notification;

  // add this to fix " 1333444999  "
  // "333 444 5555"
  const sanitizedNumber = recipient.replace(/\s/g, '').trim();

  await client.verify.v2.services(TWILIO_VERIFY_SID)
    .verifications.create({
      to: sanitizedNumber,
      channel: messageType,
      customCode: code
    })

};
```

**3. Add secrets**

Select the **Key** icon to open the **Secrets** menu. Add the following values from your Twilio Verify service setup:

* `TWILIO_ACCOUNT_SID`
* `TWILIO_AUTH_TOKEN`
* `TWILIO_VERIFY_SID`

**4. Load Twilio helper library**

Select the **Dependency** icon, then choose **Add Dependency**. In the **Add Dependency** window that opens, enter the following values:

* **Name**: `twilio`
* **Version**: `latest`

Select **Create** and Auth0 searches for the Twilio helper library and loads the latest version.

**5. Deploy and test**

Select **Save** to save and deploy the Action.

To test the custom phone provider configuration before using it in a production environment, select **Send Test Message**.
