Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1137 from blackflux/dev
[Gally]: master <- dev
- Loading branch information
Showing
28 changed files
with
606 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const getChannelMeta = require('./util/get-channel-meta'); | ||
|
||
module.exports = (call) => ({ | ||
meta: (name) => getChannelMeta(call, name), | ||
message: async (name, msg) => { | ||
const channel = await getChannelMeta(call, name); | ||
return call('chat.postMessage', { | ||
text: msg, | ||
channel: channel.id | ||
}); | ||
}, | ||
setTopic: async (name, topic) => { | ||
const channel = await getChannelMeta(call, name); | ||
return call('conversations.setTopic', { | ||
topic, | ||
channel: channel.id | ||
}); | ||
}, | ||
setPurpose: async (name, purpose) => { | ||
const channel = await getChannelMeta(call, name); | ||
return call('conversations.setPurpose', { | ||
purpose, | ||
channel: channel.id | ||
}); | ||
}, | ||
shareFiles: async (name, files) => { | ||
const channel = await getChannelMeta(call, name); | ||
return call('files.share', { | ||
files: files.join(','), | ||
channel: channel.id | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('assert'); | ||
const FormData = require('form-data'); | ||
const axios = require('axios'); | ||
|
||
module.exports = (call) => ({ | ||
upload: async (filepath, title_ = null, filename_ = null) => { | ||
// prepare | ||
const basename = path.basename(filepath); | ||
const title = title_ === null ? basename : title_; | ||
const filename = filename_ === null ? basename : filename_; | ||
const stat = fs.statSync(filepath); | ||
|
||
// get upload information | ||
const getUploadUrlResponse = await call('files.getUploadURL', { filename, length: stat.size }); | ||
assert(getUploadUrlResponse.ok === true, getUploadUrlResponse); | ||
|
||
// upload | ||
const formData = new FormData(); | ||
formData.append('file', fs.createReadStream(filepath)); | ||
const requestParams = { | ||
method: 'post', | ||
url: getUploadUrlResponse.upload_url, | ||
data: formData, | ||
headers: { | ||
// eslint-disable-next-line no-underscore-dangle | ||
'Content-Type': `multipart/form-data; boundary=${formData._boundary}`, | ||
...formData.getHeaders() | ||
} | ||
}; | ||
const { data } = await axios(requestParams); | ||
assert(data === `OK - ${stat.size}`); | ||
|
||
// complete upload | ||
const completeUploadResponse = await call('files.completeUpload', { | ||
files: JSON.stringify([{ id: getUploadUrlResponse.file, title }]) | ||
}); | ||
assert(completeUploadResponse.ok === true, completeUploadResponse); | ||
assert(completeUploadResponse.files.length === 1, completeUploadResponse); | ||
return completeUploadResponse.files[0].id; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const getSelf = require('./util/get-self'); | ||
|
||
module.exports = (call) => ({ | ||
message: async (msg) => { | ||
const self = await getSelf(call); | ||
return call('chat.command', { | ||
disp: '/me', | ||
command: '/msg', | ||
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 | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = async (call, name) => { | ||
const rtmStart = await call('rtm.start', {}, true); | ||
const channel = rtmStart.channels.find((chan) => chan.name === name); | ||
if (!channel) { | ||
throw new Error(`Channel "${name}" not found.`); | ||
} | ||
return channel; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = (call) => ({ | ||
details: (cache = true) => call('rtm.start', {}, cache) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const expect = require('chai').expect; | ||
const { describe } = require('node-tdd'); | ||
const Slack = require('../../src/index'); | ||
|
||
describe('Testing Slack SDK', { | ||
useNock: true, | ||
cryptoSeed: '3eced0c2-38ea-4bc4-9045-ee0cb68bd688', | ||
timestamp: '2020-07-13T16:14:25.488Z' | ||
}, () => { | ||
let slack; | ||
beforeEach(() => { | ||
slack = Slack('workspace', 'SLACK-SESSION-TOKEN'); | ||
}); | ||
|
||
it('Testing channel.meta', async () => { | ||
const r = await slack.channel.meta('channel'); | ||
expect(r).to.deep.equal({ | ||
id: 'C3Y9NQTQG', | ||
name: 'channel' | ||
}); | ||
}); | ||
|
||
it('Testing channel.message', async () => { | ||
const r = await slack.channel.message('channel', 'message'); | ||
expect(r).to.deep.contain({ ok: true }); | ||
}); | ||
|
||
it('Testing channel.message-unknown', async ({ capture }) => { | ||
const e = await capture(() => slack.channel.message('unknown', 'message')); | ||
expect(e.message).to.equal('Channel "unknown" not found.'); | ||
}); | ||
|
||
it('Testing channel.setTopic', async () => { | ||
const r = await slack.channel.setTopic('channel', 'topic'); | ||
expect(r).to.deep.contain({ ok: true }); | ||
}); | ||
|
||
it('Testing channel.setPurpose', async () => { | ||
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 }); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
test/index/channel.spec.js__cassettes/testingSlackSDK_testingChannelMeta_recording.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[ | ||
{ | ||
"scope": "https://workspace.slack.com:443", | ||
"method": "POST", | ||
"path": "/api/rtm.start", | ||
"body": "----------------------------143695343986972598734041\r\nContent-Disposition: form-data; name=\"token\"\r\n\r\nSLACK-SESSION-TOKEN\r\n----------------------------143695343986972598734041--\r\n", | ||
"status": 200, | ||
"response": { | ||
"ok": true, | ||
"channels": [ | ||
{ | ||
"id": "C3Y9NQTQG", | ||
"name": "channel" | ||
} | ||
] | ||
} | ||
} | ||
] |
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions
29
.../index/channel.spec.js__cassettes/testingSlackSDK_testingChannelShareFiles_recording.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] |
Oops, something went wrong.