From 980a4558453d859724bd917e2bde4a401caae7e7 Mon Sep 17 00:00:00 2001 From: ErikBoesen Date: Sun, 15 Sep 2019 01:10:38 -0400 Subject: [PATCH 1/7] Clean up README --- README.md | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index ca1961fed..5b5f1a24a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ -# Sample GroupMe NodeJS Callback Bot +# Sample GroupMe NodeJS Bot +[**Python**](https://github.com/groupme/bot-tutorial-nodejs) | **JavaScript** ## Introduction -This project shows the capability of a bot to react to messages sent within a group. +A simple GroupMe bot that reacts to messages sent in a group. ## Contents @@ -18,7 +19,7 @@ This project shows the capability of a bot to react to messages sent within a gr * GroupMe account * Heroku account - * [Heroku Toolbelt](https://toolbelt.heroku.com/) + * [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli) # Get your bot up and running @@ -55,10 +56,10 @@ Fill out the form to create your new bot: * Select the group where you want the bot to live * Give your bot a name - * Paste in the url to your newly deply heroku app + * Paste in the URL of your newly deployed Heroku app * `http://your-app-name-here.herokuapp.com/` - * (Optional) Give your bot an avatar by providing a url to an image - * Click submit + * (Optional) Give your bot an avatar by providing the URL of an image + * Click submit! ## Find your Bot ID: @@ -113,37 +114,51 @@ Go to GroupMe and type "/cool guy" in the group where your bot lives to see it i Within terminal, change directory to the location where you would like the files to live, then run this command: - $ heroku git:clone -a YOUR_APP_NAME_HERE +```sh +heroku git:clone -a YOUR_APP_NAME_HERE +``` And then change directory into the new folder - $ cd YOUR_APP_NAME_HERE +```sh +cd YOUR_APP_NAME_HERE +``` ## Configure your local BOT_ID environment variable Open the file `.env` from your local files in your text editor of choice. Find where it says "YOUR_BOT_ID_HERE" and replace it with the ID of your new bot. -If you don't know what your Bot ID is, please refer back to [this](#get-bot-id) section, -where it is explained how to retrieve it. +If you don't know what your Bot ID is, please refer back to [this](#get-bot-id) section, where it is explained how to retrieve it. If your Bot ID is 12345678910, then: - BOT_ID="YOUR_BOT_ID_HERE" +```sh +BOT_ID="YOUR_BOT_ID_HERE" +``` becomes: - BOT_ID="12345678910" +```sh +BOT_ID="12345678910" +``` ## Start the server To test your bot locally, open terminal and run the following command to start a local server. - $ foreman start +```sh +npm start +``` + +or + +```sh +node index.js +``` Then navigate to `http://127.0.0.1:5000/` in a browser. ![Local bot](http://i.groupme.com/502x133.png.f06c630467954f5dab4c742dc67b71bf) ## All done! Go play around and make the bot your own. - From 9d30bb14f6c04fec026b714f1bc42d001533ff90 Mon Sep 17 00:00:00 2001 From: ErikBoesen Date: Sun, 15 Sep 2019 01:10:52 -0400 Subject: [PATCH 2/7] Use correct content in app.json --- app.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.json b/app.json index 693c54cf0..e397ca55e 100644 --- a/app.json +++ b/app.json @@ -1,7 +1,7 @@ { "name": "Cool guy bot", - "description": "Basic Groupme Bot written in Node", - "repository": "https://github.com/petemcgrath/cool-guy-bot", + "description": "Basic GroupMe Bot written in Node.js", + "repository": "https://github.com/groupme/bot-tutorial-nodejs", "logo": "http://www.tailgate365.com/wp-content/uploads/2011/06/tom-hanks-906.jpg", "keywords": [] } From 5ce2ed5aa2afb3d2fbd977cf044d6d69d027d431 Mon Sep 17 00:00:00 2001 From: ErikBoesen Date: Sun, 15 Sep 2019 01:11:02 -0400 Subject: [PATCH 3/7] Clean up some JavaScript code --- bot.js | 20 ++++++++++---------- index.js | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bot.js b/bot.js index d04b04016..cb09a4e13 100644 --- a/bot.js +++ b/bot.js @@ -7,12 +7,12 @@ function respond() { var request = JSON.parse(this.req.chunks[0]), botRegex = /^\/cool guy$/; - if(request.text && botRegex.test(request.text)) { + if (request.text && botRegex.test(request.text)) { this.res.writeHead(200); postMessage(); this.res.end(); } else { - console.log("don't care"); + console.log('Received irrelevant message.'); this.res.writeHead(200); this.res.end(); } @@ -30,18 +30,18 @@ function postMessage() { }; body = { - "bot_id" : botID, - "text" : botResponse + 'bot_id' : botID, + 'text' : botResponse }; console.log('sending ' + botResponse + ' to ' + botID); botReq = HTTPS.request(options, function(res) { - if(res.statusCode == 202) { - //neat - } else { - console.log('rejecting bad status code ' + res.statusCode); - } + if(res.statusCode == 202) { + // Request was successful. + } else { + console.log('received bad status code ' + res.statusCode); + } }); botReq.on('error', function(err) { @@ -54,4 +54,4 @@ function postMessage() { } -exports.respond = respond; \ No newline at end of file +exports.respond = respond; diff --git a/index.js b/index.js index 672900471..07d700f73 100644 --- a/index.js +++ b/index.js @@ -30,4 +30,4 @@ server.listen(port); function ping() { this.res.writeHead(200); this.res.end("Hey, I'm Cool Guy."); -} \ No newline at end of file +} From ec15cb9aa69585380b47e63d63552444bafd4dbd Mon Sep 17 00:00:00 2001 From: ErikBoesen Date: Sun, 15 Sep 2019 01:11:23 -0400 Subject: [PATCH 4/7] Actually describe this project in package.json --- package.json | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 3f18ebf6c..1f17b7e24 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "node-js-getting-started", + "name": "bot-tutorial", "version": "0.1.2", - "description": "A sample Node.js app using Express 4", + "description": "A simple GroupMe bot written in Node.js", "main": "index.js", "scripts": { "start": "node index.js" @@ -15,12 +15,14 @@ }, "repository": { "type": "git", - "url": "https://github.com/heroku/node-js-getting-started" + "url": "https://github.com/groupme/bot-tutorial-nodejs" }, "keywords": [ "node", "heroku", - "express" + "express", + "groupme", + "bot" ], "license": "MIT" } From 3882d556b51c886b5879a44bc49833faeda93bbf Mon Sep 17 00:00:00 2001 From: ErikBoesen Date: Sun, 15 Sep 2019 01:23:10 -0400 Subject: [PATCH 5/7] Consistent spacing after if --- bot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot.js b/bot.js index cb09a4e13..90e70911e 100644 --- a/bot.js +++ b/bot.js @@ -37,7 +37,7 @@ function postMessage() { console.log('sending ' + botResponse + ' to ' + botID); botReq = HTTPS.request(options, function(res) { - if(res.statusCode == 202) { + if (res.statusCode == 202) { // Request was successful. } else { console.log('received bad status code ' + res.statusCode); From 48726b079f14d729747844e3ded6e9866232edac Mon Sep 17 00:00:00 2001 From: ErikBoesen Date: Sun, 15 Sep 2019 01:24:13 -0400 Subject: [PATCH 6/7] Link to Python --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b5f1a24a..0d37b1a4c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Sample GroupMe NodeJS Bot -[**Python**](https://github.com/groupme/bot-tutorial-nodejs) | **JavaScript** +[**Python**](https://github.com/groupme/bot-tutorial-python) | **JavaScript** ## Introduction From bb78a7949522462edb8656103a2be907aa5569d7 Mon Sep 17 00:00:00 2001 From: ErikBoesen Date: Sun, 15 Sep 2019 01:27:34 -0400 Subject: [PATCH 7/7] Add actual LICENSE --- LICENSE | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..c092a2636 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2019 GroupMe + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.