diff --git a/index.js b/index.js index 42355f0..b332bda 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,11 @@ require('dotenv').config() const express = require('express') const app = express() +const bodyParser = require('body-parser') const slackv1Router = require('./routes/slackv1-router') const {PORT} = process.env +app.use(bodyParser.urlencoded({extended:false})) app.use('/slack/v1',slackv1Router) app.listen(PORT, () => console.log(`server running on port: ${PORT}`)) \ No newline at end of file diff --git a/package.json b/package.json index 1bcb71a..0b0a86f 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "start:dev": "nodemon index.js" }, "dependencies": { + "body-parser": "^1.18.3", "dotenv": "^6.0.0", "express": "^4.16.3" }, diff --git a/routes/slackv1-router.js b/routes/slackv1-router.js index b4d1e6c..044942a 100644 --- a/routes/slackv1-router.js +++ b/routes/slackv1-router.js @@ -2,7 +2,16 @@ const express = require('express') const slackv1Router = express.Router() slackv1Router.post('/sassy', (req,res) => { - res.send('hello') -}) + const {text} = req.body + // 1. trim outside whitespace + // 2. capitalize + // 3. split by internal whitespace + // 4. append 👏🏾 to the end of each work + // 5. join back together + + const clapbackText = text.trim().toUpperCase().split(' ').map(word => `${word} :clap::skin-tone-5:`).join(' ') + console.log(clapbackText) + res.status(200).send(clapbackText) +}) module.exports = slackv1Router \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index c01dd38..36c916e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -118,6 +118,21 @@ body-parser@1.18.2: raw-body "2.3.2" type-is "~1.6.15" +body-parser@^1.18.3: + version "1.18.3" + resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.18.3.tgz#5b292198ffdd553b3a0f20ded0592b956955c8b4" + dependencies: + bytes "3.0.0" + content-type "~1.0.4" + debug "2.6.9" + depd "~1.1.2" + http-errors "~1.6.3" + iconv-lite "0.4.23" + on-finished "~2.3.0" + qs "6.5.2" + raw-body "2.3.3" + type-is "~1.6.16" + boxen@^1.2.1: version "1.3.0" resolved "https://registry.yarnpkg.com/boxen/-/boxen-1.3.0.tgz#55c6c39a8ba58d9c61ad22cd877532deb665a20b" @@ -675,7 +690,7 @@ http-errors@1.6.2: setprototypeof "1.0.3" statuses ">= 1.3.1 < 2" -http-errors@~1.6.2: +http-errors@1.6.3, http-errors@~1.6.2, http-errors@~1.6.3: version "1.6.3" resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.6.3.tgz#8b55680bb4be283a0b5bf4ea2e38580be1d9320d" dependencies: @@ -688,7 +703,7 @@ iconv-lite@0.4.19: version "0.4.19" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b" -iconv-lite@^0.4.4: +iconv-lite@0.4.23, iconv-lite@^0.4.4: version "0.4.23" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.23.tgz#297871f63be507adcfbfca715d0cd0eed84e9a63" dependencies: @@ -1302,6 +1317,10 @@ qs@6.5.1: version "6.5.1" resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8" +qs@6.5.2: + version "6.5.2" + resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36" + range-parser@~1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e" @@ -1315,6 +1334,15 @@ raw-body@2.3.2: iconv-lite "0.4.19" unpipe "1.0.0" +raw-body@2.3.3: + version "2.3.3" + resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.3.3.tgz#1b324ece6b5706e153855bc1148c65bb7f6ea0c3" + dependencies: + bytes "3.0.0" + http-errors "1.6.3" + iconv-lite "0.4.23" + unpipe "1.0.0" + rc@^1.0.1, rc@^1.1.6, rc@^1.2.7: version "1.2.8" resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed"