TwilioVerify Data Connector

The TwilioVerify Data Connector allows you to add message-based verification via one-time codes.

Constructor

TwilioVerify(sid, authToken) → {object}

The Twilio Verify Data Connector extends the functionality of the Twilio Data Connector.

We recommend that you create a Data Connector Configuration called "Twilio" via the Verj.io Runtime Environment's Administration Application.

A TwilioVerify Data Connector is then available at connectors.verjio.twilio.verify using that configuration.

If you are unable to do that, you may use this constructor to create a new TwilioVerify Data Connector.

This method accepts an Account SID and an Auth Token.

Parameters:
Name Type Description
sid string

Twilio Account SID.

authToken string

Auth Token used to authenticate API requests.

Returns:
object

The Data Connector.

Functions

checkToken(serviceId, toopt, code, paramsopt) → (nullable) {object}

Checks the user-provided verification token (code) matches the one sent.

Parameters:
Name Type Attributes Description
serviceId string  

Service SID of the verification service to use.

to string <optional>

Recipient phone number or email address. Phone numbers must be in E.164 format. Can be omitted if a VerificationSid parameter is provided.

code string  

The verification token (code) to check.

params object <optional>

Optional parameters to include.

See:
Throws:
HttpNotFoundError

Thrown when the verification has expired or has already been completed.

Returns:
object

Details of the verification. Returns null if one or more parameters are invalid.

Examples:
// Check the user-provided verification code
const status = connectors.verjio.twilio.verify.checkToken(
  fields.service_sid.value,
  fields.phone_number.value,
  fields.code.value
)

// If the code was correct, the status will be `approved`
if (status === connectors.verjio.twilio.verify.status.APPROVED) {
  form.gotoPage('SignedIn');
}
// Send a code to the user's phone
const verification = connectors.verjio.twilio.verify.sendToken(
  fields.service_sid.value,
  fields.phone_number.value
);

// Wait for user to provide code

// Check the code using the verification SID
// rather than the user's details 
connectors.verjio.twilio.verify.checkToken(
  fields.service_sid.value,
  null,
  fields.code.value,
  {
    VerificationSid: verification.sid
  }
);

createService(name, codeLengthopt, paramsopt) → (nullable) {object}

Create a new verification service. All verification requests must be made using a verification service.

Parameters:
Name Type Attributes Default Description
name string    

Friendly name of the verification service. This may be visible to users. The name must be 30 characters or less and can only contain letters, numbers, spaces, dashes and underscores.

codeLength integer <optional> 4

Length of the verification codes to send. Values between 4 and 10 (inclusive) are accepted. Defaults to 4.

params object <optional>  

Optional parameters to include.

See:
Returns:
object

Details of the new verification service. Returns null if one or more parameters are invalid.

Example:
// Create a new verification service
// Verification codes will be 5 characters long.
const service = connectors.verjio.twilio.verify.createService(
  'Sandy\'s Ice Cream',
  5
);

// Save the SID
if (service) {
  fields.service_sid.value = service.sid;
}

handleError(response)

Checks an API response for errors. If an error is encountered, the appropriate Error is thrown.

Parameters:
Name Type Description
response object

The response from a services.rest request.

Throws:
  • HttpAuthorisationError

    Thrown when an incorrect SID or token are used.

  • HttpNotFoundError

    Thrown when the requested resource is not available.

  • HttpRequestError

    Thrown when a request is malformed or required parameters are not supplied. See the error message for more details.

  • HttpUnknownError

    Thrown when an unhandled error is encountered.

sendToken(serviceId, to, channelopt, paramsopt) → (nullable) {object}

Send a verification token (code) to the specified recipient. The token can be sent using several channels.

Parameters:
Name Type Attributes Default Description
serviceId string    

Service SID of the verification service to use.

to string    

Recipient phone number or email address. Phone numbers must be in E.164 format

channel TwilioVerify.Channel <optional> sms

Length of the verification codes to send. Values between 4 and 10 (inclusive) are accepted. Defaults to 4.

params object <optional>  

Optional parameters to include.

See:
Returns:
object

Details of the verification. Returns null if one or more parameters are invalid.

Example:
// Send a verification code
connectors.verjio.twilio.verify.sendToken(
  fields.service_sid.value,
  fields.phone_number.value
);

Type definitions

Channel

Constants used to identify messaging channels.

These can be accessed via connectors.verjio.twilio.verify.channel.

Status

Constants used to identify verification status.

These can be accessed via connectors.verjio.twilio.verify.status.