Skip to content

Commit

Permalink
[NEW] Livechat registration form message (#12597)
Browse files Browse the repository at this point in the history
  • Loading branch information
renatobecker authored and sampaiodiego committed Dec 6, 2018
1 parent 60c7c64 commit 4361c63
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 8 deletions.
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 @@ -1712,6 +1712,7 @@
"Livechat_open_inquiery_show_connecting": "Show Connecting Message Instead of Input When Guest is Not Yet Connected to an Agent",
"Livechat_Queue": "Livechat Queue",
"Livechat_registration_form": "Registration Form",
"Livechat_registration_form_message": "Registration Form Message",
"Livechat_room_count": "Livechat Room Count",
"Livechat_Routing_Method": "Livechat Routing Method",
"Livechat_Take_Confirm": "Do you want to take this client?",
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,7 @@
"Livechat_open_inquiery_show_connecting": "Mostrar conexão de mensagem em vez de entrada quando o visitante ainda não está conectado a um agente",
"Livechat_Queue": "Roleta Livechat",
"Livechat_registration_form": "Formulário de Registro",
"Livechat_registration_form_message": "Mensagem do Formulário de Registro",
"Livechat_room_count": "Contador de salas de Livechat",
"Livechat_Routing_Method": "Método de roteamento Livechat",
"Livechat_Take_Confirm": "Você quer levar esse cliente?",
Expand Down
7 changes: 7 additions & 0 deletions packages/rocketchat-livechat/.app/client/lib/_livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ this.Livechat = new (class Livechat {
this._widgetOpened = new ReactiveVar(false);
this._ready = new ReactiveVar(false);
this._agent = new ReactiveVar();
this._registrationFormMessage = new ReactiveVar('');

this.stream = new Meteor.Streamer('livechat-room');

Expand Down Expand Up @@ -141,6 +142,9 @@ this.Livechat = new (class Livechat {
get room() {
return this._room.get();
}
get registrationFormMessage() {
return this._registrationFormMessage.get();
}

set online(value) {
this._online.set(value);
Expand Down Expand Up @@ -224,6 +228,9 @@ this.Livechat = new (class Livechat {
set guestEmail(email) {
return this._guestEmail.set(email);
}
set registrationFormMessage(value) {
this._registrationFormMessage.set(value);
}

ready() {
this._ready.set(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ Template.livechatWindow.onCreated(function() {
Livechat.registrationForm = result.registrationForm;
Livechat.nameFieldRegistrationForm = result.nameFieldRegistrationForm;
Livechat.emailFieldRegistrationForm = result.emailFieldRegistrationForm;
Livechat.registrationFormMessage = result.registrationFormMessage;

loadDepartments(result.departments);

Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-livechat/.app/client/views/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Template.register.helpers({
return Template.instance().error.get();
},
welcomeMessage() {
return '';
return Livechat.registrationFormMessage;
},
showDepartments() {
return Department.find({ showOnRegistration: true }).count() > 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h2>{{_ "Settings"}}</h2>
<span class="rc-switch__button-inside"></span>
</span>
<span class="rc-switch__text">{{_ "Enabled"}}</span>
</label>
</label>
<label class="rc-switch__label">
<input class="rc-switch__input js-input-check" type="checkbox" name="registrationFormNameFieldEnabled" {{registrationFormNameFieldEnabled}}/>
<span class="rc-switch__button">
Expand All @@ -99,7 +99,11 @@ <h2>{{_ "Settings"}}</h2>
<span class="rc-switch__button-inside"></span>
</span>
<span class="rc-switch__text">{{_ "Show_email_field"}}</span>
</label>
</label>
<div class="input-line">
<label for="registrationFormMessage">{{_ "Livechat_Registration_form_message"}}</label>
<textarea class="preview-settings rc-input__element" name="registrationFormMessage" id="registrationFormMessage">{{registrationFormMessage}}</textarea>
</div>
</fieldset>
<fieldset>
<legend>{{_ "Conversation_finished"}}</legend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ Template.livechatAppearance.helpers({
return 'checked';
}
},
registrationFormMessage() {
return Template.instance().registrationFormMessage.get();
},
sampleColor() {
if (Template.instance().previewState.get().indexOf('offline') !== -1) {
return Template.instance().colorOffline.get();
Expand Down Expand Up @@ -204,6 +207,7 @@ Template.livechatAppearance.onCreated(function() {
this.registrationFormEnabled = new ReactiveVar(null);
this.registrationFormNameFieldEnabled = new ReactiveVar(null);
this.registrationFormEmailFieldEnabled = new ReactiveVar(null);
this.registrationFormMessage = new ReactiveVar(null);

this.autorun(() => {
const setting = LivechatAppearance.findOne('Livechat_title');
Expand Down Expand Up @@ -249,6 +253,10 @@ Template.livechatAppearance.onCreated(function() {
const setting = LivechatAppearance.findOne('Livechat_conversation_finished_message');
this.conversationFinishedMessage.set(setting && setting.value);
});
this.autorun(() => {
const setting = LivechatAppearance.findOne('Livechat_registration_form_message');
this.registrationFormMessage.set(setting && setting.value);
});
this.autorun(() => {
const setting = LivechatAppearance.findOne('Livechat_registration_form');
this.registrationFormEnabled.set(setting && setting.value);
Expand Down Expand Up @@ -318,6 +326,10 @@ Template.livechatAppearance.events({

const settingRegistrationFormEmailFieldEnabled = LivechatAppearance.findOne('Livechat_email_field_registration_form');
instance.registrationFormEmailFieldEnabled.set(settingRegistrationFormEmailFieldEnabled && settingRegistrationFormEmailFieldEnabled.value);

const settingRegistrationFormMessage = LivechatAppearance.findOne('Livechat_registration_form_message');
instance.registrationFormMessage.set(settingRegistrationFormMessage && settingRegistrationFormMessage.value);

},
'submit .rocket-form'(e, instance) {
e.preventDefault();
Expand Down Expand Up @@ -378,6 +390,10 @@ Template.livechatAppearance.events({
_id: 'Livechat_email_field_registration_form',
value: instance.registrationFormEmailFieldEnabled.get(),
},
{
_id: 'Livechat_registration_form_message',
value: s.trim(instance.registrationFormMessage.get()),
},
];

Meteor.call('livechat:saveAppearance', settings, (err/* , success*/) => {
Expand Down
7 changes: 7 additions & 0 deletions packages/rocketchat-livechat/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@ Meteor.startup(function() {
enableQuery: { _id: 'Livechat_enable_transcript', value: true },
});

RocketChat.settings.add('Livechat_registration_form_message', '', {
type: 'string',
group: 'Livechat',
public: true,
i18nLabel: 'Livechat_registration_form_message',
});

RocketChat.settings.add('Livechat_open_inquiery_show_connecting', false, {
type: 'boolean',
group: 'Livechat',
Expand Down
12 changes: 11 additions & 1 deletion packages/rocketchat-livechat/server/api/lib/livechat.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import _ from 'underscore';
import LivechatVisitors from '../../models/LivechatVisitors';
Expand All @@ -7,7 +8,7 @@ export function online() {
}

export function findTriggers() {
return RocketChat.models.LivechatTrigger.findEnabled().fetch().map((trigger) => _.pick(trigger, '_id', 'actions', 'conditions'));
return RocketChat.models.LivechatTrigger.findEnabled().fetch().map((trigger) => _.pick(trigger, '_id', 'actions', 'conditions', 'runOnce'));
}

export function findDepartments() {
Expand Down Expand Up @@ -58,6 +59,9 @@ export function findAgent(agentId) {

export function settings() {
const initSettings = RocketChat.Livechat.getInitSettings();
const triggers = findTriggers();
const departments = findDepartments();
const sound = `${ Meteor.absoluteUrl() }sounds/chime.mp3`;

return {
enabled: initSettings.Livechat_enabled,
Expand Down Expand Up @@ -89,11 +93,17 @@ export function settings() {
offlineUnavailableMessage: initSettings.Livechat_offline_form_unavailable,
conversationFinishedMessage: initSettings.Livechat_conversation_finished_message,
transcriptMessage: initSettings.Livechat_transcript_message,
registrationFormMessage: initSettings.Livechat_registration_form_message,
},
survey: {
items: ['satisfaction', 'agentKnowledge', 'agentResposiveness', 'agentFriendliness'],
values: ['1', '2', '3', '4', '5'],
},
triggers,
departments,
resources: {
sound,
},
};
}

Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-livechat/server/api/v1/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ RocketChat.API.v1.addRoute('livechat/message', {

const result = RocketChat.Livechat.sendMessage(sendMessage);
if (result) {
const message = { _id: result._id, msg: result.msg, u: result.u, ts: result.ts };
const message = { _id: result._id, rid: result.rid, msg: result.msg, u: result.u, ts: result.ts };
return RocketChat.API.v1.success({ message });
}

Expand Down Expand Up @@ -93,7 +93,7 @@ RocketChat.API.v1.addRoute('livechat/message/:_id', {
if (result) {
const data = RocketChat.models.Messages.findOneById(_id);
return RocketChat.API.v1.success({
message: { _id: data._id, msg: data.msg, u: data.u, ts: data.ts },
message: { _id: data._id, rid: data.rid, msg: data.msg, u: data.u, ts: data.ts },
});
}

Expand Down
8 changes: 7 additions & 1 deletion packages/rocketchat-livechat/server/api/v1/visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ RocketChat.API.v1.addRoute('livechat/visitor', {
guest.phone = { number: this.bodyParams.visitor.phone };
}

let visitor = LivechatVisitors.getVisitorByToken(token);
const visitorId = RocketChat.Livechat.registerGuest(guest);

let visitor = LivechatVisitors.getVisitorByToken(token);
// If it's updating an existing visitor, it must also update the roomInfo
const cursor = RocketChat.models.Rooms.findOpenByVisitorToken(token);
cursor.forEach((room) => {
RocketChat.Livechat.saveRoomInfo(room, visitor);
});

if (customFields && customFields instanceof Array) {
customFields.forEach((field) => {
const customField = RocketChat.models.LivechatCustomField.findOneById(field.key);
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ RocketChat.Livechat = {
'Livechat_conversation_finished_message',
'Livechat_name_field_registration_form',
'Livechat_email_field_registration_form',

'Livechat_registration_form_message',
]).forEach((setting) => {
settings[setting._id] = setting.value;
});
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-livechat/server/methods/getInitialData.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Meteor.methods({
conversationFinishedMessage: null,
nameFieldRegistrationForm: null,
emailFieldRegistrationForm: null,
registrationFormMessage: null,
};

const options = {
Expand Down Expand Up @@ -78,6 +79,7 @@ Meteor.methods({
info.conversationFinishedMessage = initSettings.Livechat_conversation_finished_message;
info.nameFieldRegistrationForm = initSettings.Livechat_name_field_registration_form;
info.emailFieldRegistrationForm = initSettings.Livechat_email_field_registration_form;
info.registrationFormMessage = initSettings.Livechat_registration_form_message;

info.agentData = room && room[0] && room[0].servedBy && RocketChat.models.Users.getAgentInfo(room[0].servedBy._id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Meteor.methods({
'Livechat_registration_form',
'Livechat_name_field_registration_form',
'Livechat_email_field_registration_form',
'Livechat_registration_form_message',
];

const valid = settings.every((setting) => validSettings.indexOf(setting._id) !== -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Meteor.publish('livechat:appearance', function() {
'Livechat_registration_form',
'Livechat_name_field_registration_form',
'Livechat_email_field_registration_form',
'Livechat_registration_form_message',
],
},
};
Expand Down

0 comments on commit 4361c63

Please sign in to comment.