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

[Bug]: Livechat - Calling registerGuest() method with existing set token causes blank chat #32042

Closed
harvard1932 opened this issue Mar 20, 2024 · 11 comments · Fixed by #32069
Closed
Labels

Comments

@harvard1932
Copy link

Running into exact issue on the latest version 6.6.4 as mentioned in https://forums.rocket.chat/t/issue-blank-chats/19092

@MartinSchoeler
Copy link
Contributor

MartinSchoeler commented Mar 21, 2024

Hello @harvard1932 can you give us more info?

Where exactly is the chat history blank? In the livechat widget or in the main Rocket.Chat view?

Do you have any errors on your browser console?

What exactly are the steps to reproduce the issue?

Thanks!

@Visbhavesh
Copy link

I wanted to work in thus issue please Assign this issue to me.

@harvard1932
Copy link
Author

Hello @harvard1932 can you give us more info?

Where exactly is the chat history blank? In the livechat widget or in the main Rocket.Chat view?

Do you have any errors on your browser console?

What exatly are the steps to reproduce the issue?

Thanks!

The issue is that javascript call to add chat information like customer name, email, etc. Would trigger the chat history to disappear on
image

basically overwriting older call on
image

which populates chat history.

@harvard1932
Copy link
Author

I wanted to work in thus issue please Assign this issue to me.

I have added some replication information on this bug

@Visbhavesh
Copy link

I wanted to work in thus issue please Assign this issue to me.

I have added some replication information on this bug

sure assign it to me and I look into it

@MartinSchoeler
Copy link
Contributor

@Visbhavesh no need for assignment, if you find something you want to work on, feel free to work on it and create a PR

@MartinSchoeler
Copy link
Contributor

Hello @harvard1932 can you give us more info?
Where exactly is the chat history blank? In the livechat widget or in the main Rocket.Chat view?
Do you have any errors on your browser console?
What exatly are the steps to reproduce the issue?
Thanks!

The issue is that javascript call to add chat information like customer name, email, etc. Would trigger the chat history to disappear on image

basically overwriting older call on image

which populates chat history.

Ahh it seems that a livechat API call is overriding your livechat guest token and another conversation is being started (if you send a message in this empty chat you'll see that it creates another conversation as another guest). Some calls like registerGuest() and setToken() can cause that. Also, if you call registerGuest() while having the said guest already logged, that causes an empty screen, that is a bug that's being worked on.

If you need more help with this you'll probably have to share your script (or something similar to what are you doing) that calls the livechat API endpoints

Cheers!

@Visbhavesh
Copy link

Hello @harvard1932 can you give us more info?
Where exactly is the chat history blank? In the livechat widget or in the main Rocket.Chat view?
Do you have any errors on your browser console?
What exatly are the steps to reproduce the issue?
Thanks!

The issue is that javascript call to add chat information like customer name, email, etc. Would trigger the chat history to disappear on image
basically overwriting older call on image
which populates chat history.

Ahh it seems that a livechat API call is overriding your livechat guest token and another conversation is being started (if you send a message in this empty chat you'll see that it creates another conversation as another guest). Some calls like registerGuest() and setToken() can cause that. Also, if you call registerGuest() while having the said guest already logged, that causes an empty screen, that is a bug that's being worked on.

If you need more help with this you'll probably have to share your script (or something similar to what are you doing) that calls the livechat API endpoints

Cheers!

to ensure it

Check API Call Order: Review your script and ensure you're not calling registerGuest() and setToken() consecutively.
Conditional Logic for registerGuest(): Implement a check before calling registerGuest(). If the guest is already registered, skip this call.
Await Bug Fix: If the issue is confirmed as a bug, consider waiting for a fix from the livechat API provider. In the meantime, you can implement a temporary workaround using the conditional logic mentioned above.

@harvard1932
Copy link
Author

Hello @harvard1932 can you give us more info?
Where exactly is the chat history blank? In the livechat widget or in the main Rocket.Chat view?
Do you have any errors on your browser console?
What exatly are the steps to reproduce the issue?
Thanks!

The issue is that javascript call to add chat information like customer name, email, etc. Would trigger the chat history to disappear on image
basically overwriting older call on image
which populates chat history.

Ahh it seems that a livechat API call is overriding your livechat guest token and another conversation is being started (if you send a message in this empty chat you'll see that it creates another conversation as another guest). Some calls like registerGuest() and setToken() can cause that. Also, if you call registerGuest() while having the said guest already logged, that causes an empty screen, that is a bug that's being worked on.
If you need more help with this you'll probably have to share your script (or something similar to what are you doing) that calls the livechat API endpoints
Cheers!

to ensure it

Check API Call Order: Review your script and ensure you're not calling registerGuest() and setToken() consecutively. Conditional Logic for registerGuest(): Implement a check before calling registerGuest(). If the guest is already registered, skip this call. Await Bug Fix: If the issue is confirmed as a bug, consider waiting for a fix from the livechat API provider. In the meantime, you can implement a temporary workaround using the conditional logic mentioned above.

Currently we are using:

this.initialize({
    theme: {
        color: '#d681f8',
        fontColor: '#FFFFFF',
        iconColor: '#1d74f5',
        title: "Chat",
       offlineTitle: "Server Updating",
    },
    department: '<?php echo $_SESSION["x"]; ?>',
    guestToken: '<?php echo $_SESSION["x"]; ?>',
    language: 'en',

});

this.registerGuest({
    token: '<?php echo $_SESSION["x"]; ?>', // The token field is not required. If it is not passed, a new token will be generated
    name: js_variable_name,
    email: '<?php echo $_SESSION["x"]; ?>@x.com',
    customFields: [ // The customFields field is not required. If it is passed it needs to be an Array, where each item needs to be an object with key and value fields
        {key:  'membership', value: '<?php echo $y; ?>', overwrite: true},
        {key:  'ID', value: '<?php echo $x; ?>', overwrite: true}
    ]
});

because this.initialize doesnt have any official doc on being able to contain customfields.
And on rocketchat js API there isn't a way to check if registerGuest already registered or not, unless I am missing something.

Thank you so much for your help! This only became of an issue in latest 6.6.4, and it wasn't really an issue in earlier versions.

@MartinSchoeler
Copy link
Contributor

MartinSchoeler commented Mar 25, 2024

@harvard1932

Yeah, you might be setting the the guestToken twice and that is causing the bug, while the fix is not out as a work around you could do something like

var token = '<?php echo $_SESSION["x"]; ?>'
if (!window.localStorage.store.includes(`"token": "${ token }"`)) {
    this.registerGuest({"your guest data here"})
}

I would also suggest removing the token from initialize as it is already being set by registerGuest

This will prevent the register guest to be called when the exact same token is already set on localstorage

Hope this helps!
Thanks!

@MartinSchoeler MartinSchoeler added type: bug stat: triaged Issue reviewed and properly tagged and removed stat: waiting response labels Mar 25, 2024
@MartinSchoeler MartinSchoeler changed the title Live chat history is blank [Bug]: Livechat - Calling registerGuest() method with existing set token causes blank chat Mar 25, 2024
@harvard1932
Copy link
Author

@harvard1932

Yeah, you might be setting the the guestToken twice and that is causing the bug, while the fix is not out as a work around you could do something like

var token = '<?php echo $_SESSION["x"]; ?>'
if (!window.localStorage.store.includes(`"token": "${ token }"`)) {
    this.registerGuest({"your guest data here"})
}

I would also suggest removing the token from initialize as it is already being set by registerGuest

This will prevent the register guest to be called when the exact same token is already set on localstorage

Hope this helps! Thanks!

Well.. Because we use the live chat from another domain, it wouldnt have access to the localstorage of the rocketchat server due to cross site limitation. It would still be better suited for rocket chat to fix the issue from the core, or add additional javascript API that allows for checking if guest token exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants