messaging-api-slack
Advanced tools
{ | ||
"name": "messaging-api-slack", | ||
"description": "Messaging API client for Slack", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"engines": { | ||
@@ -6,0 +6,0 @@ "node": ">=6" |
164
README.md
@@ -10,4 +10,8 @@ # messaging-api-slack | ||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [API Reference](#api-reference) | ||
- [OAuth Client](#oauth-client) | ||
- [Usage](#usage) | ||
- [API Reference](#api-reference) | ||
- [Webhook Client](#webhook-client) | ||
- [Usage](#usage-1) | ||
- [API Reference](#api-reference-1) | ||
@@ -24,14 +28,150 @@ ## Installation | ||
## Usage | ||
## OAuth Client | ||
### Initialize | ||
### Usage | ||
Get your bot user OAuth access token by setup OAuth & Permissions function to your app or check the [Using OAuth 2.0](https://api.slack.com/docs/oauth) document. | ||
```js | ||
const { SlackOAuthClient } = require('messaging-api-slack'); | ||
// get access token by setup OAuth & Permissions function to your app. | ||
// https://api.slack.com/docs/oauth | ||
const client = SlackOAuthClient.connect( | ||
'xoxb-000000000000-xxxxxxxxxxxxxxxxxxxxxxxx' | ||
); | ||
``` | ||
### API Reference | ||
All methods return a Promise. | ||
#### Call available methods | ||
##### callMethod(method, body) - [Official docs](https://api.slack.com/methods) | ||
###### method | ||
Type: `String` | ||
Value: One of `chat.postMessage | 'channels.info' | 'channels.list' | 'users.info' | 'users.list` | ||
###### body | ||
Type: `Object` | ||
```js | ||
client.callMethod('chat.postMessage', { channel: 'C8763', text: 'Hello!' }); | ||
``` | ||
#### Chat API | ||
##### postMessage(channel, text, options?) - [Official docs](https://api.slack.com/methods/chat.postMessage) | ||
###### channel | ||
Type: `String` | ||
###### text | ||
Type: `String` | ||
###### options | ||
Type: `Object` | ||
```js | ||
client.postMessage('C8763', 'Hello!'); | ||
client.postMessage('C8763', 'Hello!', { as_user: true }); | ||
``` | ||
#### Users API | ||
##### getUserList(cursor?) - [Official docs](https://api.slack.com/methods/users.list) | ||
###### cursor | ||
Type: `String` | ||
```js | ||
client.getUserList(CURSOR).then(res => { | ||
console.log(res); | ||
// [ | ||
// { ... }, | ||
// { ... }, | ||
// ] | ||
}); | ||
``` | ||
##### getAllUserList() - [Official docs](https://api.slack.com/methods/users.list) | ||
```js | ||
client.getAllUserList().then(res => { | ||
console.log(res); | ||
// [ | ||
// { ... }, | ||
// { ... }, | ||
// ] | ||
}); | ||
``` | ||
##### getUserInfo(userId) - [Official docs](https://api.slack.com/methods/users.info) | ||
###### userId | ||
Type: `String` | ||
```js | ||
client.getUserInfo(userId).then(res => { | ||
console.log(res); | ||
// { | ||
// id: 'U123456', | ||
// name: 'bobby', | ||
// ... | ||
// } | ||
}); | ||
``` | ||
#### Channels API | ||
##### getChannelList() - [Official docs](https://api.slack.com/methods/channels.list) | ||
```js | ||
client.getChannelList().then(res => { | ||
console.log(res); | ||
// [ | ||
// { ... }, | ||
// { ... }, | ||
// ] | ||
}); | ||
``` | ||
##### getChannelInfo(channelId) - [Official docs](https://api.slack.com/methods/channels.info) | ||
###### channelId | ||
Type: `String` | ||
```js | ||
client.getChannelInfo(channelId).then(res => { | ||
console.log(res); | ||
// { | ||
// id: 'C8763', | ||
// name: 'fun', | ||
// ... | ||
// } | ||
}); | ||
``` | ||
## Webhook Client | ||
### Usage | ||
Get your webhook url by adding a [Incoming Webhooks](https://api.slack.com/incoming-webhooks) integreation to your team or setup Incoming Webhooks function to your app. | ||
```js | ||
const { SlackClient } = require('messaging-api-slack'); | ||
const { SlackWebhookClient } = require('messaging-api-slack'); | ||
// get webhook URL by adding a Incoming Webhook integration to your team. | ||
// https://my.slack.com/services/new/incoming-webhook/ | ||
const client = SlackClient.connect( | ||
const client = SlackWebhookClient.connect( | ||
'https://hooks.slack.com/services/XXXXXXXX/YYYYYYYY/zzzzzZZZZZ' | ||
@@ -41,9 +181,9 @@ ); | ||
## API Reference | ||
### API Reference | ||
All methods return a Promise. | ||
### Send API - [Official docs](https://api.slack.com/docs/messages) | ||
#### Send API - [Official docs](https://api.slack.com/docs/messages) | ||
#### sendRawBody(body) | ||
##### sendRawBody(body) | ||
@@ -58,3 +198,3 @@ ###### body | ||
#### sendText(text) | ||
##### sendText(text) | ||
@@ -69,3 +209,3 @@ ###### text | ||
#### sendAttachments(attachments) - [Official docs](https://api.slack.com/docs/message-attachments) | ||
##### sendAttachments(attachments) - [Official docs](https://api.slack.com/docs/message-attachments) | ||
@@ -105,3 +245,3 @@ ###### attachments | ||
#### sendAttachment(attachment) - [Official docs](https://api.slack.com/docs/message-attachments) | ||
##### sendAttachment(attachment) - [Official docs](https://api.slack.com/docs/message-attachments) | ||
@@ -108,0 +248,0 @@ ###### attachment |
33516
8.32%260
116.67%