I have a Slack slash command that I would like to implement, but I’m having difficulty responding correctly. No matter what I try, Slack is tacking the json and posting it as is, rather than interpreting its API is supposed to. Other methods of interacting with Slack work normally, so I think it’s something to do with how I’m using UD.
New-UDEndpoint -Url "/commands" -Method "POST" -Endpoint {
param(
$token,
$channel_id,
$channel_name,
$user_id,
$user_name,
$command,
$text,
$response_url,
$trigger_id
)
#Wait-Debugger
$j = @{
response_type = "in_channel"
text = "hello"
}
$j | ConvertTo-Json
In the Slack channel, it just posts
{
“text”: “hello”,
“response_type”: “in_channel”
}
I have noticed if I simply don’t put any output at all, Slack actually posts ‘[]’, which is interesting. I was able to get rid of this with this line:
[Microsoft.AspNetCore.Http.HttpResponseWritingExtensions]::WriteAsync($Response, ‘’)
But this only works with a basic text string. I’ve tried sending JSON that way and the same thing as above happens.