├── .gitignore ├── CHANGES.md ├── LICENSE ├── Procfile ├── README.md ├── app.json ├── betty.js ├── gulpfile.js ├── lib ├── config.js ├── index.js ├── middlewares.js ├── profiles │ ├── ben.js │ ├── betty.js │ ├── catherine.js │ └── index.js ├── routes │ ├── api.js │ ├── call.js │ ├── dashboard.js │ ├── index.js │ └── sms.js ├── team.js ├── twilio │ ├── account.js │ ├── calls.js │ ├── client.js │ ├── index.js │ ├── normalize.js │ ├── recordings.js │ └── sms.js └── utils │ ├── parser.js │ ├── phone.js │ └── username.js ├── package.json ├── public ├── css │ └── main.css ├── images │ ├── betty.png │ ├── icon.png │ ├── preview.png │ └── team.png ├── js │ └── main.js └── less │ ├── audioplayer.less │ ├── dialogs.less │ ├── forms.less │ ├── list.less │ ├── main.less │ ├── mixins.less │ ├── navigation.less │ ├── pagination.less │ ├── panels.less │ ├── reset.less │ ├── tooltips.less │ └── variables.less ├── test ├── parser.js └── phones.js └── views ├── calls.html ├── dialogs ├── dial.html └── sms.html ├── layout.html ├── macros ├── audio.html ├── numbers.html └── pagination.html ├── recordings.html ├── sms.html ├── status.html └── team.html /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Deployed apps should consider commenting this line out: 24 | # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git 25 | node_modules 26 | 27 | # Local Configuration 28 | .env -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | # Release notes 2 | 3 | All notable changes to this project will be documented in this file. 4 | This project adheres to [Semantic Versioning](http://semver.org/). 5 | 6 | ### 0.2.0 7 | 8 | - Correctly handle machiens (like voicemail) when forwarding calls to team members 9 | - Call browser connected teqm members when receiving a call 10 | - Use relative urls to hostname for TwiML actions 11 | 12 | ### 0.1.0 13 | 14 | First release of Betty! 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2014 FriendCode Inc. 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: node ./betty.js -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Betty](https://github.com/SamyPesse/betty/blob/master/public/images/betty.png?raw=true) 2 | 3 | > Open source Google Voice with Receptionist abilities 4 | 5 | Betty (or Ben for the ones who prefer a male receptionist) is your own customizable receptionist, to forward call and messages to your team anywhere in the world. It's particularly useful if your organization is operating in the US, but based in another countries. 6 | 7 | Betty is easy to setup and build on top of Twilio and Node.js, it doesn't necessitate a database (stateless). It can be deployed to Heroku or any unix server. 8 | 9 | [![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy) 10 | 11 | ### What Betty can do? 12 | 13 | ##### One phone number for all your organization 14 | 15 | Betty is running on top of one or more phone numbers that represent your organization. 16 | 17 | ##### Forward call to available team members 18 | 19 | When receiving a call, Betty will forward it to an available team member. 20 | 21 | ##### Forward text messages to team members 22 | 23 | Like calls, when receiving an SMS, Betty will forward it to all of your team members, the first one to answer will start a session with this caller, he can after that stop the conversation by sending `betty: stop`. 24 | 25 | ##### Makes it easy for your employee to pass phone calls from the organization 26 | 27 | When a team member is calling Betty, he/she can ask to be put in touch with a specific number, Betty will dial the number and forward the call to you. 28 | 29 | This also works for text messages, simply text Betty with `betty: Call +140145170479` or `betty: Text +140145170479`. 30 | 31 | ##### Phone directory for your team members 32 | 33 | A team member can also contact Betty to get access to the organization directory (using phone call or sms). For example, just text Betty with: `betty: What is Aaron's phone number?`. 34 | 35 | ### Web Dashboard 36 | 37 | Betty is providing a nice dashboard to manage calls, messages and voicemail. You can pass calls and send SMS right from your browser. 38 | 39 | ![Dashboard](https://github.com/SamyPesse/betty/blob/master/public/images/preview.png?raw=true) 40 | 41 | ### The Receptionists Team 42 | 43 | ![Team](https://github.com/SamyPesse/betty/blob/master/public/images/team.png?raw=true) 44 | 45 | Betty can be configured to use another profile (voice, language, sentences, etc.). Change your receptionist by changing the `PROFILE` environment variable (see below). 46 | 47 | | ID | Name | Voice | Language | 48 | | ----------- | ---- | ----- | -------- | 49 | | `betty` | Betty | woman (alice) | `en-us` | 50 | | `ben` | Ben | man | `en-us` | 51 | | `catherine` | Catherine | woman (alice) | `fr` | 52 | 53 | ### Deployment 54 | 55 | Deploy Betty on your own machine using: 56 | 57 | ``` 58 | # Install Betty using NPM 59 | $ npm install betty-cli -g 60 | 61 | # Configure it 62 | $ export TEAM=Samy:+140145170479,Aaron:+147145670479 63 | ... 64 | 65 | # And finally start it 66 | $ betty 67 | ``` 68 | 69 | [Create a TwiML application](https://www.twilio.com/help/faq/twilio-client/how-do-i-create-a-twiml-app) with the following urls and associated it to a phone number: 70 | 71 | ``` 72 | * Voice 73 | * Request URL: {host}/twiml/call 74 | * Fallback URL: {host}/twiml/call/fallback 75 | * SMS 76 | * Request URL: {host}/twiml/sms 77 | * Fallback URL: {host}/twiml/sms/fallback 78 | ``` 79 | 80 | ### Configuration 81 | 82 | Configuration is set using environment variables: 83 | 84 | | Name | Description | 85 | | ------------ | ------------------- | 86 | | `PORT` | Port for running the application (Default is `3000`) | 87 | | `HOST` | Hostname where the application is accessible | 88 | | `SECRET` | Password for authentication in the dashboard and api | 89 | | `PROFILE` | Receptionist profile to use | 90 | | `PHONES` | List of phone numbers used by Betty separated by commas | 91 | | `ORG_NAME` | Name of the organization | 92 | | `TEAM` | Comma separated list of team members in the format `name:phone`, example `TEAM=Samy:+15674895678,Aaron:+15674995678` | 93 | | `TWILIO_SID` | API Application SID for Twilio | 94 | | `TWILIO_TOKEN` | API Application Token for Twilio | 95 | | `TWILIO_APPID` | SID of your TwiML application | 96 | 97 | ### REST API 98 | 99 | Betty provides a REST API with the same features that the dashboard: 100 | 101 | ``` 102 | Details about Betty and your account (balance, usages) 103 | GET /api/account 104 | 105 | List team members: 106 | GET /api/team 107 | 108 | List calls: 109 | GET /api/calls 110 | 111 | Details about a specific call: 112 | GET /api/calls/ 113 | 114 | List SMS 115 | GET /api/sms 116 | 117 | List Recordings 118 | GET /api/recordings 119 | ``` 120 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Betty", 3 | "description": "Open source Google Voice with Receptionist abilities", 4 | "logo": "https://github.com/SamyPesse/betty/raw/master/public/images/betty.png?raw=true", 5 | "repository": "https://github.com/SamyPesse/betty", 6 | "website": "https://github.com/SamyPesse/betty", 7 | "keywords": ["receptionist", "phone", "sms", "betty", "twilio"], 8 | "env": { 9 | "HOST": { 10 | "description": "Hostname where Betty will be running (including protocol)" 11 | }, 12 | "SECRET": { 13 | "description": "Secret token for web authentication" 14 | }, 15 | "SESSION_SECRET": { 16 | "description": "Secret token for sessions", 17 | "generator": "secret", 18 | "required": false 19 | }, 20 | "TEAM": { 21 | "description": "List of members separated by commas in format: name:phone" 22 | }, 23 | "TWILIO_SID": { 24 | "description": "Twilio SID" 25 | }, 26 | "TWILIO_TOKEN": { 27 | "description": "Twilio Token" 28 | }, 29 | "TWILIO_APPID": { 30 | "description": "TwiML Application ID" 31 | }, 32 | "PROFILE": { 33 | "description": "Receptionist Profile" 34 | }, 35 | "PHONES": { 36 | "description": "Phone number to use (separated by commas)" 37 | }, 38 | "ORG_NAME": { 39 | "description": "Organization's Name" 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /betty.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | 3 | var betty = require('./lib'); 4 | betty.start(); 5 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var less = require('gulp-less'); 3 | var path = require('path'); 4 | 5 | gulp.task('less', function () { 6 | return gulp.src('./public/less/main.less') 7 | .pipe(less()) 8 | .pipe(gulp.dest('./public/css')); 9 | }); 10 | 11 | 12 | gulp.task('default', ['less']); -------------------------------------------------------------------------------- /lib/config.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var phone = require('./utils/phone'); 3 | 4 | function fail(msg) { 5 | console.error(msg); 6 | process.exit(1); 7 | } 8 | 9 | var config = { 10 | 'port': process.env.PORT || 3000, 11 | 'host': process.env.HOST, 12 | 'secret': process.env.SECRET, 13 | 14 | // List of phone numbers 15 | 'phones': _.map((process.env.PHONES || "").split(','), function(num) { 16 | return phone.normalize(num); 17 | }), 18 | 19 | // Profile to use for conversation 20 | 'profile': process.env.PROFILE || "betty", 21 | 22 | // List of team members 23 | 'team': _.map((process.env.TEAM || "").split(','), function(t) { 24 | var parts = t.split(':'); 25 | return { 26 | name: parts[0], 27 | phone: phone.normalize(parts[1]) 28 | }; 29 | }), 30 | 31 | // Session configuration 32 | 'session': { 33 | 'secret': process.env.SESSION_SECRET || process.env.SECRET 34 | }, 35 | 36 | // Organization infos 37 | 'org': { 38 | 'name': process.env.ORG_NAME 39 | }, 40 | 41 | // Twilio API config 42 | 'twilio': { 43 | 'sid': process.env.TWILIO_SID, 44 | 'token': process.env.TWILIO_TOKEN, 45 | 'app': process.env.TWILIO_APPID 46 | }, 47 | 48 | 'call': { 49 | // Limit in seconds that Betty waits for the called party to answer the call. 50 | 'timeout': Number(process.env.CALL_TIMEOUT || 180) 51 | } 52 | }; 53 | 54 | config.host = config.host || "http://localhost:"+config.port; 55 | 56 | // Valid configuration 57 | if (!config.twilio.sid || !config.twilio.token || !config.twilio.app) { 58 | fail("Need TWILIO_SID, TWILIO_TOKEN and TWILIO_APPID environment variables"); 59 | } 60 | if (!config.secret) { 61 | fail("Need SECRET environment variable"); 62 | } 63 | 64 | module.exports = config; -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var _ = require('lodash'); 3 | var path = require('path'); 4 | var bodyParser = require('body-parser'); 5 | var morgan = require('morgan'); 6 | var nunjucks = require('nunjucks'); 7 | var moment = require('moment'); 8 | var session = require('cookie-session'); 9 | 10 | var config = require('./config'); 11 | var twilio = require('./twilio'); 12 | var middlewares = require('./middlewares'); 13 | var routes = require('./routes'); 14 | var profile = require('./profiles')[config.profile]; 15 | 16 | var app = express(); 17 | app.set('trust proxy', 1) 18 | 19 | app.use(morgan('combined')); 20 | 21 | app.use(session({ 22 | secret: config.session.secret 23 | })); 24 | 25 | app.use(bodyParser.urlencoded()); 26 | app.use(bodyParser.json()); 27 | app.use('/public', express.static(path.resolve(__dirname, '../public'))); 28 | 29 | 30 | // Templating 31 | var tpl = new nunjucks.Environment( 32 | new nunjucks.FileSystemLoader(path.resolve(__dirname, '../views')) 33 | ); 34 | tpl.addGlobal('config', config); 35 | tpl.addGlobal('profile', profile); 36 | tpl.addFilter('relativeDate', function(d) { 37 | return moment(d).fromNow(); 38 | }); 39 | tpl.addFilter('nl2br', function(s) { 40 | return s.replace(/(?:\r\n|\r|\n)/g, '
'); 41 | }); 42 | tpl.express(app); 43 | 44 | routes(app); 45 | 46 | app.use(function(req, res, next) { 47 | var e = new Error("Not Found"); 48 | e.status = 404; 49 | next(e); 50 | }); 51 | 52 | app.use(function(error, req, res, next) { 53 | console.log("Error:", error.stack || error.message || error); 54 | res.status(error.status || 500).send({ 55 | error: error.message || error, 56 | code: error.status || 500 57 | }); 58 | }); 59 | 60 | module.exports = { 61 | start: function () { 62 | var server = app.listen(config.port, function () { 63 | var host = server.address().address; 64 | var port = server.address().port; 65 | console.log('Listening at http://%s:%s', host, port); 66 | }); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /lib/middlewares.js: -------------------------------------------------------------------------------- 1 | var twilio = require('twilio'); 2 | var _ = require('lodash'); 3 | var basicAuth = require('basic-auth'); 4 | 5 | var config = require('./config'); 6 | var team = require('./team'); 7 | var twilio = require('./twilio'); 8 | 9 | // Block non team member 10 | function teamMember(req, res, next) { 11 | var from = req.body.From; 12 | var member = team.get(from); 13 | 14 | if (member) { 15 | req.teamMember = member; 16 | next(); 17 | } else { 18 | res.status(403).send('Limited to team member'); 19 | } 20 | } 21 | 22 | // Admin Authentication 23 | function adminAuth(req, res, next) { 24 | var user = basicAuth(req); 25 | user = team.auth(user); 26 | 27 | if (user) { 28 | res.locals.capability = { 29 | token: twilio.capability(user) 30 | }; 31 | 32 | return next(); 33 | } else { 34 | res.set('WWW-Authenticate', 'Basic realm=Authorization Required'); 35 | return res.send(401); 36 | }; 37 | } 38 | 39 | 40 | module.exports = { 41 | team: teamMember, 42 | admin: adminAuth 43 | }; 44 | -------------------------------------------------------------------------------- /lib/profiles/ben.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | name: "Ben", 4 | voice: 'man', 5 | language: 'en-us', 6 | 7 | message: {} 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /lib/profiles/betty.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | name: "Betty", 4 | voice: 'alice', 5 | language: 'en-us', 6 | 7 | messages: { 8 | // Visitor 9 | callError: "Your call could not be processed at the moment. Sorry for the inconvenience", 10 | callWelcome: "Thanks for calling <%= config.org.name %>, your call will be transfered to one of our team members", 11 | callUnavailable: "All of our team members are currently busy, please record your message after the signal, then press #", 12 | callConfirm: "Hi <%= member.name %>, we have an incoming call from <%= from %>, press # to accept the call", 13 | callRecord: "Thank you, your message has been recorded, our team will get in touch with you soon", 14 | 15 | // Team 16 | teamPrompNumber: "Hello <%= member.name %>, Enter the number to call, then press #", 17 | teamFailed: "Sorry, the call has failed, please try again later", 18 | 19 | // SMS 20 | smsError: "Your sms could not be processed at the moment. Sorry for the inconvenience", 21 | smsReceived: "Your message has been forwarded to one of our team members", 22 | smsAlreadyHandled: "This conversation is already being taken care of by <= by.name %>", 23 | smsForward: "Hi <%= member.name %>, we've received a text message from <%= message.from %>, just reply to this message to start the conversation:\n\n<%= message.body %>", 24 | 25 | // SMS Actions 26 | smsActionStop: "Ok <%= member.name %>, I stopped your sms conversation with <%= to %>", 27 | smsActionUnknown: "Sorry, I didn't understand your message", 28 | smsActionText: "Ok, you're now in conversation with <%= to %>, all your messages will be forward to them", 29 | smsActionCall: "Ok, you'll soon receive a call to connect you to <%= to %>" 30 | } 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /lib/profiles/catherine.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | name: "Catherine", 4 | voice: 'alice', 5 | language: 'fr-fr', 6 | 7 | message: {} 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /lib/profiles/index.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | 3 | var PROFILES = { 4 | betty: require('./betty'), 5 | ben: require('./ben'), 6 | catherine: require('./catherine') 7 | }; 8 | 9 | module.exports = _.mapValues(PROFILES, function(profile) { 10 | return _.merge(profile, PROFILES.betty, _.defaults); 11 | }); 12 | -------------------------------------------------------------------------------- /lib/routes/api.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var Q = require('q'); 3 | 4 | var express = require('express'); 5 | var config = require('../config'); 6 | 7 | var middlewares = require('../middlewares'); 8 | var twilio = require('../twilio'); 9 | var team = require('../team'); 10 | 11 | module.exports = function(app) { 12 | var api = express.Router(); 13 | var start = Date.now(); 14 | 15 | function method(fn) { 16 | return function(req, res, next) { 17 | return Q() 18 | .then(function() { 19 | var args = [_.extend({}, req.query, req.body)]; 20 | if (_.size(req.params) > 0) args = [req.params].concat(args); 21 | 22 | return fn.apply(null, args); 23 | }) 24 | .then(function(data) { 25 | res.send(data); 26 | }) 27 | .fail(next); 28 | }; 29 | } 30 | 31 | // Service status 32 | api.get('/', method(twilio.account.get)); 33 | 34 | // Team 35 | api.get('/team', method(function() { 36 | return team.list(); 37 | })); 38 | api.get('/team/humans', method(function() { 39 | return team.humans(); 40 | })); 41 | 42 | // Calls API 43 | api.get('/calls', method(twilio.calls.list)); 44 | api.get('/calls/:id', method(function(params) { 45 | return twilio.calls.get(params.id); 46 | })); 47 | 48 | // SMS API 49 | api.get('/sms', method(twilio.sms.list)); 50 | 51 | // Recordings 52 | api.get('/recordings', method(twilio.recordings.list)); 53 | 54 | app.use('/api', middlewares.admin, api); 55 | }; 56 | -------------------------------------------------------------------------------- /lib/routes/call.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | 3 | var config = require('../config'); 4 | var twilio = require('../twilio'); 5 | var team = require('../team'); 6 | var phone = require('../utils/phone'); 7 | var middlewares = require('../middlewares'); 8 | 9 | module.exports = function(app) { 10 | // Fallback for errors 11 | app.post('/twiml/call/fallback', twilio.twimlResponse(function(resp) { 12 | resp.say( 13 | resp._('callError') 14 | ); 15 | }, { valid: false })); 16 | 17 | // Entry point for call 18 | app.post('/twiml/call', twilio.twimlResponse(function(resp, body) { 19 | var from = body.From; 20 | var tocall = body.tocall; 21 | var member = team.get(from); 22 | 23 | if (tocall) { 24 | var phoneToCall = phone.normalize(tocall); 25 | var memberToCall = team.get(tocall); 26 | 27 | resp.dial({ 28 | callerId: _.first(config.phones), 29 | action: twilio.actionUrl('dial/status') 30 | }, function(node) { 31 | if (phone.valid(tocall)) node.number(tocall) 32 | if (memberToCall) { 33 | node.client(memberToCall.username); 34 | if (phoneToCall != memberToCall.phone) node.number(memberToCall.phone); 35 | } 36 | }); 37 | return; 38 | } 39 | 40 | if (member) { 41 | // Ask for a number to call 42 | resp.say( 43 | resp._('teamPrompNumber', { member: member }) 44 | ) 45 | .gather({ 46 | action: twilio.actionUrl('dial'), 47 | finishOnKey: '#' 48 | }); 49 | } else { 50 | // Dial first team member 51 | resp.say( 52 | resp._('callWelcome') 53 | ); 54 | resp.dial({ 55 | callerId: _.first(config.phones), 56 | action: twilio.actionUrl('call/status'), 57 | timeout: config.call.timeout 58 | }, function(node) { 59 | _.each(team.humans(), function(member) { 60 | node.number(member.phone, { 61 | url: twilio.actionUrl('call/confirm?origin='+encodeURIComponent(from)) 62 | }); 63 | node.client(member.username); 64 | }); 65 | }); 66 | } 67 | })); 68 | 69 | // Confirm call 70 | app.post('/twiml/call/confirm', twilio.twimlResponse(function(resp, body, req) { 71 | var origin = body.origin; 72 | var tocall = body.tocall; 73 | var Digits = body.Digits; 74 | var to = body.To; 75 | var member = team.get(to); 76 | 77 | // Already entered some digits 78 | if (Digits) return; 79 | 80 | // Ask to enter some digits 81 | resp.say( 82 | resp._('callConfirm', { 83 | member: member, 84 | from: origin 85 | }) 86 | ); 87 | 88 | resp.gather({ 89 | finishOnKey: "#" 90 | }); 91 | resp.hangup(); 92 | })); 93 | 94 | // Status of the call 95 | app.post('/twiml/call/status', twilio.twimlResponse(function(resp, body, req) { 96 | var status = body.DialCallStatus; 97 | var hasFailed = (status == "failed" 98 | || status == "busy" 99 | || status == "no-answer" 100 | || status == "canceled"); 101 | 102 | 103 | if (hasFailed) { 104 | resp.say( 105 | resp._('callUnavailable') 106 | ); 107 | resp.record({ 108 | action: twilio.actionUrl('call/record') 109 | }); 110 | } 111 | })); 112 | 113 | // After recording a message 114 | app.post('/twiml/call/record', twilio.twimlResponse(function(resp, body) { 115 | resp.say(resp._('callRecord')); 116 | resp.hangup(); 117 | })); 118 | 119 | // Team member entered a number to call 120 | app.post('/twiml/dial', twilio.twimlResponse(function(resp, body, req) { 121 | // Dial number 122 | resp.dial(body.Digits, { 123 | callerId: _.first(config.phones), 124 | action: twilio.actionUrl('dial/status') 125 | }); 126 | })); 127 | 128 | app.post('/twiml/dial/status', twilio.twimlResponse(function(resp, body) { 129 | var status = body.CallStatus; 130 | var hasFailed = (status == "failed" 131 | || status == "busy" 132 | || status == "no-answer" 133 | || status == "canceled"); 134 | 135 | 136 | if (hasFailed) { 137 | resp.say( 138 | resp._('teamFailed') 139 | ); 140 | resp.hangup(); 141 | } 142 | })); 143 | }; 144 | -------------------------------------------------------------------------------- /lib/routes/dashboard.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var Q = require('q'); 3 | 4 | var express = require('express'); 5 | var config = require('../config'); 6 | 7 | var middlewares = require('../middlewares'); 8 | var twilio = require('../twilio'); 9 | var team = require('../team'); 10 | 11 | module.exports = function(app) { 12 | function view(tpl, fn) { 13 | return function(req, res, next) { 14 | Q() 15 | .then(function() { 16 | var args = [_.extend({}, req.query, req.body)]; 17 | if (_.size(req.params) > 0) args = [req.params].concat(args); 18 | 19 | return fn.apply(null, args); 20 | }) 21 | .then(function(data) { 22 | res.render(tpl, data); 23 | }) 24 | .fail(next); 25 | }; 26 | } 27 | 28 | // Homepage 29 | app.get('/', middlewares.admin, view('status.html', function() { 30 | return twilio.account.get() 31 | .then(function(account) { 32 | return { 33 | tab: "status", 34 | account: account 35 | }; 36 | }) 37 | })); 38 | 39 | // List calls 40 | app.get('/calls', middlewares.admin, view('calls.html', function(args) { 41 | return twilio.calls.list(args) 42 | .then(function(calls) { 43 | return { 44 | tab: "calls", 45 | calls: calls 46 | }; 47 | }); 48 | })); 49 | 50 | // List sms 51 | app.get('/sms', middlewares.admin, view('sms.html', function(args) { 52 | return twilio.sms.list(args) 53 | .then(function(messages) { 54 | return { 55 | tab: "sms", 56 | messages: messages 57 | }; 58 | }); 59 | })); 60 | app.post('/sms', middlewares.admin, function(req, res, next) { 61 | var body = req.body.body; 62 | var to = req.body.to; 63 | 64 | Q() 65 | .then(function() { 66 | return twilio.sms.send(to, body); 67 | }) 68 | .then(function() { 69 | res.redirect('/sms') 70 | }) 71 | .fail(next); 72 | }); 73 | 74 | // List recordings 75 | app.get('/recordings', middlewares.admin, view('recordings.html', function(args) { 76 | return twilio.recordings.list(args) 77 | .then(function(recordings) { 78 | return { 79 | tab: "recordings", 80 | recordings: recordings 81 | }; 82 | }); 83 | })); 84 | 85 | // List team 86 | app.get('/team', middlewares.admin, view('team.html', function() { 87 | return { 88 | tab: "team", 89 | team: team.list() 90 | }; 91 | })); 92 | }; 93 | -------------------------------------------------------------------------------- /lib/routes/index.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | 3 | var ROUTES = [ 4 | require("./call"), 5 | require("./sms"), 6 | require("./api"), 7 | require("./dashboard") 8 | ]; 9 | 10 | module.exports = function(app) { 11 | _.each(ROUTES, function(routes) { 12 | routes(app); 13 | }); 14 | }; 15 | -------------------------------------------------------------------------------- /lib/routes/sms.js: -------------------------------------------------------------------------------- 1 | var Q = require('q'); 2 | var _ = require('lodash'); 3 | 4 | var twilio = require('../twilio'); 5 | var config = require('../config'); 6 | var phone = require('../utils/phone'); 7 | var parser = require('../utils/parser'); 8 | var team = require('../team'); 9 | 10 | module.exports = function(app) { 11 | 12 | // Fallback for errors 13 | app.post('/twiml/call/fallback', twilio.twimlResponse(function(resp) { 14 | resp.message( 15 | resp._('smsError') 16 | ); 17 | }, { valid: false })); 18 | 19 | // Receive an SMS 20 | app.post('/twiml/sms', twilio.twimlResponse(function(resp, body, req) { 21 | var from = body.From; 22 | var body = body.Body; 23 | var fromMember = team.get(from); 24 | 25 | // Get session 26 | var originFrom = req.session.origin; 27 | var linkedTo = req.session.linkedTo? team.get(req.session.linkedTo) : null; 28 | 29 | var stopConversation = function() { 30 | req.session.origin = null; 31 | req.session.linkedTo = null; 32 | }; 33 | 34 | 35 | // For member, parse message and play action 36 | if (fromMember) { 37 | // Parse action 38 | var action = parser.parse(body, { 39 | receptionist: team.profile.name 40 | }); 41 | 42 | // This is a message to betty 43 | if (action) { 44 | // Unknown action 45 | if (action.type == 'unknown') { 46 | resp.message(resp._('smsActionUnknown')); 47 | } else { 48 | // For all other action, stop current conversation 49 | stopConversation(); 50 | } 51 | 52 | // Stop current conversation 53 | if (action.type == 'stop') { 54 | 55 | if (originFrom) resp.message(resp._('smsActionStop', { 56 | member: fromMember, 57 | to: originFrom 58 | })); 59 | } 60 | 61 | // Text somebody 62 | if (action.type == 'text') { 63 | req.session.origin = action.phone; 64 | req.session.linkedTo = fromMember.phone; 65 | 66 | resp.message(resp._('smsActionText', { 67 | member: fromMember, 68 | to: action.phone 69 | })); 70 | } 71 | 72 | // Call somebody 73 | if (action.type == 'call') { 74 | return twilio.calls.start( 75 | fromMember.phone, 76 | twilio.actionUrl('dial?Digits='+encodeURIComponent(action.phone)) 77 | ) 78 | .then(function () { 79 | resp.message(resp._('smsActionCall', { 80 | member: fromMember, 81 | to: action.phone 82 | })); 83 | }); 84 | } 85 | 86 | return; 87 | } 88 | 89 | 90 | // Conversation with external number 91 | if (originFrom) { 92 | // Already started with someone else 93 | if (linkedTo && linkedTo.username != fromMember.to) { 94 | return resp.message(resp._('smsAlreadyHandled', { 95 | by: linkedTo 96 | })); 97 | } 98 | 99 | // Mark as linked to this member 100 | req.session.linkedTo = fromMember.phone; 101 | 102 | // Forward message 103 | resp.message(body, { 104 | to: originFrom 105 | }); 106 | } else { 107 | // Invalid Conversation with Betty 108 | resp.message(resp._('smsActionUnknown')); 109 | } 110 | } else { 111 | if (linkedTo) { 112 | // Forward message to team member 113 | resp.message(body, { 114 | to: linkedTo.phone 115 | }); 116 | } else { 117 | // Set session 118 | req.session.origin = from; 119 | req.session.linkedTo = null; 120 | 121 | // Forward message 122 | _.each(team.humans(), function(mb) { 123 | var msg = resp._('smsForward', { 124 | member: mb, 125 | message: { 126 | from: from, 127 | body: body 128 | } 129 | }); 130 | resp.message(msg, { 131 | to: mb.phone 132 | }); 133 | }); 134 | 135 | // Signal that message has been forwarded 136 | resp.message(resp._('smsReceived')); 137 | } 138 | } 139 | })); 140 | 141 | }; 142 | -------------------------------------------------------------------------------- /lib/team.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | 3 | var config = require('./config'); 4 | var profile = require('./profiles')[config.profile]; 5 | var phone = require('./utils/phone'); 6 | var username = require('./utils/username'); 7 | 8 | var LIST = _.chain([ 9 | { 10 | name: profile.name, 11 | machine: true, 12 | phone: _.first(config.phones) 13 | } 14 | ]) 15 | .concat(config.team) 16 | .map(function(m) { 17 | m.username = username.normalize(m.name); 18 | return m; 19 | }) 20 | .value(); 21 | 22 | // Return a member by phone 23 | function getMember(entry) { 24 | var user; 25 | 26 | // Try by phone number 27 | user = _.find(LIST, { 28 | phone: phone.normalize(entry) 29 | }); 30 | if (user) return user; 31 | 32 | return _.find(LIST, { 33 | username: username.normalize(entry) 34 | }); 35 | } 36 | 37 | // Check if a member exists 38 | function exits(num) { 39 | return getMember(num) != null; 40 | } 41 | 42 | // Return list of all members 43 | function listAll() { 44 | return LIST; 45 | } 46 | 47 | // List all humans 48 | function listHumans() { 49 | return _.filter(LIST, function(m) { 50 | return m.machine != true; 51 | }); 52 | } 53 | 54 | // Get betty 55 | function getBetty() { 56 | return _.find(LIST, { 57 | machine: true 58 | }); 59 | } 60 | 61 | // Authenticate an user 62 | function auth(user) { 63 | if (!config.secret) return true; 64 | if (!user || !user.name || !user.pass || user.pass != config.secret) return false; 65 | return getMember(user.name); 66 | } 67 | 68 | module.exports = { 69 | profile: profile, 70 | get: getMember, 71 | exits: exits, 72 | list: listAll, 73 | humans: listHumans, 74 | betty: getBetty, 75 | auth: auth 76 | } -------------------------------------------------------------------------------- /lib/twilio/account.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var Q = require('q'); 3 | 4 | var client = require('./client'); 5 | var config = require('../config'); 6 | var normalize = require('./normalize'); 7 | 8 | // Get infos about the account 9 | function getAccount(opts) { 10 | return Q.all([ 11 | Q.nfcall(client.accounts(config.twilio.sid).get), 12 | Q.nfcall(client.usage.records.get) 13 | ]) 14 | .spread(function(infos, usages) { 15 | return normalize.account(infos, usages); 16 | }); 17 | } 18 | 19 | 20 | module.exports = { 21 | get: getAccount 22 | }; 23 | -------------------------------------------------------------------------------- /lib/twilio/calls.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var Q = require('q'); 3 | 4 | var config = require('../config'); 5 | var client = require('./client'); 6 | var normalize = require('./normalize'); 7 | 8 | // List calls 9 | function listCalls(opts) { 10 | return normalize.pagination( 11 | client.calls.list, 12 | 'calls', 13 | normalize.call, 14 | opts 15 | ); 16 | } 17 | 18 | // Get a specific call 19 | function getCall(id) { 20 | return Q.nfcall(client.calls(id).get) 21 | .then(normalize.call); 22 | } 23 | 24 | // Start a call 25 | function startCall(to, action) { 26 | return Q.nfcall(client.makeCall, { 27 | to: to, 28 | from: _.first(config.phones), 29 | url: action 30 | }); 31 | } 32 | 33 | module.exports = { 34 | list: listCalls, 35 | get: getCall, 36 | start: startCall 37 | }; 38 | -------------------------------------------------------------------------------- /lib/twilio/client.js: -------------------------------------------------------------------------------- 1 | var Twilio = require('twilio'); 2 | var config = require('../config'); 3 | 4 | module.exports = Twilio(config.twilio.sid, config.twilio.token); 5 | -------------------------------------------------------------------------------- /lib/twilio/index.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var Q = require('q'); 3 | var url = require('url'); 4 | var Twilio = require('twilio'); 5 | 6 | var config = require('../config'); 7 | var profile = require('../profiles')[config.profile]; 8 | var client = require('./client'); 9 | 10 | // Return an action url 11 | function getActionUrl(action) { 12 | return '/twiml/'+action; 13 | } 14 | 15 | // TwilioML Response builder 16 | function responseBuilder(fn, opts) { 17 | opts = _.defaults(opts || {}, { 18 | valid: true 19 | }); 20 | 21 | return function(req, res, next) { 22 | var resp = new Twilio.TwimlResponse(); 23 | var rurl = url.resolve(config.host, req.originalUrl); 24 | 25 | console.log("Request from twilio on ", req.path, req.body); 26 | 27 | // Use profile to change 'say' method 28 | var say = resp.say.bind(resp); 29 | resp.say = function(msg, attrs) { 30 | attrs = attrs || {}; 31 | attrs.voice = profile.voice; 32 | attrs.language = profile.language; 33 | 34 | return say(msg, attrs); 35 | }; 36 | 37 | resp._ = function(msg, ctx) { 38 | var args = _.toArray(arguments); 39 | ctx = _.defaults(ctx || {}, { 40 | config: config 41 | }); 42 | return _.template(profile.messages[msg] || msg)(ctx); 43 | }; 44 | 45 | Q() 46 | .then(function() { 47 | if (!opts.valid) return; 48 | 49 | if (false && !Twilio.validateExpressRequest(req, config.twilio.token, { url: rurl })) { 50 | var e = new Error("Twilio Request Validation Failed.") 51 | e.status = 403; 52 | throw e; 53 | } 54 | }) 55 | .then(function() { 56 | var args = _.extend({}, req.query, req.body); 57 | 58 | return fn(resp, args, req, res); 59 | }) 60 | .then(function() { 61 | res.set('Content-Type', 'text/xml'); 62 | res.status(200).send(resp.toString()); 63 | }) 64 | .fail(next); 65 | }; 66 | } 67 | 68 | 69 | // Create a capability and return the token 70 | function createCapability(user) { 71 | var capability = new Twilio.Capability(config.twilio.sid, config.twilio.token); 72 | capability.allowClientOutgoing(config.twilio.app); 73 | capability.allowClientIncoming(user.username); 74 | return capability.generate(); 75 | } 76 | 77 | 78 | module.exports = { 79 | twimlResponse: responseBuilder, 80 | actionUrl: getActionUrl, 81 | capability: createCapability, 82 | 83 | sms: require('./sms'), 84 | account: require('./account'), 85 | calls: require('./calls'), 86 | recordings: require('./recordings') 87 | }; 88 | -------------------------------------------------------------------------------- /lib/twilio/normalize.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var Q = require('q'); 3 | var url = require('url'); 4 | var path = require('path'); 5 | var phone = require('../utils/phone'); 6 | 7 | var config = require('../config'); 8 | var team = require('../team'); 9 | 10 | var start = Date.now(); 11 | 12 | var USAGE_LABELS = { 13 | totalprice: { 14 | title: "Total Cost", 15 | icon: "ion-social-usd" 16 | }, 17 | calls: { 18 | title: "Calls", 19 | unit: "minutes", 20 | icon: "ion-android-call" 21 | }, 22 | sms: { 23 | title: "SMS", 24 | unit: "messages", 25 | icon: "ion-android-textsms" 26 | }, 27 | recordings: { 28 | title: "Recordings", 29 | unit: " recorded minutes", 30 | icon: "ion-ios-recording" 31 | } 32 | } 33 | 34 | 35 | // Normalize a call/sms direction 36 | function normalizeDirection(dir) { 37 | return _.first(dir.split('-')); 38 | } 39 | 40 | // Normalize the source of a call 41 | var CLIENT_PREFIX = 'client:'; 42 | function normalizeNumber(num, incoming) { 43 | if (num.indexOf(CLIENT_PREFIX) === 0) { 44 | num = num.slice(CLIENT_PREFIX.length); 45 | } 46 | 47 | var toMember = team.get(num); 48 | 49 | // Unknown entry 50 | if (!phone.valid(num) && !toMember) { 51 | num = null; 52 | } 53 | 54 | // If no num, then it's for betty 55 | if (!num || num == 'Anonymous') { 56 | if (incoming) { 57 | return { 58 | alias: "Anonymous" 59 | }; 60 | } 61 | 62 | toMember = team.betty(); 63 | } 64 | 65 | return { 66 | phone: phone.valid(num)? phone.normalize(num) : (toMember? toMember.phone : num), 67 | member: toMember 68 | }; 69 | } 70 | 71 | // Normalize a twilio call 72 | function normalizeCall(call) { 73 | return { 74 | // Unique id for the call 75 | id: call.sid, 76 | 77 | // From and To (number nd member) 78 | from: normalizeNumber(call.from, true), 79 | to: normalizeNumber(call.to, false), 80 | forwardedFrom: (call.forwardedFrom && call.forwardedFrom != call.to)? normalizeNumber(call.forwardedFrom) : null, 81 | 82 | // Timestamps and duration 83 | startTime: call.startTime, 84 | endTime: call.endTime, 85 | duration: Number(call.duration), 86 | 87 | // Price of this call 88 | price: Number(call.price), 89 | 90 | // Direction "inbound" or "outbound" 91 | direction: normalizeDirection(call.direction), 92 | 93 | // Status (queued, ringing, in-progress, canceled, completed, failed, busy or no-answer) 94 | status: call.status 95 | }; 96 | } 97 | 98 | // Normalize a twilio sms 99 | function normalizeSMS(sms) { 100 | return { 101 | // Unique id for the sms 102 | id: sms.sid, 103 | 104 | // From and To (number nd member) 105 | from: normalizeNumber(sms.from, true), 106 | to: normalizeNumber(sms.to, false), 107 | 108 | // Date 109 | sentTime: sms.dateSent, 110 | 111 | // Body 112 | body: sms.body, 113 | 114 | // Status 115 | status: sms.status, 116 | 117 | // Price of this call 118 | price: Number(sms.price), 119 | 120 | // Direction "inbound" or "outbound" 121 | direction: normalizeDirection(sms.direction) 122 | }; 123 | } 124 | 125 | // Normalize a recording 126 | function normalizeRecording(rc) { 127 | return { 128 | id: rc.sid, 129 | 130 | // Date 131 | createdTime: rc.dateCreated, 132 | 133 | // Call 134 | call: rc.callSid, 135 | 136 | // Duration 137 | duration: Number(rc.duration), 138 | 139 | // Urls to read 140 | urls: { 141 | mp3: "https://api.twilio.com"+(rc.uri.slice(0, -5))+'.mp3' 142 | } 143 | }; 144 | } 145 | 146 | // Normalize an account 147 | function normalizeAccount(a, usages) { 148 | return { 149 | id: a.sid, 150 | name: a.friendlyName, 151 | 152 | uptime: (Date.now() - start), 153 | phones: config.phones, 154 | startTime: start, 155 | profile: team.profile, 156 | 157 | // Status 158 | status: a.status, 159 | 160 | // Date 161 | createdTime: a.dateCreated, 162 | 163 | usages: _.chain(usages.usage_records) 164 | .map(function(u) { 165 | return [ 166 | u.category, 167 | { 168 | value: Number(u.usage), 169 | price: Number(u.price), 170 | unit: u.usage_unit, 171 | label: USAGE_LABELS[u.category] 172 | } 173 | ]; 174 | }) 175 | .object() 176 | .value() 177 | }; 178 | } 179 | 180 | // Normalize a paginated request 181 | function normalizePage(uri) { 182 | if (!uri) return null; 183 | var parts = url.parse(uri, true); 184 | 185 | return { 186 | pagetoken: parts.query.PageToken, 187 | page: Number(parts.query.Page) 188 | }; 189 | } 190 | function normalizePagination(fn, selector, normalize, opts) { 191 | opts = opts || {}; 192 | 193 | opts.PageSize = opts.limit || 20; 194 | delete opts.limit; 195 | 196 | if (opts.page) { 197 | opts.Page = (opts.page || 0); 198 | opts.PageToken = opts.pagetoken; 199 | delete opts.page; 200 | delete opts.pagetoken; 201 | } 202 | 203 | return Q.nfcall(fn, opts) 204 | .then(function(result) { 205 | var items = result[selector]; 206 | return { 207 | list: _.map(items, normalize), 208 | start: result.start || 0, 209 | limit: result.pageSize, 210 | pages: { 211 | previous: normalizePage(result.previousPageUri), 212 | next: normalizePage(result.nextPageUri) 213 | } 214 | }; 215 | }); 216 | } 217 | 218 | module.exports = { 219 | number: normalizeNumber, 220 | call: normalizeCall, 221 | sms: normalizeSMS, 222 | recording: normalizeRecording, 223 | account: normalizeAccount, 224 | pagination: normalizePagination 225 | }; 226 | -------------------------------------------------------------------------------- /lib/twilio/recordings.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var Q = require('q'); 3 | 4 | var client = require('./client'); 5 | var config = require('../config'); 6 | var normalize = require('./normalize'); 7 | 8 | // List all recordings 9 | function listRecordings(opts) { 10 | return normalize.pagination( 11 | client.recordings.list, 12 | 'recordings', 13 | normalize.recording, 14 | opts 15 | ); 16 | } 17 | 18 | 19 | module.exports = { 20 | list: listRecordings 21 | }; 22 | -------------------------------------------------------------------------------- /lib/twilio/sms.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var Q = require('q'); 3 | 4 | var client = require('./client'); 5 | var config = require('../config'); 6 | var normalize = require('./normalize'); 7 | 8 | // Send a text messages 9 | function sendMessage(to, body) { 10 | return Q.nfcall(client.sendMessage.bind(client), { 11 | to: to, 12 | from: _.first(config.phones), 13 | body: body 14 | }); 15 | } 16 | 17 | // List SMS 18 | function listSMS(opts) { 19 | return normalize.pagination( 20 | client.listMessages, 21 | 'messages', 22 | normalize.sms, 23 | opts 24 | ); 25 | } 26 | 27 | 28 | module.exports = { 29 | send: sendMessage, 30 | list: listSMS 31 | }; 32 | -------------------------------------------------------------------------------- /lib/utils/parser.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var natural = require('natural'); 3 | 4 | var phone = require('./phone'); 5 | 6 | var ACTIONS = { 7 | // Start a call with a specific number 8 | call: { 9 | keywords: ['call'], 10 | attributes: { 11 | phone: phone.extract 12 | } 13 | }, 14 | 15 | // Start a text message with a specific number 16 | text: { 17 | keywords: ['text', 'sms'], 18 | attributes: { 19 | phone: phone.extract 20 | } 21 | }, 22 | 23 | // Stop current sms conversation 24 | stop: { 25 | keywords: ['stop'] 26 | } 27 | }; 28 | 29 | // Parse a message to return an action or null 30 | function parse(msg, opts) { 31 | opts = _.defaults(opts || {}, { 32 | receptionist: "betty" 33 | }); 34 | 35 | var tokenizer = new natural.WordTokenizer(); 36 | var tokens = _.map(tokenizer.tokenize(msg), function(t) { return t.toLowerCase(); }); 37 | 38 | // Check is a valid message for betty 39 | if (tokens[0] != opts.receptionist.toLowerCase()) { 40 | return null; 41 | } 42 | 43 | return (_.reduce(ACTIONS, function(prev, action, actionType) { 44 | var r; 45 | 46 | if (prev) return prev; 47 | 48 | // Check if action is matching 49 | var matching = _.difference(tokens, action.keywords); 50 | if (matching.length == tokens.length) return null; 51 | 52 | // Action is matching 53 | r = { 54 | type: actionType, 55 | }; 56 | 57 | // Extract attributes 58 | return _.reduce(action.attributes || {}, function(_r, fn, attr) { 59 | if (!_r) return null; 60 | var value = fn(msg); 61 | if (value == undefined) return null; 62 | _r[attr] = value; 63 | return _r; 64 | }, r); 65 | }, null) || { type: "unknown" }); 66 | } 67 | 68 | 69 | module.exports = { 70 | parse: parse 71 | }; 72 | -------------------------------------------------------------------------------- /lib/utils/phone.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var phone = require('node-phonenumber'); 3 | var phoneUtil = phone.PhoneNumberUtil.getInstance(); 4 | var phoneRegex = require('phone-regex'); 5 | 6 | // Normalize phone number 7 | function normalizePhone(num) { 8 | try { 9 | var phoneNumber = phoneUtil.parse(num, 'MY'); 10 | return phoneUtil.format(phoneNumber, phone.PhoneNumberFormat.INTERNATIONAL); 11 | } catch (e) { 12 | return num; 13 | } 14 | } 15 | 16 | // Test if it's a correct phone number 17 | function isPhone(num) { 18 | try { 19 | var phoneNumber = phoneUtil.parse(num, 'MY'); 20 | return true; 21 | } catch (e) { 22 | return false; 23 | } 24 | } 25 | 26 | // Compare 2 phone numbers 27 | function equals(n1, n2) { 28 | return normalizePhone(n1) == normalizePhone(n2); 29 | } 30 | 31 | // Extract a phone number from a message 32 | function extractPhone(msg) { 33 | var phones = msg.match(phoneRegex()); 34 | if (!phones || phones.length == 0) return undefined; 35 | return _.first(phones).trim(); 36 | } 37 | 38 | 39 | module.exports = { 40 | normalize: normalizePhone, 41 | valid: isPhone, 42 | equals: equals, 43 | extract: extractPhone 44 | }; 45 | -------------------------------------------------------------------------------- /lib/utils/username.js: -------------------------------------------------------------------------------- 1 | var normall = require('normall'); 2 | 3 | // Normalize a username 4 | function normalizeUsername(name) { 5 | if (!name) return name; 6 | return normall.username(name); 7 | } 8 | 9 | module.exports = { 10 | normalize: normalizeUsername 11 | }; 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "betty-cli", 3 | "version": "0.2.0", 4 | "description": "Open source Google Voice with Receptionist abilities", 5 | "homepage": "https://github.com/SamyPesse/betty", 6 | "license": "Apache-2.0", 7 | "main": "./lib/index.js", 8 | "dependencies": { 9 | "express": "4.12.3", 10 | "twilio": "2.0.0", 11 | "lodash": "3.7.0", 12 | "q": "1.2.0", 13 | "body-parser": "1.12.3", 14 | "phone-regex": "2.0.0", 15 | "morgan": "1.5.2", 16 | "node-phonenumber": "0.2.1", 17 | "basic-auth": "1.0.0", 18 | "natural": "0.2.1", 19 | "nunjucks": "1.3.3", 20 | "moment": "2.10.2", 21 | "normall": "0.2.2", 22 | "natural": "0.2.1", 23 | "cookie-session" : "1.1.0" 24 | }, 25 | "devDependencies": { 26 | "mocha": "2.2.4", 27 | "chai": "2.2.0", 28 | "gulp": "3.8.11", 29 | "gulp-less": "3.0.3" 30 | }, 31 | "scripts": { 32 | "test": "mocha --reporter list" 33 | }, 34 | "bugs": { 35 | "url": "https://github.com/SamyPesse/betty/issues" 36 | }, 37 | "authors": [ 38 | { 39 | "name": "Samy Pesse", 40 | "email": "samypesse@gmail.com" 41 | } 42 | ], 43 | "bin": { 44 | "betty": "./betty.js" 45 | }, 46 | "repository": { 47 | "type" : "git", 48 | "url" : "https://github.com/SamyPesse/betty.git" 49 | } 50 | } -------------------------------------------------------------------------------- /public/css/main.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Global Reset of all HTML Elements 3 | * 4 | * Resetting all of our HTML Elements ensures a smoother 5 | * visual transition between browsers. If you don't believe me, 6 | * try temporarily commenting out this block of code, then go 7 | * and look at Mozilla versus Safari, both good browsers with 8 | * a good implementation of CSS. The thing is, all browser CSS 9 | * defaults are different and at the end of the day if visual 10 | * consistency is what we're shooting for, then we need to 11 | * make sure we're resetting all spacing elements. 12 | * 13 | */ 14 | html, 15 | body { 16 | border: 0; 17 | font-family: "Helvetica-Neue", "Helvetica", Arial, sans-serif; 18 | line-height: 1.5; 19 | margin: 0; 20 | padding: 0; 21 | } 22 | div, 23 | span, 24 | object, 25 | iframe, 26 | img, 27 | table, 28 | caption, 29 | thead, 30 | tbody, 31 | tfoot, 32 | tr, 33 | tr, 34 | td, 35 | article, 36 | aside, 37 | canvas, 38 | details, 39 | figure, 40 | hgroup, 41 | menu, 42 | nav, 43 | footer, 44 | header, 45 | section, 46 | summary, 47 | mark, 48 | audio, 49 | video { 50 | border: 0; 51 | margin: 0; 52 | padding: 0; 53 | } 54 | h1, 55 | h2, 56 | h3, 57 | h4, 58 | h5, 59 | h6, 60 | p, 61 | blockquote, 62 | pre, 63 | a, 64 | abbr, 65 | address, 66 | cit, 67 | code, 68 | del, 69 | dfn, 70 | em, 71 | ins, 72 | q, 73 | samp, 74 | small, 75 | strong, 76 | sub, 77 | sup, 78 | b, 79 | i, 80 | hr, 81 | dl, 82 | dt, 83 | dd, 84 | ol, 85 | ul, 86 | li, 87 | fieldset, 88 | legend, 89 | label { 90 | border: 0; 91 | font-size: 100%; 92 | vertical-align: baseline; 93 | margin: 0; 94 | padding: 0; 95 | } 96 | article, 97 | aside, 98 | canvas, 99 | figure, 100 | figure img, 101 | figcaption, 102 | hgroup, 103 | footer, 104 | header, 105 | nav, 106 | section, 107 | audio, 108 | video { 109 | display: block; 110 | } 111 | table { 112 | border-collapse: separate; 113 | border-spacing: 0; 114 | } 115 | table caption, 116 | table th, 117 | table td { 118 | text-align: left; 119 | vertical-align: middle; 120 | } 121 | a img { 122 | border: 0; 123 | } 124 | :focus { 125 | outline: 0; 126 | } 127 | .clearfix { 128 | zoom: 1; 129 | } 130 | .clearfix:before, 131 | .clearfix:after { 132 | content: ""; 133 | display: table; 134 | } 135 | .clearfix:after { 136 | clear: both; 137 | } 138 | .hidden { 139 | display: none; 140 | } 141 | .list { 142 | width: 100%; 143 | background: #fff; 144 | } 145 | .list tr td { 146 | padding: 14px 10px; 147 | border-bottom: 1px solid #ececec; 148 | vertical-align: middle; 149 | line-height: 24px; 150 | } 151 | .list tr td a { 152 | text-decoration: none; 153 | color: inherit; 154 | } 155 | .list tr td a:focus, 156 | .list tr td a:hover { 157 | text-decoration: underline; 158 | } 159 | .list tr td.list-icon { 160 | text-align: center; 161 | } 162 | .list tr td i { 163 | font-size: 24px; 164 | display: inline-block; 165 | } 166 | .list tr td i.secondary { 167 | font-size: 14px; 168 | } 169 | .list tr td .help { 170 | color: #aaa; 171 | } 172 | .list tr td.list-actions { 173 | text-align: center; 174 | } 175 | .list tr td.list-actions a { 176 | display: inline-block; 177 | padding: 0px 8px; 178 | color: #aaa; 179 | } 180 | .list tr td.list-actions a:hover { 181 | color: #555; 182 | } 183 | .list tr td.list-alternate { 184 | background: #f5f5f5; 185 | } 186 | .panel { 187 | margin: 20px 0px; 188 | box-shadow: 0 0 2px rgba(0, 0, 0, 0.12), 0 2px 4px rgba(0, 0, 0, 0.24); 189 | } 190 | .navigation { 191 | width: 100%; 192 | display: -webkit-flex; 193 | display: -moz-flex; 194 | display: -ms-flexbox; 195 | display: -ms-flex; 196 | display: flex; 197 | -webkit-flex-direction: row; 198 | -moz-flex-direction: row; 199 | -ms-flex-direction: row; 200 | flex-direction: row; 201 | -webkit-align-items: stretch; 202 | -moz-align-items: stretch; 203 | -ms-align-items: stretch; 204 | align-items: stretch; 205 | } 206 | .navigation .tab { 207 | border-bottom: 4px solid transparent; 208 | text-align: center; 209 | text-transform: uppercase; 210 | font-size: 1rem; 211 | text-decoration: none; 212 | } 213 | .navigation .tab.active { 214 | border-bottom-color: #0288d1; 215 | } 216 | .navigation .tab.tab-link { 217 | color: #999; 218 | font-weight: 300; 219 | padding: 14px; 220 | -webkit-flex-grow: 2; 221 | -moz-flex-grow: 2; 222 | -ms-flex-grow: 2; 223 | flex-grow: 2; 224 | } 225 | .navigation .tab.tab-action { 226 | font-size: 24px; 227 | color: inherit; 228 | text-decoration: none; 229 | padding: 0px 14px; 230 | line-height: 50px; 231 | color: #999; 232 | } 233 | .navigation .tab.tab-action i { 234 | display: inline-block; 235 | } 236 | .navigation .tab.tab-action:hover { 237 | text-decoration: none; 238 | } 239 | .tooltip { 240 | display: inline; 241 | position: relative; 242 | } 243 | .tooltip:hover:after { 244 | line-height: 1em; 245 | background: #111; 246 | background: rgba(0, 0, 0, 0.9); 247 | border-radius: 1px; 248 | bottom: calc(100% + 10px); 249 | color: #fff; 250 | content: attr(title); 251 | display: block; 252 | left: 5px; 253 | padding: 5px 5px; 254 | position: absolute; 255 | text-shadow: 0 1px 0 #000; 256 | white-space: nowrap; 257 | z-index: 98; 258 | font-size: 13px; 259 | text-transform: none; 260 | } 261 | .tooltip:hover:before { 262 | border: solid; 263 | border-color: #111 transparent; 264 | border-color: rgba(0, 0, 0, 0.9) transparent; 265 | border-width: 5px 5px 0px 5px; 266 | bottom: calc(100% + 5px); 267 | content: ""; 268 | display: block; 269 | left: 10px; 270 | position: absolute; 271 | z-index: 99; 272 | } 273 | .tooltip.tooltip-bottom:after { 274 | bottom: auto; 275 | top: calc(100% + 10px); 276 | } 277 | .tooltip.tooltip-bottom:before { 278 | bottom: auto; 279 | top: calc(100% + 5px); 280 | border-width: 0px 5px 5px 5px; 281 | } 282 | .dialog-container { 283 | position: fixed; 284 | top: 0px; 285 | bottom: 0px; 286 | right: 0px; 287 | left: 0px; 288 | background: rgba(0, 0, 0, 0.7); 289 | display: none; 290 | overflow: auto; 291 | } 292 | .dialog-container.active { 293 | display: block; 294 | } 295 | .dialog-container .dialog { 296 | width: 400px; 297 | margin: 40px auto; 298 | background: #eee; 299 | box-shadow: 0 0 2px rgba(0, 0, 0, 0.12), 0 2px 4px rgba(0, 0, 0, 0.24); 300 | } 301 | .dialog-container .dialog .dialog-inner { 302 | padding: 20px; 303 | text-align: center; 304 | } 305 | .dialog-container .dialog .dialog-inner .dialog-intro { 306 | margin-bottom: 20px; 307 | } 308 | .dialog-container .dialog .dialog-inner .dialog-intro h1 { 309 | font-size: 1.2rem; 310 | font-weight: 400; 311 | margin-bottom: 1rem; 312 | } 313 | .dialog-container .dialog .dialog-inner .dialog-intro p { 314 | color: #666; 315 | } 316 | .dialog-container .dialog .dialog-controls { 317 | width: 100%; 318 | display: -webkit-flex; 319 | display: -moz-flex; 320 | display: -ms-flexbox; 321 | display: -ms-flex; 322 | display: flex; 323 | -webkit-flex-direction: row; 324 | -moz-flex-direction: row; 325 | -ms-flex-direction: row; 326 | flex-direction: row; 327 | -webkit-align-items: stretch; 328 | -moz-align-items: stretch; 329 | -ms-align-items: stretch; 330 | align-items: stretch; 331 | } 332 | .dialog-container .dialog .dialog-controls button { 333 | -webkit-flex-grow: 2; 334 | -moz-flex-grow: 2; 335 | -ms-flex-grow: 2; 336 | flex-grow: 2; 337 | } 338 | .form-control { 339 | width: 100%; 340 | margin-bottom: 10px; 341 | padding: 8px; 342 | font-size: 1.1rem; 343 | border: 1px solid #ddd; 344 | } 345 | button, 346 | .button { 347 | background: #fff; 348 | border-radius: 0px; 349 | border: 1px solid #eee; 350 | font-size: 16px; 351 | cursor: pointer; 352 | color: #222; 353 | padding: 14px; 354 | text-decoration: none; 355 | } 356 | button:hover, 357 | .button:hover { 358 | color: #000; 359 | } 360 | .dialpad { 361 | margin-left: -6px; 362 | margin-right: -6px; 363 | } 364 | .dialpad table { 365 | width: 100%; 366 | border-spacing: 6px; 367 | } 368 | .dialpad table input { 369 | width: 100%; 370 | background: #fff; 371 | border-radius: 0px; 372 | border: 1px solid #eee; 373 | font-size: 16px; 374 | cursor: pointer; 375 | color: #222; 376 | padding: 14px; 377 | text-decoration: none; 378 | } 379 | .dialpad table input:hover { 380 | color: #000; 381 | } 382 | .audio-player { 383 | background: #eee; 384 | width: 300px; 385 | overflow: hidden; 386 | } 387 | .audio-player .audio-inner { 388 | display: -webkit-flex; 389 | display: -moz-flex; 390 | display: -ms-flexbox; 391 | display: -ms-flex; 392 | display: flex; 393 | -webkit-flex-direction: row; 394 | -moz-flex-direction: row; 395 | -ms-flex-direction: row; 396 | flex-direction: row; 397 | -webkit-align-items: stretch; 398 | -moz-align-items: stretch; 399 | -ms-align-items: stretch; 400 | align-items: stretch; 401 | } 402 | .audio-player button { 403 | padding: 4px 14px; 404 | -webkit-flex-grow: 1; 405 | -moz-flex-grow: 1; 406 | -ms-flex-grow: 1; 407 | flex-grow: 1; 408 | } 409 | .audio-player .position { 410 | -webkit-flex-grow: 2; 411 | -moz-flex-grow: 2; 412 | -ms-flex-grow: 2; 413 | flex-grow: 2; 414 | padding: 0px 10px; 415 | line-height: 38px; 416 | font-size: 16px; 417 | } 418 | .audio-player .do-pause, 419 | .audio-player .do-stop { 420 | display: none; 421 | } 422 | .audio-player.playing .do-pause, 423 | .audio-player.playing .do-stop { 424 | display: block; 425 | } 426 | .audio-player.playing .do-play { 427 | display: none; 428 | } 429 | .audio-player.paused .do-play, 430 | .audio-player.paused .do-stop { 431 | display: block; 432 | } 433 | .audio-player.paused .do-pause { 434 | display: hidden; 435 | } 436 | .pagination { 437 | zoom: 1; 438 | } 439 | .pagination:before, 440 | .pagination:after { 441 | content: ""; 442 | display: table; 443 | } 444 | .pagination:after { 445 | clear: both; 446 | } 447 | .pagination .next { 448 | float: right; 449 | } 450 | .pagination .previous { 451 | float: left; 452 | } 453 | * { 454 | box-sizing: border-box; 455 | } 456 | body { 457 | background-color: #e5e5e5; 458 | font: normal 13px Roboto, arial, sans-serif; 459 | height: 100%; 460 | margin: 0; 461 | padding: 15px 0px; 462 | overflow-y: scroll; 463 | visibility: visible; 464 | } 465 | .container { 466 | max-width: 800px; 467 | width: 100%; 468 | margin: 0px auto; 469 | } 470 | .text-success { 471 | color: #5cb85c; 472 | } 473 | .text-error { 474 | color: #d9534f; 475 | } 476 | -------------------------------------------------------------------------------- /public/images/betty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamyPesse/betty/68861d7d0043ec4f696e27890b100af662e71607/public/images/betty.png -------------------------------------------------------------------------------- /public/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamyPesse/betty/68861d7d0043ec4f696e27890b100af662e71607/public/images/icon.png -------------------------------------------------------------------------------- /public/images/preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamyPesse/betty/68861d7d0043ec4f696e27890b100af662e71607/public/images/preview.png -------------------------------------------------------------------------------- /public/images/team.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamyPesse/betty/68861d7d0043ec4f696e27890b100af662e71607/public/images/team.png -------------------------------------------------------------------------------- /public/js/main.js: -------------------------------------------------------------------------------- 1 | 2 | function setupDialDialog() { 3 | var connection; 4 | var inCall = false; 5 | var $dialog = $('#dialog-dial'); 6 | var $input = $dialog.find('.dial-input'); 7 | var $status = $dialog.find('.dial-status'); 8 | var $doHangup = $dialog.find('.do-hangup'); 9 | var $doCall = $dialog.find('.do-call'); 10 | 11 | var toggleCallStatus = function(){ 12 | $doCall.toggle(!inCall); 13 | $doHangup.text(inCall? "Hangup" : "Close"); 14 | } 15 | 16 | 17 | $dialog.find('.dial-button').click(function(e) { 18 | e.preventDefault(); 19 | var value = $(e.currentTarget).val(); 20 | 21 | if (connection) { 22 | connection.sendDigits(value); 23 | } 24 | $input.val($input.val()+value); 25 | }); 26 | 27 | Twilio.Device.setup($dialog.find('input[name=token]').val()); 28 | 29 | $doCall.click(function() { 30 | params = { "tocall" : $input.val()}; 31 | connection = Twilio.Device.connect(params); 32 | }); 33 | $doHangup.click(function() { 34 | Twilio.Device.disconnectAll(); 35 | }); 36 | 37 | Twilio.Device.ready(function (device) { 38 | console.log("Ready"); 39 | $status.text('Ready to start call'); 40 | }); 41 | 42 | Twilio.Device.incoming(function (conn) { 43 | if (confirm('Accept incoming call from ' + conn.parameters.From + '?')) { 44 | $dialog.addClass('active'); 45 | connection = conn; 46 | conn.accept(); 47 | } 48 | }); 49 | 50 | Twilio.Device.offline(function (device) { 51 | console.log("Offline"); 52 | $status.text('Offline'); 53 | }); 54 | 55 | Twilio.Device.error(function (error) { 56 | console.log("Error", error); 57 | $status.text("Error: "+error.message.message); 58 | }); 59 | 60 | Twilio.Device.connect(function (conn) { 61 | console.log("Connected"); 62 | $status.text("Successfully established call"); 63 | inCall = true; 64 | toggleCallStatus(); 65 | }); 66 | 67 | Twilio.Device.disconnect(function (conn) { 68 | console.log("Disconnected"); 69 | if (inCall) $status.text("Call ended"); 70 | inCall = false; 71 | toggleCallStatus(); 72 | }); 73 | 74 | toggleCallStatus(); 75 | } 76 | 77 | // Click to toggle dialog 78 | function setupDialogs() { 79 | $('*[data-dialog]').click(function(e) { 80 | e.preventDefault(); 81 | var dialog = $(e.currentTarget).attr('data-dialog'); 82 | 83 | $('#dialog-'+dialog).toggleClass('active'); 84 | }); 85 | 86 | $(document).keyup(function(e) { 87 | if (e.keyCode == 27) $('.dialog-container').removeClass('active'); 88 | }); 89 | } 90 | 91 | // Setup audio player 92 | function setupAudioPlayers() { 93 | $('.audio-player').each(function() { 94 | var $player = $(this); 95 | var audio = $player.find('audio').get(0); 96 | var $position = $player.find('.position'); 97 | var loaded = false; 98 | 99 | audio.onplaying = function() { 100 | $player.addClass('playing'); 101 | $player.removeClass('paused'); 102 | }; 103 | audio.onpause = function() { 104 | $player.addClass('playing'); 105 | $player.addClass('paused'); 106 | }; 107 | audio.onended = function() { 108 | $player.removeClass('playing'); 109 | $player.removeClass('paused'); 110 | }; 111 | audio.ontimeupdate = function() { 112 | var t = audio.currentTime; 113 | var msg = ""; 114 | 115 | msg = Math.floor(t/60)+':'+Math.ceil(t % 60); 116 | 117 | $position.text(msg); 118 | }; 119 | 120 | $player.find('.do-play').click(function(e) { 121 | e.preventDefault(); 122 | if (!loaded) { 123 | audio.load(); 124 | loaded = true; 125 | } 126 | audio.play(); 127 | }); 128 | 129 | $player.find('.do-pause').click(function(e) { 130 | e.preventDefault(); 131 | audio.pause(); 132 | }); 133 | 134 | $player.find('.do-stop').click(function(e) { 135 | e.preventDefault(); 136 | audio.pause(); 137 | audio.currentTime = 0; 138 | }); 139 | }); 140 | } 141 | 142 | // Handle call and sms links in the app 143 | function setupLinks() { 144 | $('a').click(function(e) { 145 | var $a = $(e.currentTarget); 146 | var val = decodeURIComponent($a.attr('href')); 147 | 148 | if (val.indexOf('tel:') === 0) { 149 | e.preventDefault(); 150 | $('#dialog-dial').addClass('active') 151 | .find('.dial-input') 152 | .val(val.slice('tel:'.length)); 153 | 154 | } else if (val.indexOf('sms:') === 0) { 155 | e.preventDefault(); 156 | $('#dialog-sms').addClass('active') 157 | .find('.dial-input') 158 | .val(val.slice('tel:'.length)); 159 | } 160 | }) 161 | } 162 | 163 | 164 | $(document).ready(function() { 165 | setupDialogs(); 166 | setupAudioPlayers(); 167 | setupDialDialog(); 168 | setupLinks(); 169 | }); 170 | -------------------------------------------------------------------------------- /public/less/audioplayer.less: -------------------------------------------------------------------------------- 1 | .audio-player { 2 | background: #eee; 3 | width: 300px; 4 | overflow: hidden; 5 | 6 | .audio-inner { 7 | .flex-display(flex); 8 | .flex-direction(row); 9 | .align-items(stretch); 10 | } 11 | 12 | button { 13 | padding: 4px 14px; 14 | .flex-grow(1); 15 | } 16 | 17 | .position { 18 | .flex-grow(2); 19 | padding: 0px 10px; 20 | line-height: 38px; 21 | font-size: 16px; 22 | } 23 | 24 | .do-pause, .do-stop { 25 | display: none; 26 | } 27 | 28 | &.playing { 29 | .do-pause, .do-stop { 30 | display: block; 31 | } 32 | .do-play { 33 | display: none; 34 | } 35 | } 36 | &.paused { 37 | .do-play, .do-stop { 38 | display: block; 39 | } 40 | .do-pause { 41 | display: hidden; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /public/less/dialogs.less: -------------------------------------------------------------------------------- 1 | .dialog-container { 2 | position: fixed; 3 | top: 0px; 4 | bottom: 0px; 5 | right: 0px; 6 | left: 0px; 7 | 8 | background: rgba(0, 0, 0, 0.7); 9 | 10 | display: none; 11 | overflow: auto; 12 | 13 | &.active { 14 | display: block; 15 | } 16 | 17 | .dialog { 18 | width: 400px; 19 | margin: 40px auto; 20 | 21 | background: #eee; 22 | box-shadow: 0 0 2px rgba(0,0,0,.12),0 2px 4px rgba(0,0,0,.24); 23 | 24 | .dialog-inner { 25 | padding: 20px; 26 | text-align: center; 27 | 28 | .dialog-intro { 29 | margin-bottom: 20px; 30 | 31 | h1 { 32 | font-size: 1.2rem; 33 | font-weight: 400; 34 | margin-bottom: 1rem; 35 | } 36 | 37 | p { 38 | color: #666; 39 | } 40 | } 41 | } 42 | 43 | .dialog-controls { 44 | width: 100%; 45 | .flex-display(flex); 46 | .flex-direction(row); 47 | .align-items(stretch); 48 | 49 | button { 50 | .flex-grow(2); 51 | } 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /public/less/forms.less: -------------------------------------------------------------------------------- 1 | .form { 2 | 3 | } 4 | 5 | .form-control { 6 | width: 100%; 7 | margin-bottom: 10px; 8 | padding: 8px; 9 | font-size: 1.1rem; 10 | border: 1px solid #ddd; 11 | } 12 | 13 | button, .button { 14 | background: #fff; 15 | border-radius: 0px; 16 | border: 1px solid #eee; 17 | font-size: 16px; 18 | cursor: pointer; 19 | color: #222; 20 | padding: 14px; 21 | text-decoration: none; 22 | 23 | &:hover { 24 | color: #000; 25 | } 26 | } 27 | 28 | .dialpad { 29 | margin-left: -6px; 30 | margin-right: -6px; 31 | 32 | table { 33 | width: 100%; 34 | border-spacing: 6px; 35 | 36 | input { 37 | width: 100%; 38 | .button(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /public/less/list.less: -------------------------------------------------------------------------------- 1 | .list { 2 | width: 100%; 3 | background: #fff; 4 | 5 | tr { 6 | 7 | td { 8 | padding: 14px 10px; 9 | border-bottom: 1px solid #ececec; 10 | vertical-align: middle; 11 | line-height: 24px; 12 | 13 | a { 14 | text-decoration: none; 15 | color: inherit; 16 | 17 | &:focus, &:hover { 18 | text-decoration: underline; 19 | } 20 | } 21 | 22 | &.list-icon { 23 | text-align: center; 24 | } 25 | 26 | i { 27 | font-size: 24px; 28 | display: inline-block; 29 | 30 | &.secondary { 31 | font-size: 14px; 32 | } 33 | } 34 | 35 | .help { 36 | color: #aaa; 37 | } 38 | 39 | &.list-actions { 40 | text-align: center; 41 | 42 | a { 43 | display: inline-block; 44 | padding: 0px 8px; 45 | color: #aaa; 46 | 47 | &:hover { 48 | color: #555; 49 | } 50 | } 51 | } 52 | 53 | &.list-alternate { 54 | background: #f5f5f5; 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /public/less/main.less: -------------------------------------------------------------------------------- 1 | @import "./variables.less"; 2 | @import "./reset.less"; 3 | @import "./mixins.less"; 4 | 5 | @import "./list.less"; 6 | @import "./panels.less"; 7 | @import "./navigation.less"; 8 | @import "./tooltips.less"; 9 | @import "./dialogs.less"; 10 | @import "./forms.less"; 11 | @import "./audioplayer.less"; 12 | @import "./pagination.less"; 13 | 14 | 15 | * { 16 | box-sizing: border-box; 17 | } 18 | 19 | body { 20 | background-color: #e5e5e5; 21 | font: normal 13px Roboto,arial,sans-serif; 22 | height: 100%; 23 | margin: 0; 24 | padding: 15px 0px; 25 | overflow-y: scroll; 26 | visibility: visible; 27 | } 28 | 29 | .container { 30 | max-width: @container-width; 31 | width: 100%; 32 | margin: 0px auto; 33 | } 34 | 35 | .text-success { 36 | color: @color-green; 37 | } 38 | 39 | .text-error { 40 | color: @color-red; 41 | } -------------------------------------------------------------------------------- /public/less/mixins.less: -------------------------------------------------------------------------------- 1 | .clearfix{ 2 | zoom:1; 3 | &:before, &:after{ content:""; display:table; } 4 | &:after{ clear: both; } 5 | } 6 | 7 | .hidden { 8 | display: none; 9 | } 10 | 11 | // -------------------------------------------------- 12 | // Flexbox LESS mixins 13 | // The spec: http://www.w3.org/TR/css3-flexbox 14 | // -------------------------------------------------- 15 | 16 | // Flexbox display 17 | // flex or inline-flex 18 | .flex-display(@display: flex) { 19 | display: ~"-webkit-@{display}"; 20 | display: ~"-moz-@{display}"; 21 | display: ~"-ms-@{display}box"; // IE10 uses -ms-flexbox 22 | display: ~"-ms-@{display}"; // IE11 23 | display: @display; 24 | } 25 | 26 | // The 'flex' shorthand 27 | // - applies to: flex items 28 | // , initial, auto, or none 29 | .flex(@columns: initial) { 30 | -webkit-flex: @columns; 31 | -moz-flex: @columns; 32 | -ms-flex: @columns; 33 | flex: @columns; 34 | } 35 | 36 | // Flex Flow Direction 37 | // - applies to: flex containers 38 | // row | row-reverse | column | column-reverse 39 | .flex-direction(@direction: row) { 40 | -webkit-flex-direction: @direction; 41 | -moz-flex-direction: @direction; 42 | -ms-flex-direction: @direction; 43 | flex-direction: @direction; 44 | } 45 | 46 | // Flex Line Wrapping 47 | // - applies to: flex containers 48 | // nowrap | wrap | wrap-reverse 49 | .flex-wrap(@wrap: nowrap) { 50 | -webkit-flex-wrap: @wrap; 51 | -moz-flex-wrap: @wrap; 52 | -ms-flex-wrap: @wrap; 53 | flex-wrap: @wrap; 54 | } 55 | 56 | // Flex Direction and Wrap 57 | // - applies to: flex containers 58 | // || 59 | .flex-flow(@flow) { 60 | -webkit-flex-flow: @flow; 61 | -moz-flex-flow: @flow; 62 | -ms-flex-flow: @flow; 63 | flex-flow: @flow; 64 | } 65 | 66 | // Display Order 67 | // - applies to: flex items 68 | // 69 | .flex-order(@order: 0) { 70 | -webkit-order: @order; 71 | -moz-order: @order; 72 | -ms-order: @order; 73 | order: @order; 74 | } 75 | 76 | // Flex grow factor 77 | // - applies to: flex items 78 | // 79 | .flex-grow(@grow: 0) { 80 | -webkit-flex-grow: @grow; 81 | -moz-flex-grow: @grow; 82 | -ms-flex-grow: @grow; 83 | flex-grow: @grow; 84 | } 85 | 86 | // Flex shrink 87 | // - applies to: flex item shrink factor 88 | // 89 | .flex-shrink(@shrink: 1) { 90 | -webkit-flex-shrink: @shrink; 91 | -moz-flex-shrink: @shrink; 92 | -ms-flex-shrink: @shrink; 93 | flex-shrink: @shrink; 94 | } 95 | 96 | // Flex basis 97 | // - the initial main size of the flex item 98 | // - applies to: flex itemsnitial main size of the flex item 99 | // 100 | .flex-basis(@width: auto) { 101 | -webkit-flex-basis: @width; 102 | -moz-flex-basis: @width; 103 | -ms-flex-basis: @width; 104 | flex-basis: @width; 105 | } 106 | 107 | // Axis Alignment 108 | // - applies to: flex containers 109 | // flex-start | flex-end | center | space-between | space-around 110 | .justify-content(@justify: flex-start) { 111 | -webkit-justify-content: @justify; 112 | -moz-justify-content: @justify; 113 | -ms-justify-content: @justify; 114 | justify-content: @justify; 115 | } 116 | 117 | // Packing Flex Lines 118 | // - applies to: multi-line flex containers 119 | // flex-start | flex-end | center | space-between | space-around | stretch 120 | .align-content(@align: stretch) { 121 | -webkit-align-content: @align; 122 | -moz-align-content: @align; 123 | -ms-align-content: @align; 124 | align-content: @align; 125 | } 126 | 127 | // Cross-axis Alignment 128 | // - applies to: flex containers 129 | // flex-start | flex-end | center | baseline | stretch 130 | .align-items(@align: stretch) { 131 | -webkit-align-items: @align; 132 | -moz-align-items: @align; 133 | -ms-align-items: @align; 134 | align-items: @align; 135 | } 136 | 137 | // Cross-axis Alignment 138 | // - applies to: flex items 139 | // auto | flex-start | flex-end | center | baseline | stretch 140 | .align-self(@align: auto) { 141 | -webkit-align-self: @align; 142 | -moz-align-self: @align; 143 | -ms-align-self: @align; 144 | align-self: @align; 145 | } 146 | -------------------------------------------------------------------------------- /public/less/navigation.less: -------------------------------------------------------------------------------- 1 | .navigation { 2 | width: 100%; 3 | .flex-display(flex); 4 | .flex-direction(row); 5 | .align-items(stretch); 6 | 7 | .tab { 8 | border-bottom: 4px solid transparent; 9 | text-align: center; 10 | text-transform: uppercase; 11 | font-size: 1rem; 12 | text-decoration: none; 13 | 14 | &.active { 15 | border-bottom-color: @color-blue; 16 | } 17 | 18 | &.tab-link { 19 | color: #999; 20 | font-weight: 300; 21 | padding: 14px; 22 | .flex-grow(2); 23 | } 24 | 25 | &.tab-action { 26 | font-size: 24px; 27 | color: inherit; 28 | text-decoration: none; 29 | padding: 0px 14px; 30 | line-height: 50px; 31 | color: #999; 32 | 33 | i { 34 | display: inline-block; 35 | } 36 | 37 | &:hover { 38 | text-decoration: none; 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /public/less/pagination.less: -------------------------------------------------------------------------------- 1 | .pagination { 2 | .clearfix(); 3 | 4 | .next { 5 | float: right; 6 | } 7 | 8 | .previous { 9 | float: left; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /public/less/panels.less: -------------------------------------------------------------------------------- 1 | .panel { 2 | margin: 20px 0px; 3 | box-shadow: 0 0 2px rgba(0,0,0,.12),0 2px 4px rgba(0,0,0,.24); 4 | } 5 | -------------------------------------------------------------------------------- /public/less/reset.less: -------------------------------------------------------------------------------- 1 | /** 2 | * Global Reset of all HTML Elements 3 | * 4 | * Resetting all of our HTML Elements ensures a smoother 5 | * visual transition between browsers. If you don't believe me, 6 | * try temporarily commenting out this block of code, then go 7 | * and look at Mozilla versus Safari, both good browsers with 8 | * a good implementation of CSS. The thing is, all browser CSS 9 | * defaults are different and at the end of the day if visual 10 | * consistency is what we're shooting for, then we need to 11 | * make sure we're resetting all spacing elements. 12 | * 13 | */ 14 | html, body { 15 | border: 0; 16 | font-family: "Helvetica-Neue", "Helvetica", Arial, sans-serif; 17 | line-height: 1.5; 18 | margin: 0; 19 | padding: 0; 20 | } 21 | 22 | div, span, object, iframe, img, table, caption, thead, tbody, 23 | tfoot, tr, tr, td, article, aside, canvas, details, figure, hgroup, menu, 24 | nav, footer, header, section, summary, mark, audio, video { 25 | border: 0; 26 | margin: 0; 27 | padding: 0; 28 | } 29 | 30 | h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, address, cit, code, 31 | del, dfn, em, ins, q, samp, small, strong, sub, sup, b, i, hr, dl, dt, dd, 32 | ol, ul, li, fieldset, legend, label { 33 | border: 0; 34 | font-size: 100%; 35 | vertical-align: baseline; 36 | margin: 0; 37 | padding: 0; 38 | } 39 | 40 | article, aside, canvas, figure, figure img, figcaption, hgroup, 41 | footer, header, nav, section, audio, video { 42 | display: block; 43 | } 44 | 45 | table { 46 | border-collapse: separate; 47 | border-spacing: 0; 48 | caption, th, td { 49 | text-align: left; 50 | vertical-align: middle; 51 | } 52 | } 53 | 54 | a img { 55 | border: 0; 56 | } 57 | 58 | :focus { 59 | outline: 0; 60 | } -------------------------------------------------------------------------------- /public/less/tooltips.less: -------------------------------------------------------------------------------- 1 | .tooltip { 2 | display: inline; 3 | position: relative; 4 | 5 | &:hover { 6 | &:after { 7 | line-height: 1em; 8 | background: #111; 9 | background: rgba(0,0,0,.9); 10 | border-radius: 1px; 11 | bottom: ~"calc(100% + 10px)"; 12 | color: #fff; 13 | content: attr(title); 14 | display: block; 15 | left: 5px; 16 | padding: 5px 5px; 17 | position: absolute; 18 | text-shadow: 0 1px 0 #000; 19 | white-space: nowrap; 20 | z-index: 98; 21 | font-size: 13px; 22 | text-transform: none; 23 | } 24 | 25 | &:before { 26 | border: solid; 27 | border-color: #111 transparent; 28 | border-color: rgba(0,0,0,.9) transparent; 29 | border-width: 5px 5px 0px 5px; 30 | bottom: ~"calc(100% + 5px)"; 31 | content: ""; 32 | display: block; 33 | left: 10px; 34 | position: absolute; 35 | z-index: 99; 36 | } 37 | } 38 | 39 | &.tooltip-bottom { 40 | &:after { 41 | bottom:auto; 42 | top: ~"calc(100% + 10px)"; 43 | } 44 | &:before { 45 | bottom:auto; 46 | top: ~"calc(100% + 5px)"; 47 | border-width: 0px 5px 5px 5px; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /public/less/variables.less: -------------------------------------------------------------------------------- 1 | @container-width: 800px; 2 | 3 | // Colors 4 | @color-green: #5cb85c; 5 | @color-red: #d9534f; 6 | @color-blue: #0288d1; 7 | -------------------------------------------------------------------------------- /test/parser.js: -------------------------------------------------------------------------------- 1 | var expect = require('chai').expect; 2 | var parser = require('../lib/utils/parser'); 3 | 4 | describe('Messages Parser', function() { 5 | 6 | it('should correctly reject non betty message', function() { 7 | var r = parser.parse("Random message"); 8 | 9 | expect(r).to.not.be.ok; 10 | }); 11 | 12 | it('should correctly accept betty message', function() { 13 | var r = parser.parse("betty: Random message"); 14 | 15 | expect(r).to.be.ok; 16 | expect(r.type).to.equal("unknown"); 17 | }); 18 | 19 | it('should correctly parse a call action', function() { 20 | var r = parser.parse("betty: Call +140145170479"); 21 | 22 | expect(r).to.be.ok; 23 | expect(r.type).to.equal("call"); 24 | expect(r.phone).to.equal("+140145170479"); 25 | }); 26 | 27 | it('should correctly parse a text action', function() { 28 | var r = parser.parse("betty: Text +140145170479"); 29 | 30 | expect(r).to.be.ok; 31 | expect(r.type).to.equal("text"); 32 | expect(r.phone).to.equal("+140145170479"); 33 | }); 34 | 35 | it('should not parse a text action without phone', function() { 36 | var r = parser.parse("betty: Text hello"); 37 | 38 | expect(r).to.be.ok; 39 | expect(r.type).to.equal("unknown"); 40 | }); 41 | 42 | it('should correctly parse a stop action', function() { 43 | var r = parser.parse("betty: Stop this conversation"); 44 | 45 | expect(r).to.be.ok; 46 | expect(r.type).to.equal("stop"); 47 | }); 48 | 49 | it('should correctly handle other receptionist names', function() { 50 | var r = parser.parse("ben: Stop this conversation", { receptionist: "Ben" }); 51 | 52 | expect(r).to.be.ok; 53 | expect(r.type).to.equal("stop"); 54 | }); 55 | 56 | }); 57 | -------------------------------------------------------------------------------- /test/phones.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var expect = require('chai').expect; 4 | var phone = require('../lib/utils/phone'); 5 | 6 | describe('Phone', function() { 7 | 8 | it('should correctly valid numbers', function() { 9 | expect(phone.valid('+140145170479')).to.be.ok; 10 | expect(phone.valid('844-913-7443')).to.be.ok; 11 | expect(phone.valid('(844)-913-7443')).to.be.ok; 12 | }); 13 | 14 | it('should correctly detect invalid numbers', function() { 15 | expect(phone.valid('test')).to.not.be.ok; 16 | }); 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /views/calls.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% import "macros/pagination.html" as pagination %} 3 | {% import "macros/numbers.html" as numbers %} 4 | 5 | {% block title %}Calls{% endblock %} 6 | 7 | {% block body %} 8 |
9 | 10 | {% for call in calls.list %} 11 | 12 | 22 | 28 | 29 | 30 | 31 | 32 | {% endfor %} 33 |
13 |
14 | 15 | {% if call.direction == "outbound" %} 16 | 17 | {% else %} 18 | 19 | {% endif %} 20 |
21 |
23 | {{ numbers.item(call.from) }} 24 | {% if call.forwardedFrom %} 25 |

Forwarded by {{ numbers.item(call.forwardedFrom) }}

26 | {% endif %} 27 |
{{ numbers.item(call.to) }}{{ call.startTime|relativeDate }}{{ call.duration }}s
34 |
35 | {{ pagination.nav(calls) }} 36 | {% endblock %} -------------------------------------------------------------------------------- /views/dialogs/dial.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |

New Call

6 |

Who do you want to call?

7 |
8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 |
33 |
34 |
35 |
36 | 37 | 38 |
39 |
40 |
-------------------------------------------------------------------------------- /views/dialogs/sms.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
6 |

New Text Message

7 |

Please enter a phone number and your message.

8 |
9 | 10 | 11 |
12 |
13 | 14 | 15 |
16 |
17 |
18 |
-------------------------------------------------------------------------------- /views/layout.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {% block title %}Welcome{% endblock %} - {{ profile.name }} 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 28 | {% block body %}{% endblock %} 29 |
30 | 31 | {% include "dialogs/sms.html" %} 32 | {% include "dialogs/dial.html" %} 33 | 34 | 35 | 36 | 37 | {% block script %}{% endblock %} 38 | 39 | -------------------------------------------------------------------------------- /views/macros/audio.html: -------------------------------------------------------------------------------- 1 | {% macro player(src) %} 2 |
3 |
4 | 5 | 6 | 7 |
0:0
8 | 12 |
13 |
14 | {% endmacro %} -------------------------------------------------------------------------------- /views/macros/numbers.html: -------------------------------------------------------------------------------- 1 | {% macro callUrl(num) %}tel:{{ num|urlencode }}{% endmacro %} 2 | {% macro smsUrl(num) %}sms:{{ num|urlencode }}{% endmacro %} 3 | 4 | {% macro item(num) %} 5 | {% if num.member %} 6 | {% if not num.member.machine %} 7 | 8 | {% endif %} 9 | {{ num.member.name }} 10 | {% elif num.alias %} 11 | {{ num.alias }} 12 | {% else %} 13 | {{ num.phone }} 14 | {% endif %} 15 | {% endmacro %} -------------------------------------------------------------------------------- /views/macros/pagination.html: -------------------------------------------------------------------------------- 1 | {% macro nav(list) %} 2 | 14 | {% endmacro %} -------------------------------------------------------------------------------- /views/recordings.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% import "macros/pagination.html" as pagination %} 3 | {% import "macros/audio.html" as audio %} 4 | 5 | {% block title %}Recordings{% endblock %} 6 | 7 | {% block body %} 8 |
9 | 10 | {% for rc in recordings.list %} 11 | 12 | 17 | 18 | 19 | 22 | 23 | {% endfor %} 24 |
13 |
14 | 15 |
16 |
{{ rc.createdTime|relativeDate }}{{ rc.duration }}s 20 | {{ audio.player(rc.urls.mp3) }} 21 |
25 |
26 | {{ pagination.nav(recordings) }} 27 | {% endblock %} -------------------------------------------------------------------------------- /views/sms.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% import "macros/pagination.html" as pagination %} 3 | {% import "macros/numbers.html" as numbers %} 4 | 5 | {% block title %}Messages{% endblock %} 6 | 7 | {% block body %} 8 | {% for sms in messages.list %} 9 |
10 | 11 | 12 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 |
13 |
14 | 15 | {% if sms.direction == "outbound" %} 16 | 17 | {% else %} 18 | 19 | {% endif %} 20 |
21 |
{{ numbers.item(sms.from) }}{{ numbers.item(sms.to) }}{{ sms.sentTime|relativeDate }} 26 | 27 | 28 | 29 |
{{ sms.body|nl2br }}
35 |
36 | {% endfor %} 37 | {{ pagination.nav(messages) }} 38 | {% endblock %} 39 | -------------------------------------------------------------------------------- /views/status.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% import "macros/numbers.html" as numbers %} 3 | 4 | {% block title %}Status{% endblock %} 5 | 6 | {% block body %} 7 |
8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | 22 | 23 | 24 | 27 | 28 | 29 | 30 |
11 | 12 | Receptionist{{ account.profile.name }}
18 | 19 | Running since{{ account.startTime|relativeDate }}
25 | 26 | Language{{ account.profile.language }}
31 |
32 | 33 |
34 | 35 | {% for name, usage in account.usages %} 36 | {% if usage.label %} 37 | 38 | 41 | 42 | 43 | 44 | 45 | {% endif %} 46 | {% endfor %} 47 |
39 | 40 | {{ usage.label.title }}{% if usage.label.unit %}{{ usage.value }} {{ usage.label.unit }}{% endif %}${{ usage.price }}
48 |
49 | {% endblock %} -------------------------------------------------------------------------------- /views/team.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% import "macros/numbers.html" as numbers %} 3 | 4 | {% block title %}Team{% endblock %} 5 | 6 | {% block body %} 7 |
8 | 9 | {% for user in team %} 10 | 11 | 20 | 21 | 22 | 23 | 31 | 32 | {% endfor %} 33 |
12 |
13 | {% if user.machine %} 14 | 15 | {% else %} 16 | 17 | {% endif %} 18 |
19 |
{{ user.name }}{{ user.username }}{{ user.phone }} 24 | 25 | 26 | 27 | 28 | 29 | 30 |
34 |
35 | {% endblock %} --------------------------------------------------------------------------------