Next we will take a look at the information that Slack sends us when we receive a request from a Slash command
app.post(/test..)
function in index.js
app.post(/test)
function, change the console.log(req)
to console.log(req.body)
app.post('/test', async (req, res) => {
try {
console.log(req.body) // <-- update this line
const data = {
'response_type': 'in_channel',
'text': 'Testing testing 123!'
}
res.json(data)
} catch (e) {
console.log(e)
}
})
Restart your node server
Navigate to your Slack workspace and make another slash command to but this time add a name for example, /test Fred Flintstone
Let’s see the result of console.log(req.body)
Navigate to the node server tab in your command line application and you should see something similar to the following
{
token: 'CePdTWPzpIXUufKUL3UJhaVx',
team_id: 'TN43P8U3X',
team_domain: 'reemcoworkspace',
channel_id: 'CN17QEB2M',
channel_name: 'slackbot-testing',
user_id: 'UN43P8UCD',
user_name: 'kareem.grant',
command: '/test',
text: 'Fred Flintstone',
response_url: 'https://hooks.slack.com/commands/TN43P8U3X/755841282464/Xu0N0r65xVmo3dbMgD83xUq7',
trigger_id: '755841282544.752125300133.615d84c666fefe471d23a7e53bf50f07'
}
req.body.text
in the object we get back from SlackWe are going to update our response back the Slack to the parameter that was sent along with the slash command (`text: ‘Fred Flintstone’)
app.post(/test..)
function app.post('/test', async (req, res) => {
try {
console.log(req.body)
const data = {
'response_type': 'in_channel',
'text': `Testing testing 123! ${req.body.text}` // <-- update this line
}
res.json(data)
} catch (e) {
console.log(e)
}
})
/test Fred Flintstone
in your workspaceLet’s see if we can successfully send back data we received from Slack in our response
In your workspace, make the following slash command: /test Fred Flintstone
You should now see: Testing testing 123! Fred Flintstone