diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json
index a11b1467df10..424825969ce0 100644
--- a/packages/rocketchat-i18n/i18n/en.i18n.json
+++ b/packages/rocketchat-i18n/i18n/en.i18n.json
@@ -736,6 +736,8 @@
"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? 10^x
or 2^x
or x*2
",
+ "Integration_Run_When_Message_Is_Edited": "Run On Edits",
+ "Integration_Run_When_Message_Is_Edited_Description": "Should the integration run when the message is edited? Setting this to false will cause the integration to only run on new messages.",
"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.",
diff --git a/packages/rocketchat-integrations/client/views/integrationsOutgoing.html b/packages/rocketchat-integrations/client/views/integrationsOutgoing.html
index 2a2e6b9e8656..687be0a6ca1a 100644
--- a/packages/rocketchat-integrations/client/views/integrationsOutgoing.html
+++ b/packages/rocketchat-integrations/client/views/integrationsOutgoing.html
@@ -225,6 +225,14 @@
{{_ "Integration_Word_Trigger_Placement_Description"}}
+
{{/if}}
diff --git a/packages/rocketchat-integrations/client/views/integrationsOutgoing.js b/packages/rocketchat-integrations/client/views/integrationsOutgoing.js
index d8a9418fd47b..8c98f87e0701 100644
--- a/packages/rocketchat-integrations/client/views/integrationsOutgoing.js
+++ b/packages/rocketchat-integrations/client/views/integrationsOutgoing.js
@@ -9,7 +9,8 @@ Template.integrationsOutgoing.onCreated(function _integrationsOutgoingOnCreated(
token: Random.id(24),
retryFailedCalls: true,
retryCount: 6,
- retryDelay: 'powers-of-ten'
+ retryDelay: 'powers-of-ten',
+ runOnEdits: true
});
this.updateRecord = () => {
@@ -31,7 +32,8 @@ Template.integrationsOutgoing.onCreated(function _integrationsOutgoingOnCreated(
triggerWordAnywhere: $('[name=triggerWordAnywhere]').val() ? $('[name=triggerWordAnywhere]').val().trim() : undefined,
retryFailedCalls: $('[name=retryFailedCalls]:checked').val().trim() === '1',
retryCount: $('[name=retryCount]').val() ? $('[name=retryCount]').val().trim() : 6,
- retryDelay: $('[name=retryDelay]').val() ? $('[name=retryDelay]').val().trim() : 'powers-of-ten'
+ retryDelay: $('[name=retryDelay]').val() ? $('[name=retryDelay]').val().trim() : 'powers-of-ten',
+ runOnEdits: $('[name=runOnEdits]:checked').val().trim() === '1'
});
};
@@ -287,11 +289,13 @@ Template.integrationsOutgoing.events({
let triggerWords;
let triggerWordAnywhere;
+ let runOnEdits;
if (RocketChat.integrations.outgoingEvents[event].use.triggerWords) {
triggerWords = $('[name=triggerWords]').val().trim();
triggerWords = triggerWords.split(',').filter((word) => word.trim() !== '');
triggerWordAnywhere = $('[name=triggerWordAnywhere]').val().trim();
+ runOnEdits = $('[name=runOnEdits]:checked').val().trim();
}
let channel;
@@ -338,7 +342,8 @@ Template.integrationsOutgoing.events({
retryFailedCalls: retryFailedCalls === '1',
retryCount: retryCount ? retryCount : 6,
retryDelay: retryDelay ? retryDelay : 'powers-of-ten',
- triggerWordAnywhere: triggerWordAnywhere === '1'
+ triggerWordAnywhere: triggerWordAnywhere === '1',
+ runOnEdits: runOnEdits === '1'
};
const params = Template.instance().data.params? Template.instance().data.params() : undefined;
diff --git a/packages/rocketchat-integrations/server/lib/triggerHandler.js b/packages/rocketchat-integrations/server/lib/triggerHandler.js
index a40664743305..a06a8f4bdaa5 100644
--- a/packages/rocketchat-integrations/server/lib/triggerHandler.js
+++ b/packages/rocketchat-integrations/server/lib/triggerHandler.js
@@ -389,6 +389,10 @@ RocketChat.integrations.triggerHandler = new class RocketChatIntegrationHandler
if (message.bot) {
data.bot = message.bot;
}
+
+ if (message.editedAt) {
+ data.isEdited = true;
+ }
break;
case 'fileUploaded':
data.channel_id = room._id;
@@ -585,6 +589,11 @@ RocketChat.integrations.triggerHandler = new class RocketChatIntegrationHandler
}
}
+ if (message && message.editedAt && !trigger.runOnEdits) {
+ logger.outgoing.debug(`The trigger "${ trigger.name }"'s run on edits is disabled and the message was edited.`);
+ return;
+ }
+
const historyId = this.updateHistory({ step: 'start-execute-trigger-url', integration: trigger, event });
const data = {
diff --git a/packages/rocketchat-integrations/server/lib/validation.js b/packages/rocketchat-integrations/server/lib/validation.js
index 9da2094cb763..d25a42c45e18 100644
--- a/packages/rocketchat-integrations/server/lib/validation.js
+++ b/packages/rocketchat-integrations/server/lib/validation.js
@@ -138,6 +138,11 @@ RocketChat.integrations.validateOutgoing = function _validateOutgoing(integratio
}
}
+ if (typeof integration.runOnEdits !== 'undefined') {
+ // Verify this value is only true/false
+ integration.runOnEdits = integration.runOnEdits === true;
+ }
+
_verifyUserHasPermissionForChannels(integration, userId, channels);
_verifyRetryInformation(integration);
diff --git a/packages/rocketchat-integrations/server/methods/outgoing/updateOutgoingIntegration.js b/packages/rocketchat-integrations/server/methods/outgoing/updateOutgoingIntegration.js
index aaf1f3376bc3..7719215729c9 100644
--- a/packages/rocketchat-integrations/server/methods/outgoing/updateOutgoingIntegration.js
+++ b/packages/rocketchat-integrations/server/methods/outgoing/updateOutgoingIntegration.js
@@ -44,6 +44,7 @@ Meteor.methods({
retryCount: integration.retryCount,
retryDelay: integration.retryDelay,
triggerWordAnywhere: integration.triggerWordAnywhere,
+ runOnEdits: integration.runOnEdits,
_updatedAt: new Date(),
_updatedBy: RocketChat.models.Users.findOne(this.userId, {fields: {username: 1}})
}
diff --git a/server/startup/migrations/v092.js b/server/startup/migrations/v092.js
new file mode 100644
index 000000000000..b88165afe17a
--- /dev/null
+++ b/server/startup/migrations/v092.js
@@ -0,0 +1,10 @@
+RocketChat.Migrations.add({
+ version: 92,
+ up() {
+ const outgoingIntegrations = RocketChat.models.Integrations.find({ type: 'webhook-outgoing', 'event': 'sendMessage' }, { fields: { name: 1 }}).fetch();
+
+ outgoingIntegrations.forEach((i) => {
+ RocketChat.models.Integrations.update(i._id, { $set: { runOnEdits: true }});
+ });
+ }
+});