Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable to set link_names option of incoming webhook #342

Merged
merged 3 commits into from Aug 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions docs/_reference/BaseAPIClient.md
Expand Up @@ -9,7 +9,6 @@ permalink: /reference/BaseAPIClient
* [new BaseAPIClient(token, opts)](#new_BaseAPIClient_new)
* [.slackAPIUrl](#BaseAPIClient+slackAPIUrl) : <code>string</code>
* [.transport](#BaseAPIClient+transport) : <code>function</code>
* [.userAgent](#BaseAPIClient+userAgent) : <code>string</code>
* [.retryConfig](#BaseAPIClient+retryConfig)
* [.logger](#BaseAPIClient+logger) : <code>function</code>
* [._createFacets()](#BaseAPIClient+_createFacets)
Expand All @@ -27,7 +26,6 @@ Base client for both the RTM and web APIs.
| token | <code>string</code> | The Slack API token to use with this client. |
| opts | <code>Object</code> | |
| opts.slackAPIUrl | <code>String</code> | The Slack API URL. |
| opts.userAgent | <code>String</code> | The user-agent to use, defaults to node-slack. |
| opts.transport | <code>function</code> | Function to call to make an HTTP call to the Slack API. |
| [opts.logLevel] | <code>string</code> | The log level for the logger. |
| [opts.logger] | <code>function</code> | Function to use for log calls, takes (logLevel, logString) params. |
Expand All @@ -42,10 +40,6 @@ Base client for both the RTM and web APIs.

### baseAPIClient.transport : <code>function</code>
**Kind**: instance property of <code>[BaseAPIClient](#BaseAPIClient)</code>
<a name="BaseAPIClient+userAgent"></a>

### baseAPIClient.userAgent : <code>string</code>
**Kind**: instance property of <code>[BaseAPIClient](#BaseAPIClient)</code>
<a name="BaseAPIClient+retryConfig"></a>

### baseAPIClient.retryConfig
Expand Down
1 change: 1 addition & 0 deletions docs/_reference/IncomingWebhook.md
Expand Up @@ -21,6 +21,7 @@ permalink: /reference/IncomingWebhook
| defaults.iconEmoji | <code>string</code> | The default emoji to use when sending a webhook. If no iconEmoji is specified, the one chosen when creating the webhook will be used. |
| defaults.channel | <code>string</code> | The default channel to use when sending a webhook. If no channel is specified, the one chosen when creating the webhook will be used. |
| defaults.text | <code>string</code> | The default text to use when sending a webhook. |
| defaults.linkNames | <code>string</code> | The default setting for the link_names format option to use when sending a webhook. If no value is specified, the one chosen when creating the webhook will be used. |

<a name="IncomingWebhook+send"></a>

Expand Down
12 changes: 12 additions & 0 deletions docs/_reference/SlackDataStore.md
Expand Up @@ -20,6 +20,7 @@ permalink: /reference/SlackDataStore
* [.getGroupByName(name)](#SlackDataStore+getGroupByName) ⇒ <code>Object</code>
* [.getDMById(dmId)](#SlackDataStore+getDMById) ⇒ <code>Object</code>
* [.getDMByName(name)](#SlackDataStore+getDMByName) ⇒ <code>Object</code>
* [.getDMByUserId(id)](#SlackDataStore+getDMByUserId) ⇒ <code>Object</code>
* [.getBotById(botId)](#SlackDataStore+getBotById) ⇒ <code>Object</code>
* [.getBotByName(name)](#SlackDataStore+getBotByName) ⇒ <code>Object</code>
* [.getBotByUserId(userId)](#SlackDataStore+getBotByUserId) ⇒ <code>Object</code>
Expand Down Expand Up @@ -187,6 +188,17 @@ Returns the DM object between the registered user and the user with the supplied
| --- |
| name |

<a name="SlackDataStore+getDMByUserId"></a>

### slackDataStore.getDMByUserId(id) ⇒ <code>Object</code>
Returns the DM object between the registered user and the user with the supplied id.

**Kind**: instance method of <code>[SlackDataStore](#SlackDataStore)</code>

| Param |
| --- |
| id |

<a name="SlackDataStore+getBotById"></a>

### slackDataStore.getBotById(botId) ⇒ <code>Object</code>
Expand Down
5 changes: 5 additions & 0 deletions docs/_reference/SlackMemoryDataStore.md
Expand Up @@ -23,6 +23,7 @@ permalink: /reference/SlackMemoryDataStore
* [.getGroupByName()](#SlackMemoryDataStore+getGroupByName)
* [.getDMById()](#SlackMemoryDataStore+getDMById)
* [.getDMByName()](#SlackMemoryDataStore+getDMByName)
* [.getDMByUserId()](#SlackMemoryDataStore+getDMByUserId)
* [.getBotById()](#SlackMemoryDataStore+getBotById)
* [.getBotByName()](#SlackMemoryDataStore+getBotByName)
* [.getBotByUserId()](#SlackMemoryDataStore+getBotByUserId)
Expand Down Expand Up @@ -115,6 +116,10 @@ permalink: /reference/SlackMemoryDataStore

### slackMemoryDataStore.getDMByName()
**Kind**: instance method of <code>[SlackMemoryDataStore](#SlackMemoryDataStore)</code>
<a name="SlackMemoryDataStore+getDMByUserId"></a>

### slackMemoryDataStore.getDMByUserId()
**Kind**: instance method of <code>[SlackMemoryDataStore](#SlackMemoryDataStore)</code>
<a name="SlackMemoryDataStore+getBotById"></a>

### slackMemoryDataStore.getBotById()
Expand Down
1 change: 1 addition & 0 deletions examples/example-incoming-webhook.js
Expand Up @@ -22,6 +22,7 @@ whWithDefaults.send({
text: 'Some text',
iconEmoji: ':robot_face:',
channel: 'custom-channel',
linkNames: '1',
attachments: [
// attachment data
// see https://api.slack.com/docs/attachments
Expand Down
5 changes: 5 additions & 0 deletions lib/clients/incoming-webhook/client.js
Expand Up @@ -14,6 +14,8 @@ var noop = require('lodash').noop;
* @param {string} defaults.channel The default channel to use when sending a webhook.
* If no channel is specified, the one chosen when creating the webhook will be used.
* @param {string} defaults.text The default text to use when sending a webhook.
* @param {string} defaults.linkNames The default setting for the link_names format option to use when sending a webhook.
* If no value is specified, the one chosen when creating the webhook will be used.
* @constructor
*/
function IncomingWebhook(slackUrl, defaults) {
Expand All @@ -29,6 +31,7 @@ function IncomingWebhook(slackUrl, defaults) {
iconEmoji: _defaults.iconEmoji,
iconUrl: _defaults.iconUrl,
channel: _defaults.channel,
linkNames: _defaults.linkNames,
text: _defaults.text
};

Expand Down Expand Up @@ -63,6 +66,7 @@ IncomingWebhook.prototype._formatData = function _formatData(message) {
icon_emoji: this.defaults.iconEmoji,
icon_url: this.defaults.iconUrl,
channel: this.defaults.channel,
link_names: this.defaults.linkNames,
text: this.defaults.text
};

Expand All @@ -74,6 +78,7 @@ IncomingWebhook.prototype._formatData = function _formatData(message) {
if (message.iconEmoji) data.icon_emoji = message.iconEmoji;
if (message.iconUrl) data.icon_url = message.iconUrl;
if (message.channel) data.channel = message.channel;
if (message.linkNames) data.link_names = message.linkNames;
if (message.attachments) data.attachments = message.attachments;
}

Expand Down
8 changes: 6 additions & 2 deletions test/clients/incoming-webhook/client.js
Expand Up @@ -19,13 +19,15 @@ describe('Incoming Webhook', function () {
username: 'a bot name',
iconEmoji: ':robot_face:',
channel: 'channel-name',
linkNames: '1',
text: 'some text'
};
var wh = new IncomingWebhook('slackWebhookUrl', opts);

expect(wh.defaults.username).to.equal(opts.username);
expect(wh.defaults.iconEmoji).to.equal(opts.iconEmoji);
expect(wh.defaults.channel).to.equal(opts.channel);
expect(wh.defaults.linkNames).to.equal(opts.linkNames);
expect(wh.defaults.text).to.equal(opts.text);
});

Expand Down Expand Up @@ -166,15 +168,17 @@ describe('Incoming Webhook', function () {
text: 'Some text',
username: 'A username',
channel: 'a-channel',
iconEmoji: ':robot_face:'
iconEmoji: ':robot_face:',
linkNames: '1'
}, function () {
expect(transport.calledOnce).to.equal(true);
expect(transport.calledWithMatch({
body: {
text: 'Some text',
username: 'A username',
channel: 'a-channel',
icon_emoji: ':robot_face:'
icon_emoji: ':robot_face:',
link_names: '1'
}
})).to.equal(true);

Expand Down