Skip to content

Commit

Permalink
Debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanner Nielsen committed Jun 3, 2020
1 parent fcd1b81 commit 5d7fb78
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/handlers.ts
@@ -1,6 +1,7 @@
import { NowRequest, NowResponse } from '@now/node';
import { text } from 'micro';
import { parse } from 'querystring';
import axios from 'axios';

import convert, { charSets } from './convert';

Expand All @@ -15,12 +16,24 @@ export const slackHandler = (type: keyof typeof charSets) =>
const payload = parse(await text(req)) as SlashCommandPayload;
const convertedText = convert(payload.text as string, type);

console.log(payload.response_url.slice(0, 16));
const headers = {
'Content-Type': 'application/json',
};

res.json({
response_type: 'in_channel',
const body = {
text: convertedText,
})
};

const response = await axios.post(payload.response_url, body, { headers });
if (response.status !== 200) {
console.log(JSON.stringify(response.data));
res.json({
response_type: 'ephemeral',
text: 'Oops, we failed to process that command.',
});
} else {
res.send('');
}
}

// https://api.slack.com/interactivity/slash-commands#app_command_handling
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -7,6 +7,7 @@
"test": "mocha"
},
"dependencies": {
"axios": "^0.19.2",
"micro": "^9.3.4",
"querystring": "^0.2.0"
},
Expand Down
26 changes: 26 additions & 0 deletions yarn.lock
Expand Up @@ -80,6 +80,13 @@ as-table@^1.0.36:
dependencies:
printable-characters "^1.0.42"

axios@^0.19.2:
version "0.19.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27"
integrity sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==
dependencies:
follow-redirects "1.5.10"

balanced-match@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
Expand Down Expand Up @@ -192,6 +199,13 @@ debug@3.2.6:
dependencies:
ms "^2.1.1"

debug@=3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
dependencies:
ms "2.0.0"

debug@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791"
Expand Down Expand Up @@ -299,6 +313,13 @@ flat@^4.1.0:
dependencies:
is-buffer "~2.0.3"

follow-redirects@1.5.10:
version "1.5.10"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==
dependencies:
debug "=3.1.0"

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
Expand Down Expand Up @@ -571,6 +592,11 @@ mocha@^7.2.0:
yargs-parser "13.1.2"
yargs-unparser "1.6.0"

ms@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=

ms@2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a"
Expand Down

1 comment on commit 5d7fb78

@vercel
Copy link

@vercel vercel bot commented on 5d7fb78 Jun 3, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.