Twilio Segment Personas + Twilio Flex: Bringing Personalization to the Contact Center

Say goodbye to long customer support wait times and lengthy back-and-forth with Segment Personas and Twilio Flex.

By Tim French

Twilio Segment Personas is now part of Segment’s Twilio Engage product offering.

It’s no mystery that customer expectations are at an all-time high today and that companies that execute real-time personalization strategies delight customers, increase conversion rates, and build brand loyalty.  

Still, delivering thoughtful, personalized experiences in real-time remains a dream for most companies. It’s a difficult concept to successfully execute and there aren’t (yet) a plethora of off-the-shelf solutions available to help.

This is especially true in the world of customer support. Many, if not most, consumers have likely experienced long wait times and lengthy back-and-forth making sure support agents have the right information to help. It’s frustrating for customers and agents alike.

With Twilio Flex and Segment Personas, you have all the building blocks you need to implement a next-generation, hyper-personalized contact center. Agents can instantly view a customer’s engagement history across channels and quickly address the customer’s needs. Consumers can look forward to a fast, efficient service.

In this recipe, we’ll walk through integrating Segment’s Personas Profile API with Twilio Flex, and also provide you a template that you can further customize according to your business needs.

Step 1:  Set up Segment Personas 

If you are new to Segment, you can request a demo or sign-up for a new workspace.

If you are an existing customer of Segment, login to your workspace, navigate to the Explorer tab in the Personas module. Click on a profile to see the full view of the customer’s Computed Traits, Audience Membership information, Event history, and Identity Graph. All of this data is available via the Profile API, so you can get a sense of the type of information we’ll be able to load into our Flex instance!

Make sure that you take note of the space ID from the Personas API console; you will need this value later on in the recipe when setting up the Twilio Function.

Twilio Flex & Segment Personas

Step 2: Set up Twilio Flex

Next, make sure that you have an instance of Twilio Flex ready to go. You can sign up for a free instance here. The Flex documentation provides a step-by-step guide for setting up a Flex instance if you don’t have one yet.

Twilio Flex & Segment Personas 2

Step 3: Create a Twilio Function to call the Segment Profile API

Time to integrate Segment and Twilio together!

  • Generate a Segment Profile API Token: If you haven’t already, generate an API token for Segment’s Profile API.  Instructions for creating a token can be found here.

  • Set up your Twilio Function: In order to make Personas data available in Flex, we are going to fetch the user data by deploying a Twilio Function. Create a new function and give it a name like `/fetch-data`.

With our Segment Profile API token handy and our Twilio Function environment set up, you’re ready to fetch behavioral data from Segment Personas.

Now edit your `fetch-data` Twilio Function to make the API request. You may simply copy the code below, and edit it according to your needs. Make sure you’ve saved your API token and spaceID as Environment Variables Twilio’s Functions environment.

const axios = require('axios');

exports.handler = function(context, event, callback) {
  const profile = axios.create({
    baseURL: `${context.spaceId}/collections/users/profiles`,
    auth: {
      username: context.token,
      password: '',
    .then((response) => {
      return callback(null,;
    .catch((error) => {
      return callback(error);

💡 You may also copy the code from a sample code snippet gist or your Twilio function to fetch user data from Segment.

Step 4: Invoke the Function from your Flex environment

Save your Function and hit “Deploy All”. Congrats! You have a live Twilio Function. 

Next, you will call it to load data into your Flex Plugin. You may copy and paste the below code into your Flex plugin.

***Please note that you will need to update the URL on line 10 with the URL from your own Twilio Function. You can find the URL for your Twilio Function by clicking the options button and choosing “Copy URL”.

const PLUGIN_NAME = 'PersonasPlugin';

export default class PersonasPlugin extends FlexPlugin {
  constructor() {

  init(flex, manager) {
      .then((response) => {
      .catch((error) => {

💡You may also use this sample code snippet to load user data into your Flex plugin.

Step 5: Surface customer data to your Customer Support agents

At this point, you’ve brought the data from Segment’s User Explorer (that you viewed in Step 1) full circle and into your Twilio Flex Contact Center.

With Personas data loaded into Flex, contact center agents now have a complete view of the customer available at their fingertips.

segment personas and twilio flex

Agents will now be able to:

  • Quickly identify that the customer hasn’t yet viewed an important piece of documentation, and can seamlessly point them to the right material, in real-time.

  • See the customer’s LTV, purchase history, and intelligently route their request using this information.

  • Understand where customers are stuck in their journey and provide fast, targeted support in response

Wrapping up

To recap, here’s what we learned to accomplish:

  • Used the Segment Profile API to create a single view of your customer behavior

  • Used Twilio Functions to query customer data in real-time from Segment’s Profile API

  • Built a Flex Plugin to enrich your Cloud Contact Center with real-time customer data.

If you are interested in trying this out, feel free to sign up for a Segment account or speak to one of our product specialists by requesting a demo

The state of personalization 2023

The State of Personalization 2023

Our annual look at how attitudes, preferences, and experiences with personalization have evolved over the past year.

Recommended articles


Want to keep updated on Segment launches, events, and updates?