Skip to content

[NEW] Additional Livechat iFrame API's#10918

Merged
sampaiodiego merged 22 commits intodevelopfrom
livechat-additional-iframe-apis
Jul 6, 2018
Merged

[NEW] Additional Livechat iFrame API's#10918
sampaiodiego merged 22 commits intodevelopfrom
livechat-additional-iframe-apis

Conversation

@renatobecker-zz
Copy link
Copy Markdown

@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('[email protected]'); });

  • 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: '[email protected]'}); });
    Or without a token:
    RocketChat(function() { this.registerGuest({name: 'Rocket.Chat visitor name', email: '[email protected]'}); });

@renatobecker-zz renatobecker-zz added this to the 0.66.0 milestone 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
@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
Copy Markdown

Leen15 commented Jun 13, 2018

Hi guys, any ETA for this?

@sampaiodiego
Copy link
Copy Markdown
Member

@Leen15 it will be released on 0.66

@sampaiodiego
Copy link
Copy Markdown
Member

@engelgabriel engelgabriel had a problem deploying to rocket-chat-pr-10918 June 15, 2018 13:50 Failure
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-10918 June 15, 2018 14:01 Inactive
@renatobecker-zz
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

},

setToken(token) {
if ((!token) || (token == this.token.get())) {
Copy link
Copy Markdown
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()) {

return {
userId
userId,
token
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.


this.guestName = new ReactiveVar(null);
this.autorun(() => {
this.guestName.set(Livechat.guestName);
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Author

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

},
agentData() {
const agent = Livechat.agent;
const agent = Template.instance().agentData.get();
Copy link
Copy Markdown
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
Copy Markdown
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
@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
Copy Markdown

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

None yet

Development

Successfully merging this pull request may close these issues.

Create additional iframe APIs to livechat

6 participants