├── .all-contributorsrc ├── .gitignore ├── README.md ├── craco.config.js ├── jest.config.js ├── package-lock.json ├── package.json ├── public ├── appConfig.example.js └── appConfig.js ├── src ├── AgentAutoresponsePlugin.js ├── components │ ├── CannedResponses.Styles.jsx │ └── CannedResponses.jsx └── index.js ├── webpack.config.js └── webpack.dev.js /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "files": [ 3 | "README.md" 4 | ], 5 | "imageSize": 100, 6 | "commit": false, 7 | "contributors": [ 8 | { 9 | "login": "ahcai", 10 | "name": "Alice Cai", 11 | "avatar_url": "https://avatars.githubusercontent.com/u/4912483?v=4", 12 | "profile": "https://github.com/ahcai", 13 | "contributions": [ 14 | "bug", 15 | "code", 16 | "doc", 17 | "design", 18 | "question" 19 | ] 20 | }, 21 | { 22 | "login": "ktalebian", 23 | "name": "Kousha Talebian", 24 | "avatar_url": "https://avatars.githubusercontent.com/u/2308915?v=4", 25 | "profile": "https://github.com/ktalebian", 26 | "contributions": [ 27 | "bug", 28 | "code", 29 | "doc", 30 | "design", 31 | "question" 32 | ] 33 | }, 34 | { 35 | "login": "johnfischelli", 36 | "name": "John Fischelli", 37 | "avatar_url": "https://avatars.githubusercontent.com/u/1213604?v=4", 38 | "profile": "https://github.com/johnfischelli", 39 | "contributions": [ 40 | "code", 41 | "doc", 42 | "design" 43 | ] 44 | } 45 | ], 46 | "contributorsPerLine": 7, 47 | "projectName": "plugin-agent-autoresponse", 48 | "projectOwner": "twilio-labs", 49 | "repoType": "github", 50 | "repoHost": "https://github.com", 51 | "skipCi": true 52 | } 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | # Flex related ignore 64 | appConfig.js 65 | build/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Agent Auto-Response Plugin 2 | 3 | [![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-) 4 | 5 | 6 | This Twilio Flex Plugin enables your agents to send canned responses when chatting with a customer. 7 | 8 | To learn more about developing plugins on your Flex instance, refer to the [getting started guide](https://www.twilio.com/docs/flex/quickstart/getting-started-plugin). 9 | 10 | --- 11 | 12 | There are two main files in this example: 13 | 14 | ``` 15 | src/AgentAutoResponsePlugin.js 16 | src/components/CannedResponses.js 17 | ``` 18 | 19 | The main file is the `AgentAutoResponsePlugin.js` file, and contains many comments describing how the auto-response example is achieved. In addition, it appends the Canned Responses component in `CannedResponses.js` to Chat/SMS conversations. 20 | 21 | While the canned-responses are static in this example, you might build on this example and call-out to your own server to retrieve your curated list of canned responses before rendering them in the Flex UI. 22 | 23 | --- 24 | 25 | When you run this plugin - you'll see a pre-defined message sent by the answering agent as soon as they accept the task. 26 | 27 | Additionally, you'll see new UI added below the Chat Input field which is a Select menu and will let you select from a list of pre-defined canned responses. When selecting any message in the select menu - it will automatically be sent into the chat/sms channel. 28 | 29 | ## Screenshot 30 | 31 | ![Screenshot](https://indigo-bombay-5783.twil.io/assets/auto-response-canned.png) 32 | 33 | ## Setup 34 | 35 | Make sure you have [Node.js](https://nodejs.org) as well as [`npm`](https://npmjs.com) installed. 36 | 37 | Afterwards install the dependencies by running `npm install`: 38 | 39 | ```bash 40 | cd plugin-agent-autoresponse 41 | 42 | # If you use npm 43 | npm install 44 | ``` 45 | 46 | ## Development 47 | 48 | In order to develop locally, you can use the Webpack Dev Server by running: 49 | 50 | ```bash 51 | twilio flex:plugins:start 52 | ``` 53 | 54 | This will automatically start up the Webpack Dev Server and open the browser for you. Your app will run on `http://localhost:3000`. If you want to change that you can do this by setting the `PORT` environment variable: 55 | 56 | ```bash 57 | PORT=3001 twilio flex:plugins:start 58 | ``` 59 | 60 | When you make changes to your code, the browser window will be automatically refreshed. 61 | 62 | Type `twilio flex:plugins:start --help` to get more detailed information about the command. 63 | 64 | ## Deploy and Release Plugin 65 | 66 | When you are ready to deploy your plugin, in your terminal run: 67 | 68 | ```bash 69 | twilio flex:plugins:deploy --major --changelog "Adding Auto-Response for Agents" --description "Ability for agents to send canned responses" 70 | ``` 71 | 72 | This will upload your plugin to Flex. After a deploy, your plugin is not yet enabled for all your users on your Flex application. You need to run the release command after the deploy to enable any changes: 73 | 74 | ```bash 75 | twilio flex:plugins:release --name "Plugin Auto-Response" --description "Enabling plugin auto-response" --plugin plugin-agent-autoresponse@latest 76 | ``` 77 | 78 | For more details on deploying your plugin, refer to the [deploying your plugin guide](https://www.twilio.com/docs/flex/developer/plugins/cli/deploy-and-release). 79 | 80 | Note: Common packages like `React`, `ReactDOM`, `Redux` and `ReactRedux` are not bundled with the build because they are treated as external dependencies so the plugin will depend on Flex to provide them globally. 81 | 82 | ## Contributors ✨ 83 | 84 | Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 |

Alice Cai

🐛 💻 📖 🎨 💬

Kousha Talebian

🐛 💻 📖 🎨 💬

John Fischelli

💻 📖 🎨
96 | 97 | 98 | 99 | 100 | 101 | 102 | This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! -------------------------------------------------------------------------------- /craco.config.js: -------------------------------------------------------------------------------- 1 | const config = require('craco-config-flex-plugin'); 2 | 3 | module.exports = { 4 | ...config, 5 | plugins: [ 6 | // You can customize the configuration by defining your own plugins. 7 | // See https://github.com/sharegate/craco/tree/master/packages/craco#develop-a-plugin 8 | // for more detail 9 | ] 10 | }; 11 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = (config, { isProd, isDev, isTest }) => { 2 | /** 3 | * Customize the Jest by modifying the config object. 4 | * Consult https://jestjs.io/docs/en/configuration for more information. 5 | */ 6 | 7 | return config; 8 | } 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "plugin-agent-autoresponse", 3 | "version": "0.0.0", 4 | "private": true, 5 | "description": "Enables your agents to send canned responses when chatting with a customer", 6 | "scripts": { 7 | "postinstall": "flex-plugin pre-script-check" 8 | }, 9 | "dependencies": { 10 | "react": "16.5.2", 11 | "react-dom": "16.5.2", 12 | "flex-plugin-scripts": "4.1.0" 13 | }, 14 | "devDependencies": { 15 | "@twilio/flex-ui": "^1", 16 | "react-test-renderer": "16.5.2" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /public/appConfig.example.js: -------------------------------------------------------------------------------- 1 | var appConfig = { 2 | pluginService: { 3 | enabled: true, 4 | url: '/plugins', 5 | }, 6 | ytica: false, 7 | logLevel: 'info', 8 | showSupervisorDesktopView: true, 9 | }; 10 | -------------------------------------------------------------------------------- /public/appConfig.js: -------------------------------------------------------------------------------- 1 | // your account sid 2 | var accountSid = ''; 3 | 4 | 5 | var appConfig = { 6 | pluginService: { 7 | enabled: true, 8 | url: '/plugins', 9 | }, 10 | sso: { 11 | accountSid: accountSid 12 | }, 13 | logLevel: 'debug', 14 | }; 15 | -------------------------------------------------------------------------------- /src/AgentAutoresponsePlugin.js: -------------------------------------------------------------------------------- 1 | import { FlexPlugin } from 'flex-plugin'; 2 | import React from 'react'; 3 | import CannedResponses from './components/CannedResponses'; 4 | 5 | const PLUGIN_NAME = 'AgentAutoresponsePlugin'; 6 | 7 | export default class AgentAutoresponsePlugin extends FlexPlugin { 8 | constructor() { 9 | super(PLUGIN_NAME); 10 | } 11 | 12 | /** 13 | * This code is run when your plugin is being started 14 | * Use this to modify any UI components or attach to the actions framework 15 | * 16 | * @param flex { typeof import('@twilio/flex-ui') } 17 | * @param manager { import('@twilio/flex-ui').Manager } 18 | */ 19 | init(flex, manager) { 20 | 21 | flex.MessageInput.Content.add(); 22 | 23 | 24 | manager.chatClient.on('channelJoined', (payload) => { 25 | // define a message to send into the channel - alternatively you could look it up here 26 | 27 | let body = `Hi! I'm ${manager.workerClient.attributes.full_name} and this is our predefined message.`; 28 | 29 | flex.Actions.invokeAction('SendMessage', { 30 | channelSid: payload.sid, 31 | body: body 32 | }); 33 | }); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/components/CannedResponses.Styles.jsx: -------------------------------------------------------------------------------- 1 | import styled from 'react-emotion'; 2 | 3 | export const CannedResponsesStyles = styled('div')` 4 | .form { 5 | width: 100%; 6 | margin-bottom: 20px; 7 | } 8 | 9 | .input-label { 10 | padding-left: 5px; 11 | } 12 | `; 13 | -------------------------------------------------------------------------------- /src/components/CannedResponses.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { connect } from 'react-redux'; 3 | import { Actions, withTheme } from '@twilio/flex-ui'; 4 | import FormControl from '@material-ui/core/FormControl'; 5 | import InputLabel from '@material-ui/core/InputLabel'; 6 | import Select from '@material-ui/core/Select'; 7 | import MenuItem from '@material-ui/core/MenuItem'; 8 | 9 | import { CannedResponsesStyles } from './CannedResponses.Styles'; 10 | 11 | class CannedResponses extends React.Component { 12 | constructor(props) { 13 | super(props); 14 | 15 | this.state = { 16 | response: '', 17 | } 18 | } 19 | 20 | handleChange = (event) => { 21 | this.setState({ [event.target.name]: event.target.value }); 22 | 23 | Actions.invokeAction('SendMessage', { 24 | channelSid: this.props.channelSid, 25 | body: event.target.value 26 | }); 27 | } 28 | 29 | render() { 30 | return ( 31 | 32 | 33 | Canned Responses 34 | 43 | 44 | 45 | ) 46 | } 47 | }; 48 | 49 | const mapStateToProps = (state, ownProps) => { 50 | let currentTask = false; 51 | state.flex.worker.tasks.forEach((task) => { 52 | if (ownProps.channelSid === task.attributes.channelSid) { 53 | currentTask = task; 54 | } 55 | }) 56 | 57 | return { 58 | state, 59 | currentTask, 60 | } 61 | } 62 | 63 | export default connect(mapStateToProps)(withTheme(CannedResponses)); 64 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import * as FlexPlugin from 'flex-plugin'; 2 | import AgentAutoresponsePlugin from './AgentAutoresponsePlugin'; 3 | 4 | FlexPlugin.loadPlugin(AgentAutoresponsePlugin); 5 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = (config, { isProd, isDev, isTest }) => { 2 | /** 3 | * Customize the webpack by modifying the config object. 4 | * Consult https://webpack.js.org/configuration for more information 5 | */ 6 | 7 | return config; 8 | } 9 | -------------------------------------------------------------------------------- /webpack.dev.js: -------------------------------------------------------------------------------- 1 | module.exports = (config, { isProd, isDev, isTest }) => { 2 | /** 3 | * Customize the webpack dev-server by modifying the config object. 4 | * Consult https://webpack.js.org/configuration/dev-server for more information. 5 | */ 6 | 7 | return config; 8 | } 9 | --------------------------------------------------------------------------------