├── .env ├── .gitignore ├── CHANGELOG.md ├── README.md ├── config-overrides.js ├── package.json ├── public ├── assets │ ├── webchat-appConfig.sample.js │ └── webchat-branding.js ├── img │ ├── background.png │ └── logo.svg └── index.html └── src ├── App.js ├── App.test.js ├── index.css ├── index.js └── registerServiceWorker.js /.env: -------------------------------------------------------------------------------- 1 | PORT=8081 2 | -------------------------------------------------------------------------------- /.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 | webchat-appConfig.js 27 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Twilio Flex Web Chat UI Sample 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app). 4 | 5 | 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). 6 | 7 | This package can only be consumed together with Twilio Flex. Visit http://twilio.com/flex to find out more. 8 | 9 | ## Instructions 10 | 11 | 1. Install all dependencies by running: 12 | ``` 13 | npm install 14 | ``` 15 | 2. Copy webchat-appConfig.sample.js in public/assets folder and configure accordingly to use your Twilio account 16 | ``` 17 | cp public/assets/webchat-appConfig.sample.js public/assets/webchat-appConfig.js 18 | ``` 19 | 3. Start Flex UI by running: 20 | ``` 21 | npm start 22 | ``` -------------------------------------------------------------------------------- /config-overrides.js: -------------------------------------------------------------------------------- 1 | module.exports = function override(config) { 2 | // Prevents conflicts when multiples bundles generated by different versions of Webpack 3 | // are loaded on the same page 4 | config.output.jsonpFunction = "SAFE_jsonpFunction"; 5 | 6 | 7 | // ⬇ Uncomment to output a single file 8 | // delete config.output.chunkFilename; 9 | // delete config.optimization.runtimeChunk; 10 | // delete config.optimization.splitChunks; 11 | 12 | // ⬇ Uncomment to remove hashes from filenames 13 | // config.output.filename = "static/js/[name].js"; 14 | 15 | return config; 16 | }; 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@twilio/flex-webchat-ui-sample", 3 | "version": "2.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "@twilio/flex-webchat-ui": "^2.0.0", 7 | "array-findindex-polyfill": "^0.1.0", 8 | "ie-array-find-polyfill": "^1.1.0", 9 | "react": "^16.5.2", 10 | "react-app-polyfill": "^1.0.1", 11 | "react-dom": "^16.5.2", 12 | "react-scripts": "3.4.1" 13 | }, 14 | "scripts": { 15 | "start": "react-app-rewired start", 16 | "build": "react-app-rewired build", 17 | "test": "react-app-rewired test", 18 | "eject": "react-app-rewired eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": "react-app" 22 | }, 23 | "browserslist": [ 24 | ">0.2%", 25 | "not dead", 26 | "ie 11", 27 | "not ie < 11", 28 | "not op_mini all" 29 | ], 30 | "devDependencies": { 31 | "react-app-rewired": "^2.1.5" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /public/assets/webchat-appConfig.sample.js: -------------------------------------------------------------------------------- 1 | var appConfig = { 2 | // change the your AccountSid 3 | accountSid: "AC...", 4 | // change to your Flex Flow SID 5 | flexFlowSid: "FO...", 6 | colorTheme: { 7 | overrides: brandedColors 8 | } 9 | } -------------------------------------------------------------------------------- /public/assets/webchat-branding.js: -------------------------------------------------------------------------------- 1 | var brandColor1 = "#1976d2"; 2 | var brandColor2 = "#233659"; 3 | var brandTextColor = "#ffffff"; 4 | 5 | var personalizedColors = { 6 | darkBlueBackground: "#3C425C", 7 | whiteText: "#FFFFFF", 8 | entryPointBackground: "#3C425C", 9 | lighterBackground: "#ecedf1", 10 | primaryButtonBackground: "#1976d2", 11 | primaryButtonColor: "#FFFFFF", 12 | secondaryButtonBackground: "#6e7180", 13 | secondaryButtonColor: "#FFFFFF" 14 | }; 15 | 16 | var brandMessageBubbleColors = function (bgColor) { 17 | return { 18 | Bubble: { 19 | background: bgColor, 20 | color: brandTextColor 21 | }, 22 | Avatar: { 23 | background: bgColor, 24 | color: brandTextColor 25 | }, 26 | Header: { 27 | color: brandTextColor 28 | } 29 | } 30 | }; 31 | 32 | var brandedColors = { 33 | Chat: { 34 | MessageListItem: { 35 | FromOthers: brandMessageBubbleColors(brandColor2), 36 | FromMe: brandMessageBubbleColors(brandColor1), 37 | }, 38 | MessageInput: { 39 | Button: { 40 | background: brandColor1, 41 | color: brandTextColor 42 | } 43 | }, 44 | MessageCanvasTray: { 45 | Container: { 46 | background: personalizedColors.darkBlueBackground, 47 | color: personalizedColors.whiteText 48 | } 49 | }, 50 | }, 51 | 52 | MainHeader: { 53 | Container: { 54 | background: personalizedColors.darkBlueBackground, 55 | color: personalizedColors.whiteText 56 | }, 57 | Logo: { 58 | fill: brandTextColor 59 | } 60 | }, 61 | 62 | EntryPoint: { 63 | Container: { 64 | background: personalizedColors.entryPointBackground, 65 | color: personalizedColors.whiteText 66 | } 67 | }, 68 | 69 | PreEngagementCanvas: { 70 | Container: { 71 | background: personalizedColors.lighterBackground 72 | }, 73 | 74 | Form: { 75 | SubmitButton: { 76 | background: personalizedColors.primaryButtonBackground, 77 | color: personalizedColors.whiteText 78 | } 79 | } 80 | } 81 | }; 82 | -------------------------------------------------------------------------------- /public/img/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twilio/flex-webchat-ui-sample/df789166588e60449b8fcd2383ba7ea1cec4da25/public/img/background.png -------------------------------------------------------------------------------- /public/img/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | FlexLogo/Neg/FlexLogoVert 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Twilio Flex Web Chat 7 | 8 | 9 | 10 | 11 | 12 | 15 |
16 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import * as FlexWebChat from "@twilio/flex-webchat-ui"; 3 | 4 | class App extends React.Component { 5 | 6 | state = {}; 7 | 8 | constructor(props) { 9 | super(props); 10 | 11 | const { configuration } = props; 12 | FlexWebChat.Manager.create(configuration) 13 | .then(manager => this.setState({ manager })) 14 | .catch(error => this.setState({ error })); 15 | } 16 | 17 | render() { 18 | const { manager, error } = this.state; 19 | if (manager) { 20 | return ( 21 | 22 | 23 | 24 | ); 25 | } 26 | 27 | if (error) { 28 | console.error("Failed to initialize Flex Web Chat", error); 29 | } 30 | 31 | return null; 32 | } 33 | } 34 | 35 | export default App; 36 | -------------------------------------------------------------------------------- /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 | 10 | body { 11 | position: relative; 12 | background-size: cover; 13 | background-image: url("/img/background.png"); 14 | background-color: #6D7697; 15 | } 16 | 17 | body:after { 18 | content: ""; 19 | position: absolute; 20 | top: 50%; 21 | left: 50%; 22 | width: 174px; 23 | height: 182px; 24 | margin-left: -87px; 25 | margin-top: -91px; 26 | opacity: 0.2; 27 | background: url("/img/logo.svg"); 28 | } -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | // Comment out following polyfills if you don't need IE11 support 2 | import 'react-app-polyfill/ie11'; 3 | import 'react-app-polyfill/stable'; 4 | 5 | import React from 'react'; 6 | import ReactDOM from 'react-dom'; 7 | import 'regenerator-runtime/runtime'; 8 | import './index.css'; 9 | import App from './App'; 10 | import registerServiceWorker from './registerServiceWorker'; 11 | 12 | ReactDOM.render( 13 | , 14 | document.getElementById("root") 15 | ); 16 | 17 | registerServiceWorker(); 18 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------