@slack/client
Advanced tools
Comparing version 3.6.0 to 3.6.1
191
CHANGELOG.md
@@ -1,190 +0,3 @@ | ||
### v3.6.0 (2016-09-06) | ||
* Adds support for Incoming Webhooks | ||
* Fixes a bug around User IDs | ||
### The changelog has moved | ||
### v3.5.4 (2016-07-29) | ||
* Fixes a bug whereby events with fields not recognized cause a crash. Wow. | ||
* Updated some logic around what user ids look like. | ||
### v3.5.3 (2016-07-25) | ||
* Fixes a bug in the package.json published by 3.5.2. | ||
### v3.5.2 (2016-07-25) | ||
* Updating the links in package.json so that you don't need SSL credentials to pull down the github repo. | ||
### v3.5.1 (2016-07-06) | ||
* Updates lodash from ^3.10.1 to ^4.13.1. And means it. | ||
* Minor tweaks to existing documentation and example code to make them consistent with each other. Because hobgoblins are friendly and love you. | ||
### v3.5.0 (2016-06-14) | ||
* Adds the [team.billableInfo](https://api.slack.com/methods/team.billableInfo) endpoint to the team facet | ||
* Adds the [bots.info](https://api.slack.com/methods/bots.info) endpoint and creates the `bots` facet | ||
* Removes the `user` optional argument from the [stars.list](https://api.slack.com/methods/stars.list) method | ||
### v3.4.0 (2016-05-31) | ||
* Adds the [chat.meMessage](https://api.slack.com/methods/chat.meMessage) endpoint to the chat facet | ||
### v3.3.1 (2016-05-26) | ||
* Doesn't crash the RTM client if a message with a `reply_to` ID with no response handler is received | ||
### v3.3.0 (2016-05-24) | ||
* Creates a memory data store by default if an undefined, but not false|null value is passed for `opts.dataStore` | ||
* Aliases the retry policies to be human readable | ||
### v3.2.1 (2016-05-24) | ||
* Updates the RTM client to emit an UNABLE_TO_RTM_START event when all reconnection attempts are exhausted, rather than throwing an error | ||
* Suppresses some spurious log lines when tests are run | ||
### v3.2.0 (2016-05-23) | ||
* Updates the `_makeAPICall` method to make the optional API args param optional to pass in, so the third param to this function can be either an opts object or a cb. This is to allow us to add optional arguments to API methods without it being a breaking change. | ||
* Fixes the `retry-after` header name and adds a numeric fallback if the retry-after value can't be parsed, thanks @foiseworth! | ||
* Adds new API methods to various facets | ||
- [`auth.revoke`](/lib/clients/web/facets/auth.js) | ||
- [`users.identify`](/lib/clients/web/facets/users.js) | ||
* Adds optional arguments to: | ||
- [`files.comments.add`](/lib/clients/web/facets/files.comments.js): adds a `channel` param, for the channel id of the location to associate with the new comment | ||
- [`chat.delete`](/lib/clients/web/facets/chat.js): adds a boolean `as_user` param, to support deleting a message as the authed user | ||
### v3.1.1 (2016-05-19) | ||
* Removes the DM facet | ||
* Updates the aliasing approach for IM / DM to correctly alias DM to the IM Facet | ||
### v3.1.0 (2016-05-01) | ||
* Updates the [`lib/clients/web/facets/index.js`](/lib/clients/web/facets/index.js) to reference the new facets added in the 3.0.0 update, thanks @ekmartin | ||
* Adds in a [`reminders`](/lib/clients/web/facets/reminders.js) client facet | ||
* MemoryDataStore.getUserByEmail now looks at the correct part of the user object for the email, thanks @SimantovYousoufov | ||
* Adds docs and examples for the data store and sending DMs, thanks @PaulAsjes! | ||
### v3.0.0 (2016-04-24) | ||
* Adds a number of new web client API facets: | ||
- [`dnd`](/lib/clients/web/facets/dnd.js) | ||
- [`files.comments`](/lib/clients/web/facets/files.comments.js) | ||
- [`mpim`](/lib/clients/web/facets/mpim.js) | ||
- [`usergroups`](/lib/clients/web/facets/usergroups.js) | ||
- [`usergroups.users`](/lib/clients/web/facets/usergroups.users.js) | ||
* **BREAKING** Changes the function signatures for some facet methods: | ||
- [`channels.list`](/lib/clients/web/facets/channels.js): `exclude_archived` moves to an `opts` object, instead of being a separate argument | ||
- [`groups.list`](/lib/clients/web/facets/groups.js): `exclude_archived` moves to an `opts` object, instead of being a separate argument | ||
- [`chat.delete`](/lib/clients/web/facets/chat.js): The `ts` and `channel` arguments are re-ordered to be alphabetical | ||
- [`stars.list`](/lib/clients/web/facets/stars.js): `user` moves to an `opts` object, instead of being a separate argument | ||
- [`users.list`](/lib/clients/web/facets/users.js): `presence` moves to an `opts` object, instead of being a separate argument | ||
* **BREAKING** Updates the function signature for [`BaseAPIClient.prototype.makeAPICall`](/lib/clients/client.js) to take required API args and optional API args as separate params, from `makeAPICall(endpoint, optData, optCb)` to `makeAPICall(endpoint, apiArgs, apiOptArgs, optCb)` | ||
* New methods are added to various facets: | ||
- [`files.revokePublicURL`](/lib/clients/web/facets/files.js) | ||
- [`files.sharedPublicURL`](/lib/clients/web/facets/files.js) | ||
- [`team.integrationLogs`](/lib/clients/web/facets/team.js) | ||
- [`team.integrationLogs`](/lib/clients/web/facets/team.js) | ||
### v2.3.0 (2016-02-28) | ||
* Caches messages on the RTM client, to improve handling in cases where message send fails | ||
* Removes the handler for the websocket level `ping` handler (not the RTM API level ping handler) | ||
* Refactors the logic for handling ws send responses to a single function | ||
### v2.2.1 (2016-03-12) | ||
* Adds an `im` alias for the `dm` facet to the web client, to match the API endpoint naming | ||
### v2.2.0 (2016-03-12) | ||
* Adds promise support to the RTM client `send` and `sendMessage` methods | ||
* Fixes the way message response callbacks work, so that the success case is only called when the websocket receives a message with a `reply_to` matching the id of the dispatched message, instead of when the ws instance signals message send success | ||
* Fixes the way `getAPICallArgs` works, to correctly pull data out of the `opts` arg | ||
### v2.1.0 (2016-03-05) | ||
* Adds promises to the Slack clients. If no callback is passed to an API call, a promise will be created and returned instead. | ||
* Logs a warning if an API response with a `warning` key is received | ||
### v2.0.6 (2016-03-01) | ||
* Fixes a crash introduce in `2.0.5` if you try and instantiate a `WebClient` without passing in any options | ||
### v2.0.5 (2016-03-01) | ||
* Updates the way that API requests are throttled to: | ||
* avoid a condition where the request queue callback could be called multiple times, causing a crash | ||
* refactor the logic in `_callTransport` into multiple functions to make it easier to follow | ||
* Updates dev dependencies: | ||
* eslint | ||
* nock | ||
* eslint-config-airbnb | ||
### v2.0.4 (2016-02-28) | ||
* Passes through the logLevel param to the getLogger function | ||
### v2.0.3 (2016-02-28) | ||
* The RTM `AUTHENTICATED` event now also emits the `rtm.start` payload | ||
* Fixes the way that loggers are instantiated and used, so that the JSDoc for `opts.logger` is correct | ||
### v2.0.2 (2016-02-15) | ||
* Adds coveralls to the repo, to track code coverage and display a badge in the README | ||
* Updates the disconnect function on the RTM client to support both an error message and a code or reason for the disconnect, e.g. `account_inactive` | ||
* Updates the message-handlers for `team_xxx` events to set the team back to the data-store once changes are made | ||
### v2.0.1 (2016-02-13) | ||
* Updates to `ws@1.0.1` | ||
* Fixes a bad variable name in [`example-web-client`](/examples/example-web-client.js) | ||
### v2.0.0 (2016-02-13) | ||
Refactors the library to javascript, adds a lot of tests and restructures it to improve maintainability and extend functionality. | ||
* Creates two separate clients: | ||
- RTM; manages connection to Slack's RTM API, including reconnects | ||
- Web; provideas a callback interface to all of Slack's Web API endpoints | ||
* Moves the memory data store implementation off the clients and into its own class | ||
* Uncouples the model objects from the clients; model functions to send messages to channels etc are now accessed via the web and RTM client | ||
* Moves the transport layer (websockets and HTTP) to a pluggable model, so that complex transports (through request proxies etc) can be handled | ||
* Adds test coverage on most core functionality in the library | ||
### v1.5.1 (2015-12-15) | ||
* Adds support for a request-proxy URL to use the client from behind a proxy | ||
### v1.5.0 (2015-12-01): | ||
* Updates the ws library from 0.4.3 to 0.8.1 | ||
* Reconnects when a `team_migration_started` event is received | ||
* Supports finding users by email from the memory data store | ||
* Fixes the getUnreadCount and getChannelsWithUnreads functions | ||
* Emits error code and message when the ws closes | ||
* Removes no-op call when a `ping` is received on the websocket | ||
### v1.4.0 (2015-02-25): | ||
* Added callbacks to all API calls ([#20](https://github.com/slackhq/node-slack-client/pull/20)) | ||
* Added support for star added/delete events ([#27](https://github.com/slackhq/node-slack-client/pull/27) | ||
* Fixed sample code ([#18](https://github.com/slackhq/node-slack-client/issues/18)) | ||
* `getChannelByName` now strips leading hash marks ([#9](https://github.com/slackhq/node-slack-client/pull/9)) | ||
* Dropped support for Node 0.8 ([#25](https://github.com/slackhq/node-slack-client/pull/25)) | ||
* Fix duplicate scripts entries in package.json ([230c7f74](https://github.com/slackhq/node-slack-client/commit/230c7f743a48f600aff5660367cf1e6816cc67e2)) | ||
### v1.3.1 (2015-02-03): | ||
* Added ability to call chat.postMessage web API method ([#15](https://github.com/slackhq/node-slack-client/pull/15)) | ||
* Added ability to update and delete messages ([#14](https://github.com/slackhq/node-slack-client/pull/14) and [#17](https://github.com/slackhq/node-slack-client/pull/17)) | ||
* Added sample code ([7ee93a7b](https://github.com/slackhq/node-slack-client/commit/7ee93a7bd51c97519d6d5deb54bd8058612a9b19)) | ||
* Fixed `getChannelsWithUnreads` ([#8](https://github.com/slackhq/node-slack-client/pull/8)) | ||
* Fixed race condition when emitting `open` event ([#19](https://github.com/slackhq/node-slack-client/pull/19)) | ||
### v1.2.2 (2014-12-16): | ||
* Compile coffeescript to JS before publishing to NPM ([#6](https://github.com/slackhq/node-slack-client/pull/6)) | ||
* Fixed typo in docs ([#2](https://github.com/slackhq/node-slack-client/pull/2/files)) | ||
### v1.2.0 (2014-12-08) | ||
* First public release | ||
Please see [the new changelog](https://slackapi.github.io/node-slack-sdk/changelog). |
@@ -13,8 +13,8 @@ # Contributing at Slack | ||
- Reading [the documentation](https://github.com/slackhq/{project_name}/blob/master/README.md) and [the changelog](https://github.com/slackhq/{project_name}/blob/master/README.md) first. | ||
- Reading [the documentation](./README.md) and [the changelog](./CHANGELOG.md) first. | ||
- Searching for any related issues and avoid creating duplicated issues. | ||
- Adding details, diagnoses, screenshots or any type of useful information in existing issues, even if they are marked as closed. The team will still review it. | ||
- Trying out the examples [provided in this repository](https://github.com/slackhq/{project_name}/tree/master/examples). | ||
- Trying out the examples [provided in this repository](https://github.com/slackapi/node-slack-sdk/tree/master/examples). | ||
- Taking the time to think of a solution and [**open a pull request**](#new-pull-requests) for either improving the documentation, fixing a bug or suggesting a feature. | ||
- Finally, **[open an issue]**(https://github.com/slackhq/{project_name}/issues/new) to report a bug, ask for help or suggest a feature. The more information you give, the better people can help you. | ||
- Finally, **[open an issue]**(https://github.com/slackapi/node-slack-sdk/issues/new) to report a bug, ask for help or suggest a feature. The more information you give, the better people can help you. | ||
@@ -26,3 +26,3 @@ | ||
- [Fork the repository](https://github.com/slackhq/{project_name}) and make sure to work on a branch up to date with origin master. | ||
- [Fork the repository](https://github.com/slackapi/node-slack-sdk) and make sure to work on a branch up to date with origin master. | ||
- Do your thing! | ||
@@ -29,0 +29,0 @@ - Be mindful about doing atomic commits, adding documentation to your changes, not refactoring too much. |
@@ -30,2 +30,3 @@ var requestsTransport = require('../transports/request').requestTransport; | ||
iconEmoji: _defaults.iconEmoji, | ||
iconUrl: _defaults.iconUrl, | ||
channel: _defaults.channel, | ||
@@ -64,2 +65,3 @@ text: _defaults.text | ||
icon_emoji: this.defaults.iconEmoji, | ||
icon_url: this.defaults.iconUrl, | ||
channel: this.defaults.channel, | ||
@@ -75,2 +77,3 @@ text: this.defaults.text | ||
if (message.iconEmoji) data.icon_emoji = message.iconEmoji; | ||
if (message.iconUrl) data.icon_url = message.iconUrl; | ||
if (message.channel) data.channel = message.channel; | ||
@@ -77,0 +80,0 @@ if (message.attachments) data.attachments = message.attachments; |
@@ -19,5 +19,7 @@ /** | ||
var wsOpts = {}; | ||
var proxyURL = wsTransportOpts.proxyURL || process.env.https_proxy; | ||
if (wsTransportOpts.proxyURL) { | ||
wsOpts.agent = new HttpsProxyAgent(wsTransportOpts.proxyUrl); | ||
if (proxyURL) { | ||
console.log('Using https proxy: ' + proxyURL); | ||
wsOpts.agent = new HttpsProxyAgent(proxyURL); | ||
} | ||
@@ -24,0 +26,0 @@ |
{ | ||
"name": "@slack/client", | ||
"version": "3.6.0", | ||
"version": "3.6.1", | ||
"description": "A library for creating a Slack client", | ||
@@ -11,4 +11,5 @@ "main": "./index", | ||
"cover": "istanbul cover -x **/facets/*.js --report lcovonly _mocha -- --recursive", | ||
"coveralls": "npm run cover && istanbul-coveralls", | ||
"make-slack-client-symlink": "mkdir -p $PWD/node_modules/@slack/client && ln -s $PWD/index.js $PWD/node_modules/@slack/client/index.js" | ||
"codecov": "npm run cover && codecov", | ||
"make-slack-client-symlink": "mkdir -p $PWD/node_modules/@slack/client && ln -s $PWD/index.js $PWD/node_modules/@slack/client/index.js", | ||
"make-docs": "node jsdoc.js" | ||
}, | ||
@@ -20,5 +21,5 @@ "keywords": [ | ||
"license": "MIT", | ||
"repository": "slackhq/node-slack-sdk", | ||
"repository": "slackapi/node-slack-sdk", | ||
"bugs": { | ||
"url": "https://github.com/slackhq/node-slack-sdk/issues" | ||
"url": "https://github.com/slackapi/node-slack-sdk/issues" | ||
}, | ||
@@ -40,7 +41,7 @@ "dependencies": { | ||
"chai": "^3.3.0", | ||
"coveralls": "^2.11.6", | ||
"codecov": "^1.0.1", | ||
"eslint": "^2.2.0", | ||
"eslint-config-airbnb": "^6.0.2", | ||
"istanbul": "^0.4.2", | ||
"istanbul-coveralls": "^1.0.3", | ||
"jsdoc-to-markdown": "^1.3.7", | ||
"mocha": "~2.3.3", | ||
@@ -47,0 +48,0 @@ "mocha-lcov-reporter": "^1.0.0", |
316
README.md
# Node Library for the Slack APIs | ||
[![Build Status](https://travis-ci.org/slackhq/node-slack-sdk.svg?branch=master)](https://travis-ci.org/slackhq/node-slack-sdk) | ||
[![Coverage Status](https://coveralls.io/repos/github/slackhq/node-slack-sdk/badge.svg?branch=master)](https://coveralls.io/github/slackhq/node-slack-sdk?branch=master) | ||
[![Build Status](https://travis-ci.org/slackapi/node-slack-sdk.svg?branch=master)](https://travis-ci.org/slackapi/node-slack-sdk) | ||
[![codecov](https://codecov.io/gh/slackapi/node-slack-sdk/branch/master/graph/badge.svg)](https://codecov.io/gh/slackapi/node-slack-sdk) | ||
[![npm (scoped)](https://img.shields.io/npm/v/@slack/client.svg?maxAge=2592000)](https://www.npmjs.com/package/@slack/client) | ||
## Motivation | ||
This is a wrapper around the Slack [RTM](https://api.slack.com/rtm) and [Web](https://api.slack.com/web) APIs. | ||
Access the Slack Platform from your Node.js app. This library lets you build on the Slack Web APIs, Incoming Webhooks, | ||
Slash Commands, and the RTM API for building Slack apps and bots, in an idiomatically JavaScript way. | ||
This library will provide the low level functionality you need to build reliable apps and projects on top of Slack's APIs. It: | ||
- handles reconnection logic and request retries | ||
- provides reasonable defaults for events and logging | ||
- defines a basic model layer and data-store for caching Slack RTM API responses | ||
This library does not attempt to provide application level support, e.g. regex matching and filtering of the conversation stream. If you're looking for those kinds of features, you should check out one of the great libraries built on top of this. | ||
## Installation | ||
```bashp | ||
npm install @slack/client --save | ||
``` | ||
## Usage | ||
* [Examples](#examples) | ||
* [RTM Client](#rtm-client) | ||
* [Creating an RTM client](#creating-an-rtm-client) | ||
* [Listen to messages](#listen-to-messages) | ||
* [Send messages](#send-messages) | ||
* [Update messages](#update-messages) | ||
* [Data stores] (#data-stores) | ||
* [Send direct messages] (#send-direct-messages) | ||
* [RTM Client Lifecycle](#rtm-client-lifecycle) | ||
* [Web Client](#web-client) | ||
* [Uploading a file](#uploading-a-file) | ||
* [Incoming Webhook](#incoming-webhook) | ||
* [Migrating from earlier versions](#migrating-from-earlier-versions) | ||
* [Models](#models) | ||
## Examples | ||
There are some examples for using this package in the [examples directory](/examples), these include: | ||
* [connecting to the RTM API](/examples/example-rtm-client.js) | ||
* [connecting to the RTM API and using a datastore](/examples/example-rtm-client-datastore.js) | ||
* [using the web client](/examples/example-web-client.js) | ||
* [uploading a file via the web client](/examples/upload-a-file.js) | ||
* [using incoming webhooks](/examples/example-incoming-webhook.js) | ||
## RTM Client | ||
The [Real Time Messaging client](lib/clients/rtm) connects to [Slack's RTM API](https://api.slack.com/rtm) over a websocket. | ||
It allows you to listen for activity in the Slack team you've connected to and push simple messages back to that team over the websocket. | ||
### Creating an RTM client | ||
```js | ||
var RtmClient = require('@slack/client').RtmClient; | ||
var token = process.env.SLACK_API_TOKEN || ''; | ||
var rtm = new RtmClient(token, {logLevel: 'debug'}); | ||
rtm.start(); | ||
``` | ||
### Capturing the `rtm.start` payload | ||
The RTM client will emit a `RTM.AUTHENTICATED` event, with the `rtm.start` payload. | ||
```js | ||
var CLIENT_EVENTS = require('@slack/client').CLIENT_EVENTS; | ||
rtm.on(CLIENT_EVENTS.RTM.AUTHENTICATED, function (rtmStartData) { | ||
console.log(`Logged in as ${rtmStartData.self.name} of team ${rtmStartData.team.name}, but not yet connected to a channel`); | ||
}); | ||
``` | ||
### Listen to messages | ||
```js | ||
var RTM_EVENTS = require('@slack/client').RTM_EVENTS; | ||
rtm.on(RTM_EVENTS.MESSAGE, function (message) { | ||
// Listens to all `message` events from the team | ||
}); | ||
rtm.on(RTM_EVENTS.CHANNEL_CREATED, function (message) { | ||
// Listens to all `channel_created` events from the team | ||
}); | ||
``` | ||
### Send messages | ||
```js | ||
var RTM_CLIENT_EVENTS = require('@slack/client').CLIENT_EVENTS.RTM; | ||
// you need to wait for the client to fully connect before you can send messages | ||
rtm.on(RTM_CLIENT_EVENTS.RTM_CONNECTION_OPENED, function () { | ||
// This will send the message 'this is a test message' to the channel identified by id 'C0CHZA86Q' | ||
rtm.sendMessage('this is a test message', 'C0CHZA86Q', function messageSent() { | ||
// optionally, you can supply a callback to execute once the message has been sent | ||
}); | ||
}); | ||
``` | ||
### Update messages | ||
```js | ||
rtm.sendMessage('doing stuff!', channel.id, function (err, msg) { | ||
msg.text = "Updated!"; | ||
/* msg is an object which contains: | ||
* ts (string) Timestamp of the message to be updated | ||
* channel (string) ID of the channel the original message was sent in | ||
* text (string) New text to be displayed | ||
* opts (object) Additional options, see here: https://api.slack.com/methods/chat.update | ||
*/ | ||
rtm.updateMessage(msg, function (err, res) { | ||
console.log(err, res); | ||
}); | ||
}); | ||
``` | ||
### Data stores | ||
```js | ||
var RtmClient = require('@slack/client').RtmClient; | ||
// The memory data store is a collection of useful functions we can include in our RtmClient | ||
var MemoryDataStore = require('@slack/client').MemoryDataStore; | ||
var CLIENT_EVENTS = require('@slack/client').CLIENT_EVENTS; | ||
var token = process.env.SLACK_API_TOKEN; | ||
var rtm = new RtmClient(token, { | ||
// Sets the level of logging we require | ||
logLevel: 'error', | ||
// Initialise a data store for our client, this will load additional helper functions for the storing and retrieval of data | ||
dataStore: new MemoryDataStore() | ||
}); | ||
rtm.start(); | ||
// Wait for the client to connect | ||
rtm.on(CLIENT_EVENTS.RTM.RTM_CONNECTION_OPENED, function() { | ||
// Get the user's name | ||
var user = rtm.dataStore.getUserById(rtm.activeUserId); | ||
// Get the team's name | ||
var team = rtm.dataStore.getTeamById(rtm.activeTeamId); | ||
// Log the slack team name and the bot's name | ||
console.log('Connected to ' + team.name + ' as ' + user.name); | ||
}); | ||
``` | ||
### Send Direct Messages | ||
```js | ||
var RTM_EVENTS = require('@slack/client').RTM_EVENTS; | ||
// Responds to a message with a 'hello' DM | ||
rtm.on(RTM_EVENTS.MESSAGE, function(message) { | ||
var user = rtm.dataStore.getUserById(message.user) | ||
var dm = rtm.dataStore.getDMByName(user.name); | ||
rtm.sendMessage('Hello ' + user.name + '!', dm.id); | ||
}); | ||
``` | ||
### RTM Client Lifecycle | ||
The RTM client has its own lifecycle events. These reflect the different states the RTM client can be in as it connects to Slack's RTM API. | ||
The full details of the client lifecycle are in the [RTM client events file](/lib/clients/events/client.js) | ||
The most important events are: | ||
- `RTM_CONNECTION_OPENED`: the remote server has acked the socket and sent a `hello` message, the connection is now live and can be used to send messages | ||
- `DISCONNECT`: the RTM client has disconnected and will not try to reconnect again automatically | ||
## Web Client | ||
### Uploading a file | ||
See [examples/upload-a-file.js](/examples/upload-a-file.js) | ||
## Incoming Webhook | ||
### Setup | ||
Go to https://slack.com/apps/manage/A0F7XDUAZ-incoming-webhooks and configure an incoming webhook. Grab the url. | ||
### Sending Basic Text | ||
```js | ||
var IncomingWebhooks = require('@slack/client').IncomingWebhook; | ||
// Anyone who has access to this url will be able to post your | ||
// slack org without authentication. So don't save this value in version control | ||
var url = process.env.SLACK_WEBHOOK_URL; | ||
var wh = new IncomingWebhooks(url); | ||
// This will send a message "Some Text" using the configuration | ||
// chosen when creating the webhook | ||
wh.send('Some text'); | ||
// You can pass an optional callback | ||
wh.send('More text', function () { | ||
console.log('done sending'); | ||
}); | ||
``` | ||
### Sending More than Text | ||
```js | ||
// This will send a message "Some Text" and override | ||
// the configuration values chosen when creating the webhook. | ||
wh.send({ | ||
text: 'Some text', | ||
channel: 'custom-channel', | ||
iconEmoji: ':robot_face:', | ||
username: 'Custom Name' | ||
}); | ||
// You can send attachments as well | ||
// See https://api.slack.com/docs/attachments | ||
wh.send({ | ||
text: 'Some text', | ||
attachments: [ | ||
// attachment data | ||
] | ||
}); | ||
``` | ||
### Pre-Configure Defaults | ||
```js | ||
var wh = new IncomingWebhooks(url, { | ||
username: 'Custom Username', | ||
channel: 'custom-channel', | ||
iconEmoji: ':robot_face:', | ||
text: 'Default Text' | ||
}); | ||
// This will send a message "Some Text" using the configuration | ||
// that was passed in when the wh object was initialized | ||
wh.send('Some text'); | ||
// This will send a message "Some Text" and override | ||
// the values chosen when initializing the wh object | ||
wh.send({ | ||
text: 'Some text', | ||
channel: 'custom-channel', | ||
iconEmoji: ':robot_face:', | ||
username: 'Custom Name' | ||
}); | ||
``` | ||
## Migrating from earlier versions | ||
This is an incomplete list of items to consider when you migrate from earlier versions. As issues and PRs are raised for things that don't work as expected we'll fill this out. | ||
### Models | ||
The model objects no longer provide utility functions for working with the API. This is to decouple them from the client implementation. There should be functions on each of the clients that allow you to take the same actions you took from the model via the clients instead. The most common of these are below. | ||
#### Sending a message | ||
```js | ||
channel.sendMessage('test message'); | ||
``` | ||
becomes | ||
```js | ||
rtmClient.sendMessage('test message', channel.id); | ||
``` | ||
#### Posting a message | ||
```js | ||
channel.postMessage({ | ||
attachments: [...] | ||
}); | ||
``` | ||
becomes | ||
```js | ||
var data = { | ||
attachments: [...] | ||
}; | ||
webClient.chat.postMessage(channelId, 'test message', data, function() {}); | ||
``` | ||
## Copyright | ||
Copyright © Slack Technologies, Inc. MIT License; see LICENSE for further details. | ||
Comprehensive documentation [is available](https://slackapi.github.io/node-slack-sdk). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
451026
174
7154
12
11