Skip to content
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

[NEW] Livechat trigger option to run only once #12068

Merged
merged 2 commits into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,7 @@
"Room_uploaded_file_list": "Files List",
"Room_uploaded_file_list_empty": "No files available.",
"Rooms": "Rooms",
"Run_only_once_for_each_visitor": "Run only once for each visitor",
"run-import": "Run Import",
"run-import_description": "Permission to run the importers",
"run-migration": "Run Migration",
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-i18n/i18n/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,8 @@
"Room_unarchived": "Sala desarquivada",
"Room_uploaded_file_list": "Lista de arquivos",
"Room_uploaded_file_list_empty": "Nenhum arquivo disponível",
"Rooms": "Salas",
"Rooms": "Salas",
"Run_only_once_for_each_visitor": "Rodar apenas uma vez por visitante",
"run-import": "Executar importação",
"run-import_description": "Permissão para executar os importadores",
"run-migration": "Executar migração",
Expand Down
16 changes: 16 additions & 0 deletions packages/rocketchat-livechat/.app/client/lib/triggers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* globals Livechat */
import visitor from '../../imports/client/visitor';

const firedTriggers = JSON.parse(localStorage.getItem('rocketChatFiredTriggers')) || [];

function getAgent(triggerAction) {
return new Promise((resolve, reject) => {
const { params } = triggerAction;
Expand Down Expand Up @@ -77,6 +79,12 @@ this.Triggers = (function() {
});
}
});

if (trigger.runOnce) {
trigger.skip = true;
firedTriggers.push(trigger._id);
localStorage.setItem('rocketChatFiredTriggers', JSON.stringify(firedTriggers));
}
};

const processRequest = function(request) {
Expand Down Expand Up @@ -115,6 +123,14 @@ this.Triggers = (function() {
const init = function() {
initiated = true;

firedTriggers.forEach((triggerId) => {
triggers.forEach((trigger) => {
if (trigger._id === triggerId) {
trigger.skip = true;
}
});
});

if (requests.length > 0 && triggers.length > 0) {
requests.forEach(function(request) {
processRequest(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
<label><input type="radio" name="enabled" value="0" checked="{{$eq enabled false}}" /> {{_ "No"}}</label>
</div>
</div>
<div class="input-line">
<label>{{_ "Run_only_once_for_each_visitor"}}</label>
<div>
<label><input type="radio" name="runOnce" value="1" checked="{{$eq runOnce true}}" /> {{_ "Yes"}}</label>
<label><input type="radio" name="runOnce" value="0" checked="{{$eq runOnce false}}" /> {{_ "No"}}</label>
</div>
</div>
<div class="input-line">
<label>{{_ "Name"}}</label>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Template.livechatTriggersForm.helpers({
const trigger = LivechatTrigger.findOne(FlowRouter.getParam('_id'));
return trigger && trigger.enabled;
},
runOnce() {
const trigger = LivechatTrigger.findOne(FlowRouter.getParam('_id'));
return (trigger && trigger.runOnce) || false;
},
conditions() {
const trigger = LivechatTrigger.findOne(FlowRouter.getParam('_id'));
if (!trigger) {
Expand Down Expand Up @@ -43,6 +47,7 @@ Template.livechatTriggersForm.events({
name: instance.$('input[name=name]').val(),
description: instance.$('input[name=description]').val(),
enabled: instance.$('input[name=enabled]:checked').val() === '1',
runOnce: instance.$('input[name=runOnce]:checked').val() === '1',
conditions: [],
actions: [],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Meteor.methods({
info.agentData = room && room[0] && room[0].servedBy && RocketChat.models.Users.getAgentInfo(room[0].servedBy._id);

RocketChat.models.LivechatTrigger.findEnabled().forEach((trigger) => {
info.triggers.push(_.pick(trigger, '_id', 'actions', 'conditions'));
info.triggers.push(_.pick(trigger, '_id', 'actions', 'conditions', 'runOnce'));
});

RocketChat.models.LivechatDepartment.findEnabledWithAgents().forEach((department) => {
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-livechat/server/methods/saveTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Meteor.methods({
name: String,
description: String,
enabled: Boolean,
runOnce: Boolean,
conditions: Array,
actions: Array,
});
Expand Down