Twilio Segment Demo Integration
This document outlines a possible example of how to integrate SheerID into a Twilio Segment project.
Overview
This is a lightweight demo showcasing the ease of using SheerID verification data as a Twilio Segment data source. This demo is not meant to give a feature-complete solution integrating SheerID verification into an existing Twilio Segment project, but to give ideas on how to approach the task and raise questions.
Ways to integrate with SheerID
There are at least three scenarios:
- Give code to the consumer on success / Send code to the consumer via email.
- Apply code to shopping session (visible or invisible).
- Send verified signal to the merchant and use the verified status freely.
The demo is implementing the third scenario. The first scenario is the easiest to implement, but the consumer needs to enter the code manually.
The second scenario is the most complex to implement from the frontend perspective, but the consumer does not need to enter the code manually.
The third scenario is giving the most freedom, as it can be used to implement integration with any third-party systems and there is no limitation on how the verified customer data can be utilized, stored and reused.
Demo Application
The demo is a simple node.js-based Express server, accepting requests from the webhooks from SheerID verification API.
The demo application’s code is publicly available on the SheerID github: https://github.com/sheerid/integration-demos/tree/main/segment-demo
Endpoints
Endpoints used in the current demo:
/api/success-webhook
endpoint receiving SheerID verification webhook.
SheerID API
The demo application is using SheerID API and webhooks. The demo is using a SheerID program in test mode, so no real verification is done, but the verification process is fully functional. See more about how to test your program here.
Requirements
Running this example requires:
- A Twilio Segment account with a data source that has a valid write key. See this guide for more information on adding sources.
- A SheerID account.
- Computer with Node.js v18 or higher.
Installation
Preparation, this process does not install anything outside of the cloned folder.
- Clone the repository to your local machine.
- Run
npm install
to install the dependencies.
Running the Application
How to use:
- Create a data source in your Twilio Segment workspace. Make note of the write key for the source.
- The data source does not need a destination, the debugger can be used to track events.
- Log in to your MySheerID Dashboard
- Create a SheerID program, that you will use e.g. “Student discount”.
- Configure your program with eligibility, theme etc.
- Set the Codes section to “No Code”.
- In Program Settings:
- Set Webhook for eligible verification to
https://<your_server_address>/api/success-webhook
. - Add userId as a required Metadata Tracking Field. See this page for more information about tracking custom metadata.
- Set Webhook for eligible verification to
- Copy the access token from Settings > Access Tokens page.
- Copy
.env.example
to a new.env
file, and add relevant information about your setup, for example:
WRITE_KEY=<Your Twilio Segment Write Key>
PORT=3000
SHEERID_TOKEN=<Your Copied SheerID Access Token>
SHEERID_API_URL=https://services.sheerid.com/rest/v2/
- Run
npm start
to run the application.
Further Reading, Links
https://github.com/sheerid/integration-demos/tree/main/segment-demo