-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: roughing out chat-bot codebase
- Loading branch information
Benjamin Coe
committed
Oct 15, 2016
0 parents
commit 5dcf057
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.DS_Store | ||
node_modules | ||
.env | ||
.nyc_output | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const flip = require('flip') | ||
|
||
exports.command = 'flip <strings...>' | ||
|
||
exports.describe = "to davy jones' locker with ye" | ||
|
||
exports.builder = {} | ||
|
||
exports.handler = function (argv) { | ||
argv.respond(flip(argv.string.join(' '))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "pirate-joe", | ||
"version": "1.0.0", | ||
"description": "yargs' chat-bot", | ||
"main": "server.js", | ||
"scripts": { | ||
"test": "nyc mocha test.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/yargs/pirate-joe.git" | ||
}, | ||
"keywords": [ | ||
"chat-bot", | ||
"example" | ||
], | ||
"author": "Ben Coe <ben@npmjs.com>", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/yargs/pirate-joe/issues" | ||
}, | ||
"homepage": "https://github.com/yargs/pirate-joe#readme", | ||
"dependencies": { | ||
"body-parser": "^1.15.2", | ||
"dotenv": "^2.0.0", | ||
"express": "^4.14.0", | ||
"flip": "^1.0.0", | ||
"request": "^2.75.0", | ||
"yargs": "^6.1.0-candidate" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const express = require('express') | ||
const bodyParser = require('body-parser') | ||
|
||
if (process.env.NODE_ENV !== 'production') require('dotenv').config() | ||
|
||
const app = express() | ||
const parser = require('yargs') | ||
.commandDir('commands') | ||
.demand(1) | ||
.strict() | ||
.help() | ||
|
||
app.use(bodyParser.urlencoded({ extended: false })) | ||
|
||
app.post('/', function (req, res) { | ||
let context = Object.assign({}, req.body) | ||
|
||
context.respond = function (msg) { | ||
res.setHeader('Content-Type', 'application/json') | ||
res.send(JSON.stringify({ | ||
response_type: 'in_channel', | ||
text: msg | ||
})) | ||
} | ||
context.batman = Math.random() * 100 | ||
|
||
parser.parse(req.body.text || '', context, (err, argv, output) => { | ||
if (output) argv.respond(output) | ||
}) | ||
}) | ||
|
||
const port = process.env.PORT || 3000 | ||
app.listen(port, function (foo) { | ||
console.log('pirate joe bot listening on :' + port, 'beep boop') | ||
}) |