Sending JSON to Slack in a HTTP POST request

后端 未结 11 787
隐瞒了意图╮
隐瞒了意图╮ 2020-12-24 05:21

I\'m trying to send a message using Slack\'s chat.postMessage API call. I have no problems encoding my test messages within HTTP GET, but I\'m trying to achieve the same res

11条回答
  •  一个人的身影
    2020-12-24 05:52

    I did this in powershell and it works like a charm.

    $url="https://slack.com/api/chat.postMessage"
        $messageContent= # your message here
        $token = # your token here
        $channel = # channel name
        $opt_username= # optional user name
    
        $body = @{token=$token;channel=$channel;username=$opt_username;text=$messageContent;pretty=1}
    
        try
        {
            Invoke-WebRequest -Uri $url -Method POST -Body $body
        }
        catch
        {
            Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ 
            Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription        
        }
    

提交回复
热议问题