node-red-contrib-slack
Version:
A node-red module to interact with the Slack API
324 lines (292 loc) • 12.5 kB
HTML
<script type="text/x-red" data-template-name="slack-config">
<div class="form-row">
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-config-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-config-input-token"><i class="fa fa-user"></i> Token</label>
<input type="text" id="node-config-input-token" placeholder="" />
</div>
</script>
<script type="text/x-red" data-help-name="slack-config">
<p>Configuration node for Slack.</p>
<h3>Details</h3>
<p>Simply supply your Slack token. A <i>bot</i> token is likely much easier than a <i>user</i> token.</p>
<h3>References</h3>
<ul>
<li><a href="https://api.slack.com/docs/token-types">Token Types</a> - explanation of Slack token types</li>
<li><a href="https://api.slack.com/tokens">Tokens</a> - list of Slack tokens you already have</li>
<li><a href="https://api.slack.com">Slack API Introduction</a> - introduction to Slack APIs</li>
<li><a href="https://api.slack.com/rtm">Slack RTM API</a> - full description of RTM API</li>
<li><a href="https://api.slack.com/web">Slack Web API</a> - full description of Web API</li>
<li><a href="https://api.slack.com/methods">Slack Web API Methods</a> - full descriptions of all Web API methods</li>
<li><a href="https://github.com/yayadrian/node-red-slack">GitHub</a> - project homepage</li>
</ul>
</script>
<script type="text/x-red" data-template-name="slack-state">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-client"><i class="fa fa-user"></i> Slack Client</label>
<input type="text" id="node-input-client">
</div>
</script>
<script type="text/x-red" data-help-name="slack-state">
<p>Outputs and <i>optionally</i> refreshes the <code>msg.slackState</code> data.</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt class="optional">payload
<span class="property-type">boolean</span>
</dt>
<dd>If <code>true</code> then <code>msg.slackState</code> will be refreshed before output.</dd>
</dl>
<h3>Outputs</h3>
<ol class="node-ports">
<li>State
<dl class="message-properties">
<dt>slackState <span class="property-type">object</span></dt>
<dd>The current state of the slack connection.</dd>
</dl>
<li>Events
<dl class="message-properties">
<dt>payload <span class="property-type">object</span></dt>
<dd>The state event details.</dd>
<dt>slackState <span class="property-type">object</span></dt>
<dd>The current state of the slack connection.</dd>
</dl>
</li>
</ol>
<h3>References</h3>
<ul>
<li><a href="https://github.com/yayadrian/node-red-slack#slack-state">slack-state</a> - full description of node behavior</li>
<li><a href="https://github.com/yayadrian/node-red-slack#slackstate">slackState</a> - full description of <code>msg.slackState</code> object</li>
<li><a href="https://api.slack.com">Slack API Introduction</a> - introduction to Slack APIs</li>
<li><a href="https://api.slack.com/rtm">Slack RTM API</a> - full description of RTM API</li>
<li><a href="https://api.slack.com/web">Slack Web API</a> - full description of Web API</li>
<li><a href="https://api.slack.com/methods">Slack Web API Methods</a> - full descriptions of all Web API methods</li>
<li><a href="https://github.com/yayadrian/node-red-slack">GitHub</a> - project homepage</li>
</ul>
</script>
<script type="text/x-red" data-template-name="slack-rtm-in">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-client"><i class="fa fa-user"></i> Slack Client</label>
<input type="text" id="node-input-client">
</div>
<div class="form-row">
<label for="node-input-events"><i class="fa fa-filter"></i> Slack Events</label>
<input type="text" id="node-input-events" placeholder="message">
</div>
<div class="form-tips"><b>Tip:</b> Leave blank to receive <b>ALL</b> events.</div>
</script>
<script type="text/x-red" data-help-name="slack-rtm-in">
<p>Listens to Slack RTM API events and outputs the event details.</p>
<h3>Outputs</h3>
<dl class="message-properties">
<dt>payload <span class="property-type">object</span></dt>
<dd>The Slack RTM API event.</dd>
<dt>slackState <span class="property-type">object</span></dt>
<dd>The current state of the slack connection.</dd>
</dl>
<h3>Details</h3>
<p>
For a complete list of events emitted with their details review the <a href="https://api.slack.com/rtm">Slack RTM API</a> documentation.
</p>
<p>
By default the node will listen to <b>ALL</b> events (<code>slack_event</code>). You can however filter event types by setting the node <em>Slack Events</em> property
to a value taking the form of <code>type[::subtype][,type[::subtype],...]</code>. For example <code>message</code> to receive only events of type <code>message</code>
or <code>message::bot_message</code> to receive only events of type <code>message</code> which additionally have a <code>subtype</code> of <code>bot_message</code>.
</p>
<h3>References</h3>
<ul>
<li><a href="https://github.com/yayadrian/node-red-slack#slack-rtm-in">slack-rtm-in</a> - full description of node behavior</li>
<li><a href="https://api.slack.com">Slack API Introduction</a> - introduction to Slack APIs</li>
<li><a href="https://api.slack.com/rtm">Slack RTM API</a> - full description of RTM API</li>
<li><a href="https://github.com/yayadrian/node-red-slack#slackstate">slackState</a> - full description of <code>msg.slackState</code> object</li>
<li><a href="https://github.com/yayadrian/node-red-slack">GitHub</a> - project homepage</li>
</ul>
</script>
<script type="text/x-red" data-template-name="slack-rtm-out">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-client"><i class="fa fa-user"></i> Slack Client</label>
<input type="text" id="node-input-client">
</div>
</script>
<script type="text/x-red" data-help-name="slack-rtm-out">
<p>Invokes a Slack RTM API method and outputs the response.</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>topic
<span class="property-type">string</span>
</dt>
<dd>The method name.</dd>
<dt class="optional">payload
<span class="property-type">object</span>
</dt>
<dd>The method arguments.</dd>
</dl>
<h3>Outputs</h3>
<dl class="message-properties">
<dt>payload <span class="property-type">object</span></dt>
<dd>The Slack RTM API response.</dd>
<dt>slackState <span class="property-type">object</span></dt>
<dd>The current state of the slack connection.</dd>
</dl>
<h3>Details</h3>
<p>
For simple message sending as an alternative the to method/arguments style, you may set the <code>msg.topic</code> to either <code>@username</code> or <code>#channel</code> syntax.
If you use this syntax simply set <code>msg.payload</code> to the message you want sent.
</p>
<h3>References</h3>
<ul>
<li><a href="https://github.com/yayadrian/node-red-slack#slack-rtm-out">slack-rtm-out</a> - full description of node behavior</li>
<li><a href="https://api.slack.com">Slack API Introduction</a> - introduction to Slack APIs</li>
<li><a href="https://api.slack.com/rtm">Slack RTM API</a> - full description of RTM API</li>
<li><a href="https://github.com/yayadrian/node-red-slack#slackstate">slackState</a> - full description of <code>msg.slackState</code> object</li>
<li><a href="https://github.com/yayadrian/node-red-slack">GitHub</a> - project homepage</li>
</ul>
</script>
<script type="text/x-red" data-template-name="slack-web-out">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-client"><i class="fa fa-user"></i> Slack Client</label>
<input type="text" id="node-input-client">
</div>
</script>
<script type="text/x-red" data-help-name="slack-web-out">
<p>Invokes a Slack Web API method and outputs the response.</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>topic
<span class="property-type">string</span>
</dt>
<dd>The method name.</dd>
<dt class="optional">payload
<span class="property-type">object</span>
</dt>
<dd>The method arguments.</dd>
</dl>
<h3>Outputs</h3>
<dl class="message-properties">
<dt>payload <span class="property-type">object</span></dt>
<dd>The Slack Web API response.</dd>
<dt>slackState <span class="property-type">object</span></dt>
<dd>The current state of the slack connection.</dd>
</dl>
<h3>Details</h3>
<p>
For simple message sending as an alternative the to method/arguments style, you may set the <code>msg.topic</code> to either <code>@username</code> or <code>#channel</code> syntax.
If you use this syntax simply set <code>msg.payload</code> to the message you want sent.
</p>
<h3>References</h3>
<ul>
<li><a href="https://github.com/yayadrian/node-red-slack#slack-web-out">slack-web-out</a> - full description of node behavior</li>
<li><a href="https://api.slack.com">Slack API Introduction</a> - introduction to Slack APIs</li>
<li><a href="https://api.slack.com/web">Slack Web API</a> - full description of Web API</li>
<li><a href="https://api.slack.com/methods">Slack Web API Methods</a> - full descriptions of all Web API methods</li>
<li><a href="https://github.com/yayadrian/node-red-slack#slackstate">slackState</a> - full description of <code>msg.slackState</code> object</li>
<li><a href="https://github.com/yayadrian/node-red-slack">GitHub</a> - project homepage</li>
</ul>
</script>
<script type="text/javascript">
/**
* slack purple #611f69
* lightened up because on the canvas the default is very dark
*/
RED.nodes.registerType("slack-config", {
category: "config",
defaults: {
name: { value: "" }
},
credentials: {
token: { type: "text" }
},
label: function() {
return this.name || "slack-config";
}
});
RED.nodes.registerType("slack-state", {
category: "social",
defaults: {
client: { type: "slack-config", required: true },
name: { value: "" }
},
color: "#C785CF",
icon: "slack_mark_white.png",
align: "left",
inputs: 1,
inputLabels: "state request",
outputs: 2,
outputLabels: ["state", "state events"],
label: function() {
return this.name || "slack-state";
},
paletteLabel: "slack-state"
});
RED.nodes.registerType("slack-rtm-in", {
category: "social",
defaults: {
client: { type: "slack-config", required: true },
name: { value: "" },
events: { value: "" }
},
color: "#C785CF",
icon: "slack_mark_white.png",
align: "left",
inputs: 0,
outputs: 1,
outputLabels: ["rtm events"],
label: function() {
return this.name || "slack-rtm-in";
},
paletteLabel: "slack-rtm-in"
});
RED.nodes.registerType("slack-rtm-out", {
category: "social",
defaults: {
client: { type: "slack-config", required: true },
name: { value: "" }
},
color: "#C785CF",
icon: "slack_mark_white.png",
align: "left",
inputs: 1,
inputLabels: "rtm request",
outputs: 1,
outputLabels: ["rtm response"],
label: function() {
return this.name || "slack-rtm-out";
},
paletteLabel: "slack-rtm-out"
});
RED.nodes.registerType("slack-web-out", {
category: "social",
defaults: {
client: { type: "slack-config", required: true },
name: { value: "" }
},
color: "#C785CF",
icon: "slack_mark_white.png",
align: "left",
inputs: 1,
inputLabels: "web request",
outputs: 1,
outputLabels: ["web response"],
label: function() {
return this.name || "slack-web-out";
},
paletteLabel: "slack-web-out"
});
</script>