├── .env
├── .gitignore
├── CHANGELOG.md
├── README.md
├── craco.config.js
├── package.json
├── public
├── assets
│ └── appConfig.sample.js
├── index.html
└── plugins.json
└── src
├── App.js
├── App.test.js
├── index.css
├── index.js
└── registerServiceWorker.js
/.env:
--------------------------------------------------------------------------------
1 | PORT=8080
2 | BROWSER=none
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 |
6 | # testing
7 | /coverage
8 |
9 | # production
10 | /build
11 |
12 | # misc
13 | .DS_Store
14 | .env.local
15 | .env.development.local
16 | .env.test.local
17 | .env.production.local
18 |
19 | npm-debug.log*
20 | yarn-debug.log*
21 | yarn-error.log*
22 |
23 | appConfig.js
24 | yarn.lock
25 | package-lock.json
26 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 | All notable changes to this project will be documented in this file.
3 |
4 | ## 0.14.0
5 | ### Changed
6 | - Consume @twilio/flex-ui@0.14.0
7 |
8 | ## 0.13.0
9 | ### Changed
10 | - Consume @twilio/flex-ui@0.13.0
11 |
12 | ## 0.12.0
13 | ### Changed
14 | - Consume @twilio/flex-ui@0.12.0
15 |
16 | ## 0.7.0
17 |
18 | ### Changed
19 | - Project bootstrapped with create-react-app and renamed to flex-ui-sample
20 | - Use @twilio/flex-ui@0.7.0
21 | ### Removed
22 | - Sample code
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Twilio Flex UI Sample
2 |
3 | This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app).
4 |
5 | **NOTE** This branch of Flex UI sample app is compatible with Flex UI version 2.0.0 and newer. For sample app compatible with Flex UI 1.x.x versions, use -[v1 branch](https://github.com/twilio/flex-ui-sample/tree/v1).
6 |
7 | You can find the most recent version of the guide on how to perform common tasks [here](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md).
8 |
9 | This package can only be consumed together with Twilio Flex. Visit http://twilio.com/flex to find out more.
10 |
11 | ## Instructions
12 |
13 | 1. Install all dependencies by running:
14 | ```
15 | npm install
16 | ```
17 | 2. Copy appConfig.sample.js in public/assets folder and configure accordingly to use your Twilio account
18 | ```
19 | cp public/assets/appConfig.sample.js public/assets/appConfig.js
20 | ```
21 | 3. Start Flex UI by running:
22 | ```
23 | npm start
24 | ```
25 |
--------------------------------------------------------------------------------
/craco.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | webpack: {
3 | configure: (config) => {
4 | const fileLoaderRule = getFileLoaderRule(config.module.rules);
5 | if (!fileLoaderRule) {
6 | throw new Error("File loader not found");
7 | }
8 | fileLoaderRule.exclude.push(/\.cjs$/);
9 |
10 | config.resolve.fallback = {
11 | path: false,
12 | };
13 |
14 | config.ignoreWarnings = [ignoreSourcemapsloaderWarnings];
15 |
16 | return config;
17 | },
18 | },
19 | };
20 |
21 | function getFileLoaderRule(rules) {
22 | for (const rule of rules) {
23 | if ("oneOf" in rule) {
24 | const found = getFileLoaderRule(rule.oneOf);
25 | if (found) {
26 | return found;
27 | }
28 | } else if (rule.test === undefined && rule.type === "asset/resource") {
29 | return rule;
30 | }
31 | }
32 | }
33 |
34 | /**
35 | *
36 | * @param {import('webpack').WebpackError} warning
37 | * @returns {boolean}
38 | */
39 | function ignoreSourcemapsloaderWarnings(warning) {
40 | return (
41 | warning.module &&
42 | warning.module.resource.includes("node_modules") &&
43 | warning.details &&
44 | warning.details.includes("source-map-loader")
45 | );
46 | }
47 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@twilio/flex-ui-sample",
3 | "version": "1.0.0",
4 | "private": true,
5 | "dependencies": {
6 | "@twilio/flex-ui": "^2.0.0",
7 | "history": "4.7.2",
8 | "react": "^17.0.2",
9 | "react-dom": "^17.0.2",
10 | "react-scripts": "^5.0.1"
11 | },
12 | "scripts": {
13 | "start": "craco start",
14 | "build": "craco build",
15 | "test": "craco test",
16 | "eject": "craco eject"
17 | },
18 | "eslintConfig": {
19 | "extends": "react-app"
20 | },
21 | "browserslist": [
22 | ">0.2%",
23 | "not dead",
24 | "not ie <= 11",
25 | "not op_mini all"
26 | ],
27 | "devDependencies": {
28 | "@craco/craco": "^7.1.0"
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/public/assets/appConfig.sample.js:
--------------------------------------------------------------------------------
1 | // set your account sid here
2 | var accountSid = "AC...";
3 |
4 |
5 | var appConfig = {
6 | // Uncomment the following lines to enable automatic log in
7 | //
8 | // sso: {
9 | // accountSid: accountSid
10 | // },
11 | sdkOptions: {
12 | worker: {
13 | logLevel: "error"
14 | },
15 | insights: {
16 | logLevel: "error"
17 | },
18 | chat: {
19 | logLevel: "error"
20 | },
21 | flex: {
22 | logger: {
23 | level: "error"
24 | }
25 | },
26 | voice: {
27 | debug: false
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Twilio Flex
8 |
9 |
10 |
11 |
12 |
15 |
16 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/public/plugins.json:
--------------------------------------------------------------------------------
1 | []
2 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import * as Flex from "@twilio/flex-ui";
3 |
4 | class App extends React.Component {
5 | render() {
6 | const { manager } = this.props;
7 |
8 | if (!manager) {
9 | return null;
10 | }
11 |
12 | return (
13 |
14 |
15 |
16 | );
17 | }
18 | }
19 |
20 | export default App;
21 |
--------------------------------------------------------------------------------
/src/App.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import App from './App';
4 |
5 | it('renders without crashing', () => {
6 | const div = document.createElement('div');
7 | ReactDOM.render(, div);
8 | ReactDOM.unmountComponentAtNode(div);
9 | });
10 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | body, #root {
2 | margin: 0;
3 | padding: 0;
4 | width: 100vw;
5 | height: 100vh;
6 | display: flex;
7 | font-family: 'Open Sans', sans-serif;
8 | }
9 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import ReactDOM from "react-dom";
3 | import "regenerator-runtime/runtime";
4 | import * as Flex from "@twilio/flex-ui";
5 | import "./index.css";
6 | import App from "./App";
7 | import registerServiceWorker from "./registerServiceWorker";
8 |
9 | const mountNode = document.getElementById("root");
10 |
11 | window.onload = () => {
12 | const predefinedConfig = window.appConfig || {};
13 |
14 | const configuration = {
15 | ...predefinedConfig,
16 | };
17 |
18 | Flex
19 | .progress(mountNode)
20 | .provideLoginInfo(configuration, mountNode)
21 | .then(() => Flex.Manager.create(configuration))
22 | .then(manager => renderApp(manager))
23 | .catch(error => handleError(error));
24 | };
25 |
26 | function renderApp(manager) {
27 | ReactDOM.render(
28 | ,
29 | mountNode
30 | );
31 | }
32 |
33 | function handleError(error) {
34 | Flex.errorPage(error, mountNode);
35 | console.error("Failed to initialize Flex", error);
36 | }
37 |
38 | registerServiceWorker();
39 |
--------------------------------------------------------------------------------
/src/registerServiceWorker.js:
--------------------------------------------------------------------------------
1 | // In production, we register a service worker to serve assets from local cache.
2 |
3 | // This lets the app load faster on subsequent visits in production, and gives
4 | // it offline capabilities. However, it also means that developers (and users)
5 | // will only see deployed updates on the "N+1" visit to a page, since previously
6 | // cached resources are updated in the background.
7 |
8 | // To learn more about the benefits of this model, read https://goo.gl/KwvDNy.
9 | // This link also includes instructions on opting out of this behavior.
10 |
11 | const isLocalhost = Boolean(
12 | window.location.hostname === 'localhost' ||
13 | // [::1] is the IPv6 localhost address.
14 | window.location.hostname === '[::1]' ||
15 | // 127.0.0.1/8 is considered localhost for IPv4.
16 | window.location.hostname.match(
17 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
18 | )
19 | );
20 |
21 | export default function register() {
22 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
23 | // The URL constructor is available in all browsers that support SW.
24 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
25 | if (publicUrl.origin !== window.location.origin) {
26 | // Our service worker won't work if PUBLIC_URL is on a different origin
27 | // from what our page is served on. This might happen if a CDN is used to
28 | // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
29 | return;
30 | }
31 |
32 | window.addEventListener('load', () => {
33 | const swUrl = `${process.env.PUBLIC_URL}/assets/service-worker.js`;
34 |
35 | if (isLocalhost) {
36 | // This is running on localhost. Lets check if a service worker still exists or not.
37 | checkValidServiceWorker(swUrl);
38 |
39 | // Add some additional logging to localhost, pointing developers to the
40 | // service worker/PWA documentation.
41 | navigator.serviceWorker.ready.then(() => {
42 | console.log(
43 | 'This web app is being served cache-first by a service ' +
44 | 'worker. To learn more, visit https://goo.gl/SC7cgQ'
45 | );
46 | });
47 | } else {
48 | // Is not local host. Just register service worker
49 | registerValidSW(swUrl);
50 | }
51 | });
52 | }
53 | }
54 |
55 | function registerValidSW(swUrl) {
56 | navigator.serviceWorker
57 | .register(swUrl)
58 | .then(registration => {
59 | registration.onupdatefound = () => {
60 | const installingWorker = registration.installing;
61 | installingWorker.onstatechange = () => {
62 | if (installingWorker.state === 'installed') {
63 | if (navigator.serviceWorker.controller) {
64 | // At this point, the old content will have been purged and
65 | // the fresh content will have been added to the cache.
66 | // It's the perfect time to display a "New content is
67 | // available; please refresh." message in your web app.
68 | console.log('New content is available; please refresh.');
69 | } else {
70 | // At this point, everything has been precached.
71 | // It's the perfect time to display a
72 | // "Content is cached for offline use." message.
73 | console.log('Content is cached for offline use.');
74 | }
75 | }
76 | };
77 | };
78 | })
79 | .catch(error => {
80 | console.error('Error during service worker registration:', error);
81 | });
82 | }
83 |
84 | function checkValidServiceWorker(swUrl) {
85 | // Check if the service worker can be found. If it can't reload the page.
86 | fetch(swUrl)
87 | .then(response => {
88 | // Ensure service worker exists, and that we really are getting a JS file.
89 | if (
90 | response.status === 404 ||
91 | response.headers.get('content-type').indexOf('javascript') === -1
92 | ) {
93 | // No service worker found. Probably a different app. Reload the page.
94 | navigator.serviceWorker.ready.then(registration => {
95 | registration.unregister().then(() => {
96 | window.location.reload();
97 | });
98 | });
99 | } else {
100 | // Service worker found. Proceed as normal.
101 | registerValidSW(swUrl);
102 | }
103 | })
104 | .catch(() => {
105 | console.log(
106 | 'No internet connection found. App is running in offline mode.'
107 | );
108 | });
109 | }
110 |
111 | export function unregister() {
112 | if ('serviceWorker' in navigator) {
113 | navigator.serviceWorker.ready.then(registration => {
114 | registration.unregister();
115 | });
116 | }
117 | }
118 |
--------------------------------------------------------------------------------