From 71a55ab15204c27c2a86ef9f0b6ad868daa6fb00 Mon Sep 17 00:00:00 2001 From: Diana Lozano Date: Wed, 17 Aug 2016 12:39:30 -0500 Subject: [PATCH 1/7] file name sample to example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 869aed3..8bfc2f1 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ This should install all of our project dependencies from npm into a local ### Configuration -Next, open `.env.sample` at the root of the project and update it with +Next, open `.env.example` at the root of the project and update it with values from your [Twilio account](https://www.twilio.com/user/account/voice-messaging) and local configuration. Save the file as `.env`. You'll need to set From 9431e6e176b803511f8b60acb4d71006ba6475ca Mon Sep 17 00:00:00 2001 From: Hector Ortega Date: Fri, 25 Nov 2016 05:30:23 -0500 Subject: [PATCH 2/7] Bump Twilio version and update code --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5a25be7..4547405 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "express-session": "^1.10.3", "morgan": "^1.5.1", "sanitize-html": "^1.10.0", - "twilio": "^1.11.1", + "twilio": "3.0.0-rc.13", "underscore": "^1.8.3" }, "devDependencies": { From 7919de560e22e16e6722e301069dfdd794f218a6 Mon Sep 17 00:00:00 2001 From: Hector Ortega Date: Fri, 25 Nov 2016 05:30:27 -0500 Subject: [PATCH 3/7] Update Readme.md to comply with standard --- README.md | 96 ++++++++++++++++++++++++++----------------------- twilioClient.js | 16 ++++----- 2 files changed, 60 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 8bfc2f1..84dd129 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ + + Twilio + + # Server notifications with Twilio, Node.js, and Express [![Build Status](https://travis-ci.org/TwilioDevEd/call-tracking-node.svg?branch=master)](https://travis-ci.org/TwilioDevEd/server-notifications-node) @@ -6,66 +10,70 @@ Use Twilio to send SMS alerts so that you never miss a critical issue. [Read the full tutorial here](https://www.twilio.com/docs/tutorials/walkthrough/server-notifications/node/express)! -## Running the Project on Your Machine +## Local development -To run this project on your computer, download or clone the source. You will -also need to download and install either [Node.js](http://nodejs.org/) -or [io.js](https://iojs.org/en/index.html), both of which should also install -[npm](https://www.npmjs.com/). +To run this project on your computer you will + need to download and install either [Node.js](http://nodejs.org/) +or [io.js](https://iojs.org/en/index.html), both of which should also install +[npm](https://www.npmjs.com/). -You will also need to [sign up for a Twilio account](https://www.twilio.com/try-twilio) +You will also need to [sign up for a Twilio account](https://www.twilio.com/try-twilio) if you don't have one already. -### Install Dependencies +1. First clone this repository and `cd` into it. -Navigate to the project directory in your terminal and run: + ```bash + $ git clone git@github.com:TwilioDevEd/server-notifications-node.git + $ cd server-notifications-node + ``` -```bash -npm install -``` +1. Next, open `.env.example` at the root of the project and update it with + values from your + [Twilio account](https://www.twilio.com/user/account/voice-messaging) + and local configuration. Save the file as `.env`. You'll need to set + `TWILIO_AUTH_TOKEN`, `TWILIO_ACCOUNT_SID`, and `TWILIO_NUMBER`. -This should install all of our project dependencies from npm into a local -`node_modules` folder. + For the `TWILIO_NUMBER` variable you'll need to provision a new number + in the + [Manage Numbers page](https://www.twilio.com/user/account/phone-numbers/incoming) + under your account. The phone number should be in + [E.164 format](https://www.twilio.com/help/faq/phone-numbers/how-do-i-format-phone-numbers-to-work-internationally) -### Configuration + Run `source .env` to export the environment variables. -Next, open `.env.example` at the root of the project and update it with -values from your -[Twilio account](https://www.twilio.com/user/account/voice-messaging) -and local configuration. Save the file as `.env`. You'll need to set -`TWILIO_AUTH_TOKEN`, `TWILIO_ACCOUNT_SID`, and `TWILIO_NUMBER`. +1. Navigate to the project directory in your terminal and run: -For the `TWILIO_NUMBER` variable you'll need to provision a new number -in the -[Manage Numbers page](https://www.twilio.com/user/account/phone-numbers/incoming) -under your account. The phone number should be in -[E.164 format](https://www.twilio.com/help/faq/phone-numbers/how-do-i-format-phone-numbers-to-work-internationally) + ```bash + npm install + ``` -### Running the Project + This should install all of our project dependencies from npm into a local + `node_modules` folder. -To launch the application, you can use `node .` in the project's root directory. -You might also consider using [nodemon](https://github.com/remy/nodemon) for -this. It works just like the node command, but automatically restarts your -application when you change any source code files. +1. Make sure the tests succeed. -Make sure you have customized the `config/administrators.json` file -with your phone number and then open -[http://localhost:3000/error](http://localhost:3000/error). You'll get a text message shortly -informing you of an exception. + ```bash + $ npm test + ``` -```bash -npm install -g nodemon -nodemon . -``` +1. To launch the application, you can use `node .` in the project's root directory. + You might also consider using [nodemon](https://github.com/remy/nodemon) for + this. It works just like the node command, but automatically restarts your + application when you change any source code files. -### Running Tests + Make sure you have customized the `config/administrators.json` file + with your phone number and then open + [http://localhost:3000/error](http://localhost:3000/error). You'll get a text message shortly + informing you of an exception. -Basic functional tests can be run with: + ```bash + npm install -g nodemon + nodemon . + ``` -```bash -npm test -``` -## License +## Meta -MIT +* No warranty expressed or implied. Software is as is. Diggity. +* [MIT License](http://www.opensource.org/licenses/mit-license.html) +* Lovingly crafted by Twilio Developer Education. diff --git a/twilioClient.js b/twilioClient.js index 3120292..bff1897 100644 --- a/twilioClient.js +++ b/twilioClient.js @@ -6,13 +6,13 @@ module.exports.sendSms = function(to, message) { body: message, to: to, from: config.sendingNumber - // mediaUrl: 'http://www.yourserver.com/someimage.png' - }, function(err, data) { - if (err) { - console.error('Could not notify administrator'); - console.error(err); - } else { - console.log('Administrator notified'); - } +// mediaUrl: imageUrl + }) + .then(function(data) { + console.log('Administrator notified'); + }) + .catch(function(err) { + console.error('Could not notify administrator'); + console.error(err); }); }; From 79ca9fd19f72d2568dbe1851b2bfe23d28bf9145 Mon Sep 17 00:00:00 2001 From: Hector Ortega Date: Fri, 25 Nov 2016 05:30:29 -0500 Subject: [PATCH 4/7] Update deps and minor format change --- package.json | 8 ++++---- twilioClient.js | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 4547405..c7cd1bd 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "body-parser": "^1.12.0", "connect-flash": "^0.1.1", "csurf": "^1.8.3", - "dotenv": "^1.2.0", + "dotenv": "^2.0.0", "express": "^4.12.0", "express-session": "^1.10.3", "morgan": "^1.5.1", @@ -38,8 +38,8 @@ "underscore": "^1.8.3" }, "devDependencies": { - "chai": "^2.1.0", - "mocha": "^2.3.0", - "supertest": "^1.1.0" + "chai": "^3.5.0", + "mocha": "^3.1.2", + "supertest": "^2.0.1" } } diff --git a/twilioClient.js b/twilioClient.js index bff1897..6058cf1 100644 --- a/twilioClient.js +++ b/twilioClient.js @@ -7,11 +7,9 @@ module.exports.sendSms = function(to, message) { to: to, from: config.sendingNumber // mediaUrl: imageUrl - }) - .then(function(data) { + }).then(function(data) { console.log('Administrator notified'); - }) - .catch(function(err) { + }).catch(function(err) { console.error('Could not notify administrator'); console.error(err); }); From b370d353105b462b564a3826f7a60537bf558660 Mon Sep 17 00:00:00 2001 From: Hector Ortega Date: Fri, 25 Nov 2016 05:30:32 -0500 Subject: [PATCH 5/7] Remove protocol from links and update 'Did this help' section on index.jade --- tutorial/index.jade | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/tutorial/index.jade b/tutorial/index.jade index 1fb0fdf..534fad7 100644 --- a/tutorial/index.jade +++ b/tutorial/index.jade @@ -3,12 +3,12 @@ :markdown ## What does this thing do? - This [Express.js](http://expressjs.com/) sample application + This [Express.js](//expressjs.com/) sample application demonstrates how to send SMS alerts to a list of system administrators if something goes wrong on your server. In this tutorial, we'll show you the key bits of code to make this work. Head to the [application's - README.md](https://github.com/TwilioDevEd/server-notifications-node) + README.md](//github.com/TwilioDevEd/server-notifications-node) to see how to run the application locally. Let's get started! @@ -16,15 +16,15 @@ --- **See Also:** - * [Getting started with Express.js](http://expressjs.com/starter/hello-world.html) - * [twilio-node library](http://twilio.github.io/twilio-node/) + * [Getting started with Express.js](//expressjs.com/starter/hello-world.html) + * [twilio-node library](//twilio.github.io/twilio-node/) .step(data-file='config.js', data-highlight='23-45') :markdown ## Configure Twilio client In order to send messages we'll need to create a [Twilio REST - client](http://twilio.github.io/twilio-node/#quickstart), which + client](//twilio.github.io/twilio-node/#quickstart), which requires reading our `TWILIO_ACCOUNT_SID`, `TWILIO_NUMBER` `TWILIO_AUTH_TOKEN` from the enviroment. We also make the variables available through the `config` module. @@ -32,8 +32,8 @@ --- **See Also:** - * [twilio-node Quickstart](http://twilio.github.io/twilio-node/#quickstart) - * [Twilio REST Web Service Interface](https://www.twilio.com/docs/api/rest) + * [twilio-node Quickstart](//twilio.github.io/twilio-node/#quickstart) + * [Twilio REST Web Service Interface](//www.twilio.com/docs/api/rest) .step(data-file='config/administrators.json') :markdown @@ -49,20 +49,20 @@ We will implement error handling and message delivery as a piece of [Express.js - middleware](http://expressjs.com/guide/using-middleware.html). We + middleware](//expressjs.com/guide/using-middleware.html). We will make all the Twilio API calls from there. --- **See Also:** - * [Error handling middleware](http://expressjs.com/guide/using-middleware.html#middleware.error-handling) + * [Error handling middleware](//expressjs.com/guide/using-middleware.html#middleware.error-handling) .step(data-file='middleware/twilioNotifications.js') :markdown ## Trigger notifications for administrator list In our Express middleware module, we read the admins from our JSON file - and send alert messages to each of them with the `sendSms` method in + and send alert messages to each of them with the `sendSms` method in `twilioClient`. We also call `next` with the error object, which will allow other configured error handling middleware to execute. @@ -71,43 +71,41 @@ ## Send a text message There are the three parameters needed to [send an - SMS](http://twilio.github.io/twilio-node/#moreexamples) + SMS](//twilio.github.io/twilio-node/#moreexamples) using the [Twilio REST - API](https://www.twilio.com/docs/api/rest): `From`, `To`, and + API](//www.twilio.com/docs/api/rest): `From`, `To`, and `Body`. [US and Canadian phone - numbers](https://www.twilio.com/help/faq/sms/is-mms-supported-for-all-carriers-in-us-and-canada) + numbers](//www.twilio.com/help/faq/sms/is-mms-supported-for-all-carriers-in-us-and-canada) can also send an image with the message. --- **See Also:** - * [REST API Docs for Message resource](https://www.twilio.com/docs/api/rest/message) - * [Your message logs in the account portal](https://www.twilio.com/user/account/log/messages) + * [REST API Docs for Message resource](//www.twilio.com/docs/api/rest/message) + * [Your message logs in the account portal](//www.twilio.com/user/account/log/messages) .step :markdown ## Where to next? - That's it! We've just implemented an automated server notification system + That's it! We've just implemented an automated server notification system that can send you server alerts if anything goes wrong. If you're a Node.js developer working with Twilio, you might want to check out these other tutorials. - [**Two-Factor Authentication**](https://www.twilio.com/docs/howto/walkthrough/two-factor-authentication/node/express) + [**Two-Factor Authentication**](//www.twilio.com/docs/howto/walkthrough/two-factor-authentication/node/express) Increase the security of your login system by verifying a user's mobile phone in addition to their password. - [**SMS and MMS marketing notifications**](https://www.twilio.com/docs/howto/walkthrough/marketing-notifications/node/express) + [**SMS and MMS marketing notifications**](//www.twilio.com/docs/howto/walkthrough/marketing-notifications/node/express) SMS and MMS messages are a personal way to engage with users, offering a much higher open rate than e-mail and more impact than a tweet. - ### Did this help? - Thanks for checking out this tutorial! If you have any feedback to share - with us, we'd love to hear it. Tweet [@twilio](http://twitter.com/twilio) - to let us know what you think. - + Thanks for checking out this tutorial! If you have any feedback + to share with us, we'd love to hear it. [Contact the Twilio Developer + Education Team](mailto:deved-oss@twilio.com) to let us know what you think. From 654bf8913bcda06c761e39dc9e11f88e6c05f346 Mon Sep 17 00:00:00 2001 From: Hector Ortega Date: Fri, 25 Nov 2016 05:30:35 -0500 Subject: [PATCH 6/7] Reinstate mediaUrl parameter on twilioClient and minor fix on Readme --- README.md | 6 +++--- twilioClient.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 84dd129..8ef6a69 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ if you don't have one already. 1. Navigate to the project directory in your terminal and run: ```bash - npm install + $ npm install ``` This should install all of our project dependencies from npm into a local @@ -67,8 +67,8 @@ if you don't have one already. informing you of an exception. ```bash - npm install -g nodemon - nodemon . + $ npm install -g nodemon + $ nodemon . ``` diff --git a/twilioClient.js b/twilioClient.js index 6058cf1..83efa01 100644 --- a/twilioClient.js +++ b/twilioClient.js @@ -5,8 +5,8 @@ module.exports.sendSms = function(to, message) { client.messages.create({ body: message, to: to, - from: config.sendingNumber -// mediaUrl: imageUrl + from: config.sendingNumber, + mediaUrl: imageUrl }).then(function(data) { console.log('Administrator notified'); }).catch(function(err) { From 4a3832463c5bf13dffad202c304921e5e0d837cf Mon Sep 17 00:00:00 2001 From: Hector Ortega Date: Fri, 25 Nov 2016 05:30:38 -0500 Subject: [PATCH 7/7] Minor modifications to Readme.md --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8ef6a69..3f6b795 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ if you don't have one already. 1. Next, open `.env.example` at the root of the project and update it with values from your - [Twilio account](https://www.twilio.com/user/account/voice-messaging) + [Twilio account](https://www.twilio.com/console) and local configuration. Save the file as `.env`. You'll need to set `TWILIO_AUTH_TOKEN`, `TWILIO_ACCOUNT_SID`, and `TWILIO_NUMBER`. @@ -43,18 +43,18 @@ if you don't have one already. 1. Navigate to the project directory in your terminal and run: - ```bash - $ npm install - ``` + ```bash + $ npm install + ``` This should install all of our project dependencies from npm into a local `node_modules` folder. 1. Make sure the tests succeed. - ```bash - $ npm test - ``` + ```bash + $ npm test + ``` 1. To launch the application, you can use `node .` in the project's root directory. You might also consider using [nodemon](https://github.com/remy/nodemon) for