Skip to content

Commit

Permalink
feat: test: comput hmac value
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Liendo committed Jul 3, 2018
1 parent 69951a7 commit 327b1ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 10 additions & 4 deletions routes/slackv1-router.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
const express = require('express')
const slackv1Router = express.Router()
const {getSlackToken} = require('../services/slack-oauth')
const {clapback} = require('../services/slack-transforms')
const {clapback,getFormData} = require('../services/slack-transforms')
const crypto = require('crypto')

const {CLIENT_ID, CLIENT_SECRET} = process.env

slackv1Router.post('/sassy', (req,res) => {

console.log(req.get('X-Slack-Request-Timestamp'))
console.log(req.body)

const {text} = req.body
const formData = getFormData(req.body)
const timestamp = req.get('X-Slack-Request-Timestamp')
const baseString = `v0:${timestamp}:${formData}`
const hmac = crypto.createHmac('sha256', baseString)
const clapbackText = clapback(text)

console.log('the hmac value is:', hmac)

res.status(200).json({
response_type: "in_channel",
text: clapbackText
Expand Down
6 changes: 6 additions & 0 deletions services/slack-transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ module.exports.clapback = function(text) {
.split(' ')
.map(word => `${word} :clap::skin-tone-5:`)
.join(' ')
}

module.exports.getFormData = function getFormData(object) {
const formData = new FormData();
Object.keys(object).forEach(key => formData.append(key, object[key]));
return formData
}

0 comments on commit 327b1ab

Please sign in to comment.