Skip to content

Commit

Permalink
Merge pull request #1145 from simlu/dev
Browse files Browse the repository at this point in the history
feat: added channel.shareFiles and self.shareFiles
  • Loading branch information
simlu committed Aug 1, 2021
2 parents 21272f2 + d403fd2 commit dc45c9c
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 26 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ Maximum number of entries in cache at any given time. Optional, defaults to `100

Send `message` to self.

### self.shareFiles(files: array<string>)

Share `files` to self.

### channel.meta(channel: string)

Get meta information about channel `channel`
Expand All @@ -69,6 +73,10 @@ Set `topic` of channel `channel`

Set `purpose` of channel `channel`

### channel.shareFiles(channel: string, files: array<string>)

Share `files` to a channel `channel`.

### workspace.details(cache: boolean = true)

Obtain details for workspace. Should usually be cached as it is easy to run into rate limits.
Expand Down
7 changes: 7 additions & 0 deletions src/index/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,12 @@ module.exports = (call) => ({
purpose,
channel: channel.id
});
},
shareFiles: async (name, files) => {
const channel = await getChannelMeta(call, name);
return call('files.share', {
files: files.join(','),
channel: channel.id
});
}
});
22 changes: 0 additions & 22 deletions src/index/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,4 @@ module.exports = (call) => ({
assert(completeUploadResponse.files.length === 1, completeUploadResponse);
return completeUploadResponse.files[0].id;
}
// share: async (name, id) => {
// const channel = await channelMeta(name);
// return call('files.share', {
// files: id,
// broadcast: false,
// blocks: JSON.stringify([{
// type: 'rich_text',
// elements: [
// {
// type: 'rich_text_section',
// elements: [
// {
// type: 'text',
// text: 'test'
// }]
// }
// ]
// }]),
// resharing_aware: true,
// channel: channel.id
// });
// }
});
16 changes: 12 additions & 4 deletions src/index/self.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
const getSelf = require('./util/get-self');

module.exports = (call) => ({
message: async (msg) => {
const rtmStart = await call('rtm.start', {}, true);
const user = rtmStart.self;
const self = await getSelf(call);
return call('chat.command', {
disp: '/me',
command: '/msg',
text: `${user.name} ${msg}`,
channel: rtmStart.ims.find((im) => im.user === user.id).id
text: `${self.name} ${msg}`,
channel: self.channel
});
},
shareFiles: async (files) => {
const self = await getSelf(call);
return call('files.share', {
files: files.join(','),
channel: self.channel
});
}
});
9 changes: 9 additions & 0 deletions src/index/util/get-self.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = async (call) => {
const rtmStart = await call('rtm.start', {}, true);
const user = rtmStart.self;
return {
id: user.id,
name: user.name,
channel: rtmStart.ims.find((im) => im.user === user.id).id
};
};
5 changes: 5 additions & 0 deletions test/index/channel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ describe('Testing Slack SDK', {
const r = await slack.channel.setPurpose('channel', 'purpose');
expect(r).to.deep.contain({ ok: true });
});

it('Testing channel.shareFiles', async () => {
const r = await slack.channel.shareFiles('channel', ['F029QHN0AAZ', 'F02AH8J752L']);
expect(r).to.deep.equal({ ok: true });
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[
{
"scope": "https://workspace.slack.com:443",
"method": "POST",
"path": "/api/rtm.start",
"body": "----------------------------240931670220439824763760\r\nContent-Disposition: form-data; name=\"token\"\r\n\r\nSLACK-SESSION-TOKEN\r\n----------------------------240931670220439824763760--\r\n",
"status": 200,
"response": {
"ok": true,
"channels": [
{
"id": "C3Y9NQTQG",
"name": "channel"
}
]
}
},
{
"scope": "https://workspace.slack.com:443",
"method": "POST",
"path": "/api/files.share",
"body": "----------------------------898525272439246643720391\r\nContent-Disposition: form-data; name=\"token\"\r\n\r\nSLACK-SESSION-TOKEN\r\n----------------------------898525272439246643720391\r\nContent-Disposition: form-data; name=\"files\"\r\n\r\nF029QHN0AAZ,F02AH8J752L\r\n----------------------------898525272439246643720391\r\nContent-Disposition: form-data; name=\"channel\"\r\n\r\nC3Y9NQTQG\r\n----------------------------898525272439246643720391--\r\n",
"status": 200,
"response": {
"ok": true
},
"responseIsBinary": false
}
]
5 changes: 5 additions & 0 deletions test/index/self.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ describe('Testing Slack SDK', {
const r = await slack.self.message('message');
expect(r).to.deep.contain({ ok: true });
});

it('Testing self.shareFiles', async () => {
const r = await slack.self.shareFiles(['F029QHN0AAZ', 'F02AH8J752L']);
expect(r).to.deep.equal({ ok: true });
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[
{
"scope": "https://workspace.slack.com:443",
"method": "POST",
"path": "/api/rtm.start",
"body": "----------------------------004906267591311878777087\r\nContent-Disposition: form-data; name=\"token\"\r\n\r\nSLACK-SESSION-TOKEN\r\n----------------------------004906267591311878777087--\r\n",
"status": 200,
"response": {
"ok": true,
"self": {
"id": "U0G9QF9C6",
"name": "user.name"
},
"ims": [
{
"id": "D19NX2Y3Z",
"user": "U0G9QF9C6"
}
]
}
},
{
"scope": "https://workspace.slack.com:443",
"method": "POST",
"path": "/api/files.share",
"body": "----------------------------253285144519931620775601\r\nContent-Disposition: form-data; name=\"token\"\r\n\r\nSLACK-SESSION-TOKEN\r\n----------------------------253285144519931620775601\r\nContent-Disposition: form-data; name=\"files\"\r\n\r\nF029QHN0AAZ,F02AH8J752L\r\n----------------------------253285144519931620775601\r\nContent-Disposition: form-data; name=\"channel\"\r\n\r\nD19NX2Y3Z\r\n----------------------------253285144519931620775601--\r\n",
"status": 200,
"response": {
"ok": true
},
"responseIsBinary": false
}
]

0 comments on commit dc45c9c

Please sign in to comment.