clonn / slack-node-sdk

slack.com, slack, node sdk
MIT License
167 stars 32 forks source link

Add webhook default options #40

Closed bells17 closed 4 years ago

bells17 commented 8 years ago

Add webhook default options

example:

var Slack = require('slack-node');

webhookUri = "-- api token --";

slack = new Slack();
slack.setWebhook(webhookUri, {
  channel: "#general",
  username: "webhookbot",
});

slack.webhook({
  text: "This is posted to #general and comes from a bot named webhookbot."
}, function(err, response) {
  console.log(response);
});
kevinburkeshyp commented 8 years ago

Thanks for this, and thanks for writing a test! I think if we want to go this route, it would be better to have a Webhook object or something, that can encode these options and have that call respond instead of globally changing the channel settings. eg

wb = new slack.Webhook(options); 
wb.respond("This is posted to #general")
bells17 commented 8 years ago

@kevinburkeshyp Thanks for your feedback! I have added the following changes:

var Slack = require('slack-node');

var webhookUri = "__uri___";

var webhook = new Slack.Webhook({
  url: webhookUri,
  channel: "#general",
  username: "webhookbot",
});

// only text
webhook.respond("This is posted to #general and comes from a bot named webhookbot.", function(err, response) {
  console.log(response)
});

Can you review it? Thanks!