-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apps: Command Previews, Message and Room Removal Events #10822
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0dd45d9
Add message and room removal events for Apps, fix a few other issues
graywolf336 6f73bfb
First very rough draft of the slash command preview
graywolf336 fafc6da
Add the command preview rest api and make the previews selectable via…
graywolf336 5eb1a4b
Merge branch 'develop' into apps/features-for-may
rodrigok 1040141
Add loading i18n
sampaiodiego d6558c2
Remove duplicated toLowerCase()
sampaiodiego File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ RocketChat.API.v1.addRoute('commands.run', { authRequired: true }, { | |
} | ||
|
||
if (typeof body.roomId !== 'string') { | ||
return RocketChat.API.v1.failure('The room\'s id where to execute this command must provided and be a string.'); | ||
return RocketChat.API.v1.failure('The room\'s id where to execute this command must be provided and be a string.'); | ||
} | ||
|
||
const cmd = body.command.toLowerCase(); | ||
|
@@ -84,3 +84,81 @@ RocketChat.API.v1.addRoute('commands.run', { authRequired: true }, { | |
return RocketChat.API.v1.success({ result }); | ||
} | ||
}); | ||
|
||
RocketChat.API.v1.addRoute('commands.preview', { authRequired: true }, { | ||
// Expects these query params: command: 'giphy', params: 'mine', roomId: 'value' | ||
get() { | ||
const query = this.queryParams; | ||
const user = this.getLoggedInUser(); | ||
|
||
if (typeof query.command !== 'string') { | ||
return RocketChat.API.v1.failure('You must provide a command to get the previews from.'); | ||
} | ||
|
||
if (query.params && typeof query.params !== 'string') { | ||
return RocketChat.API.v1.failure('The parameters for the command must be a single string.'); | ||
} | ||
|
||
if (typeof query.roomId !== 'string') { | ||
return RocketChat.API.v1.failure('The room\'s id where the previews are being displayed must be provided and be a string.'); | ||
} | ||
|
||
const cmd = query.command.toLowerCase(); | ||
if (!RocketChat.slashCommands.commands[query.command.toLowerCase()]) { | ||
return RocketChat.API.v1.failure('The command provided does not exist (or is disabled).'); | ||
} | ||
|
||
// This will throw an error if they can't or the room is invalid | ||
Meteor.call('canAccessRoom', query.roomId, user._id); | ||
|
||
const params = query.params ? query.params : ''; | ||
|
||
let preview; | ||
Meteor.runAsUser(user._id, () => { | ||
preview = Meteor.call('getSlashCommandPreviews', { cmd, params, msg: { rid: query.roomId } }); | ||
}); | ||
|
||
return RocketChat.API.v1.success({ preview }); | ||
}, | ||
// Expects a body format of: { command: 'giphy', params: 'mine', roomId: 'value', previewItem: { id: 'sadf8' type: 'image', value: 'https://dev.null/gif } } | ||
post() { | ||
const body = this.bodyParams; | ||
const user = this.getLoggedInUser(); | ||
|
||
if (typeof body.command !== 'string') { | ||
return RocketChat.API.v1.failure('You must provide a command to run the preview item on.'); | ||
} | ||
|
||
if (body.params && typeof body.params !== 'string') { | ||
return RocketChat.API.v1.failure('The parameters for the command must be a single string.'); | ||
} | ||
|
||
if (typeof body.roomId !== 'string') { | ||
return RocketChat.API.v1.failure('The room\'s id where the preview is being executed in must be provided and be a string.'); | ||
} | ||
|
||
if (typeof body.previewItem === 'undefined') { | ||
return RocketChat.API.v1.failure('The preview item being executed must be provided.'); | ||
} | ||
|
||
if (!body.previewItem.id || !body.previewItem.type || typeof body.previewItem.value === 'undefined') { | ||
return RocketChat.API.v1.failure('The preview item being executed is in the wrong format.'); | ||
} | ||
|
||
const cmd = body.command.toLowerCase(); | ||
if (!RocketChat.slashCommands.commands[body.command.toLowerCase()]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to repeat |
||
return RocketChat.API.v1.failure('The command provided does not exist (or is disabled).'); | ||
} | ||
|
||
// This will throw an error if they can't or the room is invalid | ||
Meteor.call('canAccessRoom', body.roomId, user._id); | ||
|
||
const params = body.params ? body.params : ''; | ||
|
||
Meteor.runAsUser(user._id, () => { | ||
Meteor.call('executeSlashCommandPreview', { cmd, params, msg: { rid: body.roomId } }, body.previewItem); | ||
}); | ||
|
||
return RocketChat.API.v1.success(); | ||
} | ||
}); |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to repeat
query.command.toLowerCase();