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] Additional Livechat iFrame API's #10918

Merged
merged 22 commits into from
Jul 6, 2018

Conversation

renatobecker-zz
Copy link

@renatobecker-zz renatobecker-zz commented May 29, 2018

Closes #10866

This PR adds new Livechat iFrame API's, as described below:

  • setGuestToken(token):
    Using this method a new Livechat session will be created using a external token (e.g.):
    RocketChat(function() { this.setGuestToken('FHwaLnp8fzjMupSAj'); });

  • setGuestName(name):
    This method assigns a name to the Livechat active session visitor. If the visitor is already registered, its name will be updated in the database. If the visitor is not yet registered, its name will be assigned when the registration method is called.(e.g.):
    RocketChat(function() { this.setGuestName('Rocket.Chat visitor name'); });

  • setGuestEmail(email):
    This method assigns an email to the Livechat active session visitor. If the visitor is already registered, its email will be updated in the database. If the visitor is not yet registered, its email will be assigned when the registration method is called.(e.g.):
    RocketChat(function() { this.setGuestEmail('rocket@rocket.chat'); });

  • registerGuest(data):
    This method checks if there is a Livechat visitor with the same token passed by the object. If a Livechat visitor does not exist, a new Livechat visitor will be created or, if one exists, will be updated. After that, a new Livechat session will be started.(e.g.):
    RocketChat(function() { this.registerGuest({token: 'pSjpaw46CeL6Zu9f9', name: 'Rocket.Chat visitor name', email: 'rocket@rocket.chat'}); });
    Or without a token:
    RocketChat(function() { this.registerGuest({name: 'Rocket.Chat visitor name', email: 'rocket@rocket.chat'}); });

@renatobecker-zz renatobecker-zz added this to the 0.66.0 milestone May 29, 2018
@renatobecker-zz renatobecker-zz added this to Desireable in June/2018 via automation May 29, 2018
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10918 May 29, 2018 00:23 Inactive
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10918 May 29, 2018 00:29 Inactive
@RocketChat RocketChat deleted a comment May 29, 2018
@renatobecker-zz renatobecker-zz moved this from Desireable to In progress in June/2018 May 29, 2018
@renatobecker-zz renatobecker-zz moved this from In progress to Review/QA in June/2018 May 29, 2018
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10918 May 29, 2018 14:41 Inactive
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10918 June 1, 2018 13:43 Inactive
@Leen15
Copy link

Leen15 commented Jun 13, 2018

Hi guys, any ETA for this?

@sampaiodiego
Copy link
Member

@Leen15 it will be released on 0.66

@sampaiodiego
Copy link
Member

@renatobecker can you please add the new events to our docs as well? https://github.com/RocketChat/docs/tree/master/developer-guides/livechat-api

@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10918 June 15, 2018 14:01 Inactive
@renatobecker-zz
Copy link
Author

@sampaiodiego,
I have sent the Livechat API documentation changes for approval.
Thanks.

@sampaiodiego sampaiodiego temporarily deployed to rocket-chat-pr-10918 June 18, 2018 19:03 Inactive
@sampaiodiego sampaiodiego temporarily deployed to rocket-chat-pr-10918 June 18, 2018 19:44 Inactive
Copy link
Member

@sampaiodiego sampaiodiego left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

general considerations:

  • when calling setGuestToken I get an error because it is trying to insert a department record which was already added:

image

  • after calling setGuestName and setGuestEmail I would expect to see the values on the register form (pre-filled)

},

registerGuest(data) {
if (!(typeof data === 'object')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change to if (typeof data !== 'object') { to help readability

@@ -38,6 +55,59 @@ export default {
return this.token.get();
},

setToken(token) {
if ((!token) || (token == this.token.get())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to use this much parenthesis.. without them the code looks much clearer:

if (!token || token === this.token.get()) {

@@ -11,7 +11,8 @@ Meteor.methods({
RocketChat.models.Messages.keepHistoryForToken(token);

return {
userId
userId,
token
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on pull request #10767 this method will return the whole visitor object, I think you can to the same here (it should avoid future conflicts)

Livechat.guestName = null;
Livechat.guestEmail = null;

msgStream.unsubscribe('room-messages');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not have the desired effect. on my tests after changing the token using setGuestToken, I'm still receiving messages from the old room/token and being notified as well.

@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10918 June 21, 2018 20:27 Inactive
# Conflicts:
#	packages/rocketchat-livechat/server/methods/registerGuest.js
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10918 June 21, 2018 20:30 Inactive
@renatobecker-zz
Copy link
Author

renatobecker-zz commented Jun 21, 2018

@sampaiodiego, the changes requested has been submitted.
I want to say that even calling this method https://github.com/RocketChat/Rocket.Chat/pull/10918/files#diff-11b7d22c1f403eeeb1b94248bf66adcaR22 when a new session is created, if the agent keeps sending messages in the unused room, this events are still being emitted to Livechat websocket.

@renatobecker-zz renatobecker-zz moved this from In progress to Review/QA in June/2018 Jun 22, 2018

this.guestName = new ReactiveVar(null);
this.autorun(() => {
this.guestName.set(Livechat.guestName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to not use Livechat.guestName directly on helper instead of creating this reactive var?

}
},
getName() {
return Template.instance().guestName.get();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use Livechat.guestName directly here, instead of using the reactive var

@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10918 July 3, 2018 13:21 Inactive
@renatobecker-zz
Copy link
Author

@sampaiodiego, I fixed the usage of ReactiveVar's on register helpers.
Sorry, my mistake.

@@ -62,7 +62,7 @@ Template.messages.helpers({
};
},
agentData() {
const agent = Livechat.agent;
const agent = Template.instance().agentData.get();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the same case as Livechat.guestName I've talked before (sry for not have seen this before). Any reason to use a ReactiveVar here instead of keeping Livechat. agent ?

@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10918 July 4, 2018 14:21 Inactive
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10918 July 4, 2018 14:28 Inactive
@renatobecker-zz
Copy link
Author

Hi @sampaiodiego!
I fixed the ReactiveVar stuff.. The last one was the same as the others you have seen before.
My mistake.

@sampaiodiego sampaiodiego merged commit 8014455 into develop Jul 6, 2018
June/2018 automation moved this from Review/QA to Closed Jul 6, 2018
@sampaiodiego sampaiodiego deleted the livechat-additional-iframe-apis branch July 6, 2018 20:37
@sampaiodiego sampaiodiego mentioned this pull request Jul 20, 2018
@salviof
Copy link

salviof commented Jun 17, 2019

Please, we need this too:
#13583

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
June/2018
  
Closed
Development

Successfully merging this pull request may close these issues.

Create additional iframe APIs to livechat
6 participants