stackvana / hook.io

Open-Source Microservice Hosting Platform
https://hook.io
Other
1.26k stars 117 forks source link

request.post does not seem to work #281

Closed simocl closed 7 years ago

simocl commented 7 years ago

Hi,

Why the code below does work?

Thanks,

var request = require('request'); request .post('http://webhook.site/e6255c2c-5783-4cbf-986a-9cda5d754a1f') .form({ "chat_id": "efgerf", "text": "egferfg" });

simocl commented 7 years ago

Got it working with the code below that I found in https://medium.com/@katyemoe/making-custom-slack-slash-commands-with-hook-io-93ba70daf681

var request = require('request');

// The parameters passed in via the slash command POST request. var params = hook.params;

// Set up the options for the HTTP request.
var options = {

  // Use the Webhook URL from the Slack Incoming Webhooks integration.
  uri: 'http://webhook.site/e6255c2c-5783-4cbf-986a-9cda5d754a1f',

  method: 'POST',

  // Slack expects a JSON payload with a "text" property.
  json: {
    'text': '@' + 'params.user_name' + ' sent a high five to ' + 'params.text',

    // Request that Slack parse URLs, usernames, emoji, etc. in the 
    // incoming text.
    'parse': 'full'
  }
};

// Make the POST request to the Slack incoming webhook.
request(options, function (error, response, body) {

  // Pass error back to client if request endpoint can't be reached.
  if (error) {
    hook.res.end(error.message);
  }

  // Finally, send the response. This will be displayed to the user after
  // they submit the slash command.
  hook.res.end('High five success! Go to #highfives to see it :smile:');
});