Skip to content

Commit

Permalink
Enhance outgoing webhooks and add history (#5823)
Browse files Browse the repository at this point in the history
* Convert the majority of the integrations package to JavaScript

* Move the trigger handler to it's own class

* Start trying to generalize integration items

* Yay, additional events trigger outgoing webhooks

* Silence codacy and fix eslint problems.

* Started work on user created event for outgoing integrations

* Finish the outgoing integration work on the user created event.

* Add user join and leave room events for outgoing webhooks

* Add fields to the rest api integration creation and clean up the processWebhookMessage

* Add the HTTP to the incoming webhook context

* Don't check for property on result if it isn't there.
Closes #4175, #5762, and #5896.

* Add archive room and file upload events for the webhooks

* Disable integrations when the user to run/post as gets deleted.

* Try to fix the tests failing due to the requird events property

* Add history of integration which get fired

* Add the missing file for the IntegrationHistory

* Fix deleting users being broke due to my code

* Add the outgoing webhook integration history viewing page along with v1 rest api to retrieve it

* Integration history replays are now enabled along with advanced settings

* Work on the advanced settings and enable paging on the integration history

* Enable i18n for the history and advanced settings

* Update the wording on the word placement

* Move migration to be 88 now.

* Add missing translations for the webhooks

* Fix en.i18n.json identation

* Fix integrations.html indentation

* Fix more identations

* Fix identation of integrationsOutgoing.html
  • Loading branch information
graywolf336 authored and rodrigok committed Feb 16, 2017
1 parent 89c4d94 commit e888808
Show file tree
Hide file tree
Showing 65 changed files with 3,022 additions and 1,520 deletions.
35 changes: 34 additions & 1 deletion packages/rocketchat-api/server/v1/integrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ RocketChat.API.v1.addRoute('integrations.create', { authRequired: true }, {
username: String,
urls: [String],
channel: String,
event: String,
triggerWords: Match.Maybe([String]),
alias: Match.Maybe(String),
avatar: Match.Maybe(String),
emoji: Match.Maybe(String),
token: Match.Maybe(String),
scriptEnabled: Boolean,
script: Match.Maybe(String)
script: Match.Maybe(String),
targetChannel: Match.Maybe(String)
}));

let integration;
Expand All @@ -32,6 +34,37 @@ RocketChat.API.v1.addRoute('integrations.create', { authRequired: true }, {
}
});

RocketChat.API.v1.addRoute('integrations.history', { authRequired: true }, {
get: function() {
if (!RocketChat.authz.hasPermission(this.userId, 'manage-integrations')) {
return RocketChat.API.v1.unauthorized();
}

if (!this.queryParams.id || this.queryParams.id.trim() === '') {
return RocketChat.API.v1.failure('Invalid integration id.');
}

const id = this.queryParams.id;
const { offset, count } = this.getPaginationItems();
const { sort, fields, query } = this.parseJsonQuery();

const ourQuery = Object.assign({}, query, { 'integration._id': id });
const history = RocketChat.models.IntegrationHistory.find(ourQuery, {
sort: sort ? sort : { _updatedAt: -1 },
skip: offset,
limit: count,
fields
}).fetch();

return RocketChat.API.v1.success({
history,
offset,
items: history.length,
total: RocketChat.models.IntegrationHistory.find(ourQuery).count()
});
}
});

RocketChat.API.v1.addRoute('integrations.list', { authRequired: true }, {
get: function() {
if (!RocketChat.authz.hasPermission(this.userId, 'manage-integrations')) {
Expand Down
13 changes: 10 additions & 3 deletions packages/rocketchat-file-upload/server/methods/sendFileMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,24 @@ Meteor.methods({
attachment.video_size = file.size;
}

const msg = Object.assign({
const user = Meteor.user();
let msg = Object.assign({
_id: Random.id(),
rid: roomId,
ts: new Date(),
msg: '',
file: {
_id: file._id
_id: file._id,
name: file.name
},
groupable: false,
attachments: [attachment]
}, msgData);

return Meteor.call('sendMessage', msg);
msg = Meteor.call('sendMessage', msg);

Meteor.defer(() => RocketChat.callbacks.run('afterFileUpload', { user, room, message: msg }));

return msg;
}
});
42 changes: 41 additions & 1 deletion packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
"Back": "Back",
"Back_to_applications": "Back to applications",
"Back_to_integrations": "Back to integrations",
"Back_to_integration_detail": "Back to the integration detail",
"Back_to_login": "Back to login",
"Back_to_permissions": "Back to permissions",
"Beta_feature_Depends_on_Video_Conference_to_be_enabled": "Beta feature. Depends on Video Conference to be enabled.",
Expand Down Expand Up @@ -299,6 +300,7 @@
"Choose_the_username_that_this_integration_will_post_as": "Choose the username that this integration will post as.",
"clear": "Clear",
"clear_cache_now": "Clear cache now",
"clear_history": "Clear History",
"Clear_all_unreads_question": "Clear all unreads?",
"Click_here": "Click here",
"Click_here_for_more_info": "Click here for more info",
Expand Down Expand Up @@ -330,6 +332,7 @@
"Create_new": "Create new",
"Created_at": "Created at",
"Created_at_s_by_s": "Created at <strong>%s</strong> by <strong>%s</strong>",
"Created_at_s_by_s_triggered_by_s": "Created at <strong>%s</strong> by <strong>%s</strong> triggered by <strong>%s</strong>",
"CROWD_Reject_Unauthorized": "Reject Unauthorized",
"CRM_Integration": "CRM Integration",
"Current_Chats": "Current Chats",
Expand Down Expand Up @@ -522,6 +525,8 @@
"error-you-are-last-owner": "You are the last owner. Please set new owner before leaving the room.",
"Error_changing_password": "Error changing password",
"Esc_to": "Esc to",
"Event_Trigger": "Event Trigger",
"Event_Trigger_Description": "Select which type of event will trigger this Outgoing WebHook Integration",
"every_30_minutes": "Once every 30 minutes",
"every_hour": "Once every hour",
"every_six_hours": "Once every six hours",
Expand Down Expand Up @@ -671,11 +676,41 @@
"Instructions_to_your_visitor_fill_the_form_to_send_a_message": "Instructions to your visitor fill the form to send a message",
"Impersonate_user": "Impersonate User",
"Impersonate_user_description": "When enabled, integration posts as the user that triggered integration",
"Incoming_WebHook": "Incoming WebHook",
"Integration_Advanced_Settings": "Advanced Settings",
"Integration_added": "Integration has been added",
"Integration_History_Cleared": "Integration History Successfully Cleared",
"Integration_Incoming_WebHook": "Incoming WebHook Integration",
"Integration_New": "New Integration",
"Integrations_Outgoing_Type_FileUploaded": "File Uploaded",
"Integrations_Outgoing_Type_RoomArchived": "Room Archived",
"Integrations_Outgoing_Type_RoomCreated": "Room Created (public and private)",
"Integrations_Outgoing_Type_RoomJoined": "User Joined Room",
"Integrations_Outgoing_Type_RoomLeft": "User Left Room",
"Integrations_Outgoing_Type_SendMessage": "Message Sent",
"Integrations_Outgoing_Type_UserCreated": "User Created",
"Integration_Outgoing_WebHook": "Outgoing WebHook Integration",
"Integration_updated": "Integration has been updated",
"Integration_Outgoing_WebHook_History": "Outgoing WebHook Integration History",
"Integration_Outgoing_WebHook_No_History": "This outgoing webhook integration has yet to have any history recorded.",
"Integration_Outgoing_WebHook_History_Time_Triggered": "Time Integration Triggered",
"Integration_Outgoing_WebHook_History_Time_Ended_Or_Error": "Time it Ended or Error'd",
"Integration_Outgoing_WebHook_History_Trigger_Step": "Last Trigger Step",
"Integration_Outgoing_WebHook_History_Messages_Sent_From_Prepare_Script": "Messages Sent from Prepare Step",
"Integration_Outgoing_WebHook_History_Messages_Sent_From_Process_Script": "Messages Sent from Process Response Step",
"Integration_Outgoing_WebHook_History_Data_Passed_To_Trigger": "Data Passed to Integration",
"Integration_Outgoing_WebHook_History_Data_Passed_To_URL": "Data Passed to URL",
"Integration_Outgoing_WebHook_History_Http_Response_Error": "HTTP Response Error",
"Integration_Outgoing_WebHook_History_Http_Response": "HTTP Response",
"Integration_Outgoing_WebHook_History_Error_Stacktrace": "Error Stacktrace",
"Integration_Retry_Failed_Url_Calls": "Retry Failed Url Calls",
"Integration_Retry_Failed_Url_Calls_Description": "Should the integration try a reasonable amount of time if the call out to the url fails?",
"Integration_Retry_Count": "Retry Count",
"Integration_Retry_Count_Description": "How many times should the integration be tried if the call to the url fails?",
"Integration_Retry_Delay": "Retry Delay",
"Integration_Retry_Delay_Description": "Which delay algorithm should the retrying use? <code class=\"inline\">10^x</code> or <code class=\"inline\">2^x</code> or <code class=\"inline\">x*2</code>",
"Integration_Word_Trigger_Placement": "Word Placement Anywhere",
"Integration_Word_Trigger_Placement_Description": "Should the Word be Triggered when placed anywhere in the sentence other than the beginning?",
"Integration_updated": "Integration has been updated.",
"Integrations": "Integrations",
"Integrations_for_all_channels": "Enter <strong>all_public_channels</strong> to listen on all public channels, <strong>all_private_groups</strong> to listen on all private groups, and <strong>all_direct_messages</strong> to listen to all direct messages.",
"InternalHubot": "Internal Hubot",
Expand Down Expand Up @@ -990,6 +1025,7 @@
"No_Encryption": "No Encryption",
"No_group_with_name_%s_was_found": "No private group with name <strong>\"%s\"</strong> was found!",
"No_groups_yet": "You have no private groups yet.",
"No_integration_found": "No integration found by the provided id.",
"No_livechats": "You have no livechats.",
"No_mentions_found": "No mentions found",
"No_pinned_messages": "No pinned messages",
Expand Down Expand Up @@ -1057,6 +1093,8 @@
"others": "others",
"OTR": "OTR",
"OTR_is_only_available_when_both_users_are_online": "OTR is only available when both users are online",
"Outgoing_WebHook": "Outgoing WebHook",
"Outgoing_WebHook_Description": "Get data out of Rocket.Chat in real-time.",
"Override_URL_to_which_files_are_uploaded_This_url_also_used_for_downloads_unless_a_CDN_is_given": "Override URL to which files are uploaded. This url also used for downloads unless a CDN is given",
"Page_title": "Page title",
"Page_URL": "Page URL",
Expand Down Expand Up @@ -1366,6 +1404,8 @@
"System_messages": "System Messages",
"Tag": "Tag",
"Take_it": "Take it!",
"TargetRoom": "Target Room",
"TargetRoom_Description": "The room where messages will be sent which are a result of this event being fired. Only one target room is allowed and it must exist.",
"Test_Connection": "Test Connection",
"Test_Desktop_Notifications": "Test Desktop Notifications",
"Thank_you_exclamation_mark": "Thank you!",
Expand Down
1 change: 0 additions & 1 deletion packages/rocketchat-integrations/client/collection.coffee

This file was deleted.

2 changes: 2 additions & 0 deletions packages/rocketchat-integrations/client/collections.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
this.ChatIntegrations = new Meteor.Collection('rocketchat_integrations');
this.ChatIntegrationHistory = new Meteor.Collection('rocketchat_integration_history');
41 changes: 0 additions & 41 deletions packages/rocketchat-integrations/client/route.coffee

This file was deleted.

62 changes: 62 additions & 0 deletions packages/rocketchat-integrations/client/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
FlowRouter.route('/admin/integrations', {
name: 'admin-integrations',
subscriptions() {
this.register('integrations', Meteor.subscribe('integrations'));
},
action() {
return BlazeLayout.render('main', {
center: 'integrations',
pageTitle: t('Integrations')
});
}
});

FlowRouter.route('/admin/integrations/new', {
name: 'admin-integrations-new',
subscriptions() {
this.register('integrations', Meteor.subscribe('integrations'));
},
action() {
return BlazeLayout.render('main', {
center: 'integrationsNew',
pageTitle: t('Integration_New')
});
}
});

FlowRouter.route('/admin/integrations/incoming/:id?', {
name: 'admin-integrations-incoming',
subscriptions() {
this.register('integrations', Meteor.subscribe('integrations'));
},
action(params) {
return BlazeLayout.render('main', {
center: 'pageSettingsContainer',
pageTitle: t('Integration_Incoming_WebHook'),
pageTemplate: 'integrationsIncoming',
params
});
}
});

FlowRouter.route('/admin/integrations/outgoing/:id?', {
name: 'admin-integrations-outgoing',
action(params) {
return BlazeLayout.render('main', {
center: 'integrationsOutgoing',
pageTitle: t('Integration_Outgoing_WebHook'),
params
});
}
});

FlowRouter.route('/admin/integrations/outgoing/:id?/history', {
name: 'admin-integrations-outgoing-history',
action(params) {
return BlazeLayout.render('main', {
center: 'integrationsOutgoingHistory',
pageTitle: t('Integration_Outgoing_WebHook_History'),
params
});
}
});
5 changes: 0 additions & 5 deletions packages/rocketchat-integrations/client/startup.coffee

This file was deleted.

5 changes: 5 additions & 0 deletions packages/rocketchat-integrations/client/startup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
RocketChat.AdminBox.addOption({
href: 'admin-integrations',
i18nLabel: 'Integrations',
permissionGranted: () => RocketChat.authz.hasAtLeastOnePermission(['manage-integrations', 'manage-own-integrations'])
});
11 changes: 0 additions & 11 deletions packages/rocketchat-integrations/client/views/integrations.coffee

This file was deleted.

Loading

0 comments on commit e888808

Please sign in to comment.