Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up codebase #34

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
43 changes: 29 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Sample GroupMe NodeJS Callback Bot
# Sample GroupMe NodeJS Bot
[**Python**](https://github.com/groupme/bot-tutorial-python) | **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

Expand All @@ -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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heroku Toolbelt is now called Heroku CLI.


# Get your bot up and running<a name="deploy"></a>

Expand Down Expand Up @@ -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:<a name="get-bot-id"></a>

Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Syntax highlighting!

```

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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Foreman seems nonstandard

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.

4 changes: 2 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
@@ -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": []
}
20 changes: 10 additions & 10 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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) {
Expand All @@ -54,4 +54,4 @@ function postMessage() {
}


exports.respond = respond;
exports.respond = respond;
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ server.listen(port);
function ping() {
this.res.writeHead(200);
this.res.end("Hey, I'm Cool Guy.");
}
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "node-js-getting-started",
"name": "bot-tutorial",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was never changed from wherever it was copied from.

"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"
Expand All @@ -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"
}