Debugging a Slack WebHook

Viewed 437

I'm trying to post a message to a Slack channel. If I do it from a browser, for example through the console with an Ajax request all works fine - I don't get any errors and the message gets posted to Slack.

However I need to do it from Node.js app so I chose to use Axios for the request itself. Here's my code

const url = 'https://hooks.slack.com/services/TOKEN/GOES/HERE';
let requestConfig = {
        url: url,
        data: {'text': 'foo'},
        method: 'POST',
        proxy: {
            'host': '127.0.0.1',
            'port': 3128,
            'auth': {
                'username': 'myusername',
                'password': 'mypwd'
            }
        }
    }

axios.request(requestConfig)
        .then((res) => {
            console.log(`Slack notification sent - ${res.status}\n${res.data}`);
        })
        .catch((error) => {
            console.log(`Error sending notification to Slack\n${error}`);
        });
  • proxy itself works and is not a problem, tested on different targets
  • I get a status 200 OK with an empty body, no errors, but nothing gets posted to Slack

Am I doing something wrong? Is there a way to debug this? I'm afraid there is some underlying issue that I don't see and the web hook sends a 200 anyway.

Thanks!

1 Answers

Managed to get it running by setting proxy:false and configuring an httpsAgent, even though it does go through a proxy.

const HttpsProxyAgent = require('https-proxy-agent');
//...
let requestConfig = {
    url: url,
    data: {'text': 'foo'},
    method: 'POST',
    proxy: false,
    httpsAgent: new HttpsProxyAgent('http://myusername:mypwd@localhost:3128')
}
Related