-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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 #1744 from RocketChat/improvements/outgoing-hooks
Improvements/outgoing hooks
- Loading branch information
Showing
20 changed files
with
654 additions
and
50 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
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
170 changes: 170 additions & 0 deletions
170
packages/rocketchat-integrations/client/views/integrationsOutgoing.coffee
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,170 @@ | ||
Template.integrationsOutgoing.onCreated -> | ||
@record = new ReactiveVar | ||
username: 'rocket.cat' | ||
token: Random.id(24) | ||
|
||
|
||
Template.integrationsOutgoing.helpers | ||
|
||
join: (arr, sep) -> | ||
if not arr?.join? | ||
return arr | ||
|
||
return arr.join sep | ||
|
||
hasPermission: -> | ||
return RocketChat.authz.hasAllPermission 'manage-integrations' | ||
|
||
data: -> | ||
params = Template.instance().data.params?() | ||
|
||
if params?.id? | ||
data = ChatIntegrations.findOne({_id: params.id}) | ||
if data? | ||
if not data.token? | ||
data.token = Random.id(24) | ||
return data | ||
|
||
return Template.instance().record.curValue | ||
|
||
example: -> | ||
record = Template.instance().record.get() | ||
return {} = | ||
_id: Random.id() | ||
alias: record.alias | ||
emoji: record.emoji | ||
avatar: record.avatar | ||
msg: 'Response text' | ||
bot: | ||
i: Random.id() | ||
groupable: false | ||
attachments: [{ | ||
title: "Rocket.Chat" | ||
title_link: "https://rocket.chat" | ||
text: "Rocket.Chat, the best open source chat" | ||
image_url: "https://rocket.chat/images/mockup.png" | ||
color: "#764FA5" | ||
}] | ||
ts: new Date | ||
u: | ||
_id: Random.id() | ||
username: record.username | ||
|
||
exampleJson: -> | ||
record = Template.instance().record.get() | ||
data = | ||
username: record.alias | ||
icon_emoji: record.emoji | ||
icon_url: record.avatar | ||
text: 'Response text' | ||
attachments: [{ | ||
title: "Rocket.Chat" | ||
title_link: "https://rocket.chat" | ||
text: "Rocket.Chat, the best open source chat" | ||
image_url: "https://rocket.chat/images/mockup.png" | ||
color: "#764FA5" | ||
}] | ||
|
||
for key, value of data | ||
delete data[key] if value in [null, ""] | ||
|
||
return hljs.highlight('json', JSON.stringify(data, null, 2)).value | ||
|
||
|
||
Template.integrationsOutgoing.events | ||
"blur input": (e, t) -> | ||
t.record.set | ||
name: $('[name=name]').val().trim() | ||
alias: $('[name=alias]').val().trim() | ||
emoji: $('[name=emoji]').val().trim() | ||
avatar: $('[name=avatar]').val().trim() | ||
channel: $('[name=channel]').val().trim() | ||
username: $('[name=username]').val().trim() | ||
triggerWords: $('[name=triggerWords]').val().trim() | ||
urls: $('[name=urls]').val().trim() | ||
token: $('[name=token]').val().trim() | ||
|
||
|
||
"click .submit > .delete": -> | ||
params = Template.instance().data.params() | ||
|
||
swal | ||
title: t('Are_you_sure') | ||
text: t('You_will_not_be_able_to_recover') | ||
type: 'warning' | ||
showCancelButton: true | ||
confirmButtonColor: '#DD6B55' | ||
confirmButtonText: t('Yes_delete_it') | ||
cancelButtonText: t('Cancel') | ||
closeOnConfirm: false | ||
html: false | ||
, -> | ||
Meteor.call "deleteOutgoingIntegration", params.id, (err, data) -> | ||
swal | ||
title: t('Deleted') | ||
text: t('Your_entry_has_been_deleted') | ||
type: 'success' | ||
timer: 1000 | ||
showConfirmButton: false | ||
|
||
FlowRouter.go "admin-integrations" | ||
|
||
"click .submit > .save": -> | ||
name = $('[name=name]').val().trim() | ||
alias = $('[name=alias]').val().trim() | ||
emoji = $('[name=emoji]').val().trim() | ||
avatar = $('[name=avatar]').val().trim() | ||
channel = $('[name=channel]').val().trim() | ||
username = $('[name=username]').val().trim() | ||
triggerWords = $('[name=triggerWords]').val().trim() | ||
urls = $('[name=urls]').val().trim() | ||
token = $('[name=token]').val().trim() | ||
|
||
if username is '' | ||
return toastr.error TAPi18n.__("The_username_is_required") | ||
|
||
triggerWords = triggerWords.split(',') | ||
for triggerWord, index in triggerWords | ||
triggerWords[index] = triggerWord.trim() | ||
delete triggerWords[index] if triggerWord.trim() is '' | ||
|
||
triggerWords = _.without triggerWords, [undefined] | ||
|
||
if triggerWords.length is 0 and channel.trim() is '' | ||
return toastr.error TAPi18n.__("You should inform at least one trigger word if you do not inform a channel") | ||
|
||
urls = urls.split('\n') | ||
for url, index in urls | ||
urls[index] = url.trim() | ||
delete urls[index] if url.trim() is '' | ||
|
||
urls = _.without urls, [undefined] | ||
|
||
if urls.length is 0 | ||
return toastr.error TAPi18n.__("You_should_inform_one_url_at_least") | ||
|
||
integration = | ||
channel: channel | ||
username: username | ||
alias: alias if alias isnt '' | ||
emoji: emoji if emoji isnt '' | ||
avatar: avatar if avatar isnt '' | ||
name: name if name isnt '' | ||
triggerWords: triggerWords if triggerWords isnt '' | ||
urls: urls if urls isnt '' | ||
token: token if token isnt '' | ||
|
||
params = Template.instance().data.params?() | ||
if params?.id? | ||
Meteor.call "updateOutgoingIntegration", params.id, integration, (err, data) -> | ||
if err? | ||
return toastr.error TAPi18n.__(err.error) | ||
|
||
toastr.success TAPi18n.__("Integration_updated") | ||
else | ||
Meteor.call "addOutgoingIntegration", integration, (err, data) -> | ||
if err? | ||
return toastr.error TAPi18n.__(err.error) | ||
|
||
toastr.success TAPi18n.__("Integration_added") | ||
FlowRouter.go "admin-integrations-outgoing", {id: data._id} |
Oops, something went wrong.