This repository contains the code for a Twilio Flex plugin for displaying a real-time call sentiment indicator for supervisors in the Flex UI.
The sentiment indicator is displayed to the right of the TaskCard component for each Voice task. Green, yellow and red is used to indicate positive,neutral and negative sentiment, respectively. The below screenshot shows a voice task with positive sentiment:
The solution consists of the following building blocks:
- Twilio Flex Plugin (live-sentiment-plugin): for streaming call audio and displaying the live sentiment indicator for supervisors in the Flex Teams View.
- Twilio Functions (live-sentiment-functions): used as middleware for updating calls for streaming, and for obtaining the token for connecting to Twilio Sync.
- Cloudflare Workers (live-sentiment-worker): used as the destination for call streams. The worker forwards the audio to Deepgram for transcription and uses Workers AI for detecting sentiment from the transcript. Finally, it publishes the result to a Twilio Sync stream.
- Deepgram: used for transcribing call audio.
- Twilio Sync stream: pub/sub service for publishing and delivering the results of the sentiment analysis.
- Create Sync service:
- This can be done using the Twilio Console, under Sync > Services > Create new Sync service.
- Deploy Twilio functions:
- Navigate to the functions directory:
cd live-sentiment-functions - Install the Twilio Serverless Toolkit.
- Rename
.env.exampleto.env, and set the values of environment variables as follows:ACCOUNT_SID: your Twilio account SIDAUTH_TOKEN: your Twilio auth tokenAPI_KEY: your Twilio API keyAPI_SECRET: your Twilio API secretSYNC_SERVICE_SID: SID of the Sync service from step 1.SYNC_TOKEN_IDENTITY: hard-to-guess, arbitrary string. Used as the Sync access token's identity and for accessing the function for fetching the Sync token.
- Deploy the functions using
npm run deploy.
- Navigate to the functions directory:
- Deploy Cloudflare worker:
- Navigate to the worker directory:
cd live-sentiment-worker. - Install dependencies via
npm install. - Deploy the worker using
npm run deploy. - Add the following secrets to your worker:
DEEPGRAM_API_KEY: your Deepgram API key.SYNC_TOKEN_IDENTITY: identity string from step 2.SYNC_TOKEN_URL: full URL of the deployed/tokenTwilio function from step 2.
- Navigate to the worker directory:
- Re-deploy Twilio functions:
- Navigate to the functions directory:
cd live-sentiment-functions - Update the
.envfile and setSTREAM_URLto the websocket URL of the Cloudflare worker from step 3. - Re-deploy the functions using
npm run deploy.
- Navigate to the functions directory:
- Deploy Flex plugin:
- Navigate to the plugin directory:
cd live-sentiment-plugin. - Install the Flex Plugins CLI.
- Rename
.env.exampleto.env, and set the values of environment variables as follows:FLEX_APP_FUNCTIONS_URL: base URL of Twilio functions from step 2.FLEX_APP_SYNC_TOKEN_IDENTITY: identity string from step 2.
- Deploy the plugin using the
twilio flex:plugins:deploycommand.
- Navigate to the plugin directory:
Thanks for reading this far!
If you have any questions, do not hesitate to reach out at hello@slintab.dev

