-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] Slackbridge private channels (#14273)
* Fix SlackBridge private channels * WIP: fix slackbridge private rooms does not send message back to slack * Fix lint * WIP: move slack api calls to a specififc file * Changed all references directly to the slack api * Fix reactions to execute unsetReaction always when a reaction was removed * Add function to retrieve all members of slack channel and remove old code * Add function to retrieve all members of slack channel and remove old code * Fix send files from slack to rocket * Fix lint and remove unused code * Fix error on slackbridge importer * Fix roompick in admin page, related to choose room to publish in slackbridge * Fix callbacks order * Fixed merge error * Fixed file upload
- Loading branch information
Showing
6 changed files
with
252 additions
and
137 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { HTTP } from 'meteor/http'; | ||
|
||
export class SlackAPI { | ||
|
||
constructor(apiToken) { | ||
this.apiToken = apiToken; | ||
} | ||
|
||
getChannels() { | ||
const response = HTTP.get('https://slack.com/api/conversations.list', { | ||
params: { | ||
token: this.apiToken, | ||
types: 'public_channel', | ||
}, | ||
}); | ||
return response && response.data && Array.isArray(response.data.channels) && response.data.channels.length > 0 | ||
? response.data.channels | ||
: []; | ||
} | ||
|
||
getGroups() { | ||
const response = HTTP.get('https://slack.com/api/conversations.list', { | ||
params: { | ||
token: this.apiToken, | ||
types: 'private_channel', | ||
}, | ||
}); | ||
return response && response.data && Array.isArray(response.data.channels) && response.data.channels.length > 0 | ||
? response.data.channels | ||
: []; | ||
} | ||
|
||
getRoomInfo(roomId) { | ||
const response = HTTP.get('https://slack.com/api/conversations.info', { | ||
params: { | ||
token: this.apiToken, | ||
channel: roomId, | ||
include_num_members: true, | ||
}, | ||
}); | ||
return response && response.data && response.statusCode === 200 && response.data.ok && response.data.channel; | ||
} | ||
|
||
getMembers(channelId) { | ||
const { num_members } = this.getRoomInfo(channelId); | ||
const MAX_MEMBERS_PER_CALL = 100; | ||
let members = []; | ||
let currentCursor = ''; | ||
for (let index = 0; index < num_members; index += MAX_MEMBERS_PER_CALL) { | ||
const response = HTTP.get('https://slack.com/api/conversations.members', { | ||
params: { | ||
token: this.apiToken, | ||
channel: channelId, | ||
limit: MAX_MEMBERS_PER_CALL, | ||
cursor: currentCursor, | ||
}, | ||
}); | ||
if (response && response.data && response.statusCode === 200 && response.data.ok && Array.isArray(response.data.members)) { | ||
members = members.concat(response.data.members); | ||
const hasMoreItems = response.data.response_metadata && response.data.response_metadata.next_cursor; | ||
if (hasMoreItems) { | ||
currentCursor = response.data.response_metadata.next_cursor; | ||
} | ||
} | ||
} | ||
return members; | ||
} | ||
|
||
react(data) { | ||
const response = HTTP.post('https://slack.com/api/reactions.add', { params: data }); | ||
return response && response.statusCode === 200 && response.data && response.data.ok; | ||
} | ||
|
||
removeReaction(data) { | ||
const response = HTTP.post('https://slack.com/api/reactions.remove', { params: data }); | ||
return response && response.statusCode === 200 && response.data && response.data.ok; | ||
} | ||
|
||
removeMessage(data) { | ||
const response = HTTP.post('https://slack.com/api/chat.delete', { params: data }); | ||
return response && response.statusCode === 200 && response.data && response.data.ok; | ||
} | ||
|
||
sendMessage(data) { | ||
return HTTP.post('https://slack.com/api/chat.postMessage', { params: data }); | ||
} | ||
|
||
updateMessage(data) { | ||
const response = HTTP.post('https://slack.com/api/chat.update', { params: data }); | ||
return response && response.statusCode === 200 && response.data && response.data.ok; | ||
} | ||
|
||
getHistory(family, options) { | ||
const response = HTTP.get(`https://slack.com/api/${ family }.history`, { params: Object.assign({ token: this.apiToken }, options) }); | ||
return response && response.data; | ||
} | ||
|
||
getPins(channelId) { | ||
const response = HTTP.get('https://slack.com/api/pins.list', { | ||
params: { | ||
token: this.apiToken, | ||
channel: channelId, | ||
}, | ||
}); | ||
return response && response.data && response.statusCode === 200 && response.data.ok && response.data.items; | ||
} | ||
|
||
getUser(userId) { | ||
const response = HTTP.get('https://slack.com/api/users.info', { | ||
params: { | ||
token: this.apiToken, | ||
user: userId, | ||
}, | ||
}); | ||
return response && response.data && response.statusCode === 200 && response.data.ok && response.data.user; | ||
} | ||
|
||
} |
Oops, something went wrong.