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

Want to pass custom username to the botpress. Custom username not showing by the botpress #1813

Open
pks891618 opened this issue Feb 22, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@pks891618
Copy link

Below is the simple HTML code where user enter their name first time and after that i want that botpress can use that.But its not working ?

<title>My Basic HTML Page</title>
<script src="https://cdn.botpress.cloud/webchat/v1/inject.js?i=213132123123"></script>
<script>
    function initializeChat(userName) {
        console.log("inside function:",userName)
        window.botpressWebChat.init({
            userData: {
                name: userName,
            },
            "composerPlaceholder": "Chat with bot",
            "botConversationDescription": "This chatbot was built surprisingly fast with Botpress",
            "botId": "915398e7-3cb8-43fe-8873-8e7a30a0c16f",
            "hostUrl": "https://cdn.botpress.cloud/webchat/v1",
            "messagingUrl": "https://messaging.botpress.cloud",
            "clientId": "<add your own id>",
            "webhookId": "<add your own webhook ID>",
            "lazySocket": true,
            "themeName": "prism",
            "frontendVersion": "v1",
            "useSessionStorage": true,
            "showPoweredBy": true,
            "theme": "prism",
            "themeColor": "#2563eb"
        });
    }

    function getUserNameAndInitializeChat() {
        let userName = localStorage.getItem('user_name');

        // Check if the username exists in localStorage
        if (!userName) {
            userName = prompt('Please enter your first name:');
            if (userName) {
                // Save the username to localStorage
                localStorage.setItem('user_name', userName);


                initializeChat(userName);
            }
        } else {

                                const myTimeout = setTimeout(initializeChat(userName), 2000);

                                console.log(userName);

            //initializeChat(userName);
        }
    }

    // Call the function to get the dynamic value for userName and initialize chat
    getUserNameAndInitializeChat();
</script>
@pks891618 pks891618 added the bug Something isn't working label Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant