Auto-submit form after sidebar button click

Hello

I'm trying to auto-submit my web chat form, but I want this to happen only after the user clicks the sidebar button to open the chat.

I tried to override WebChat.open via configuration file as below:

window._genesys.widgets.onReady = function(QuickBus){

  var oMyPlugin = QuickBus.registerPlugin('MyPlugin');
  oMyPlugin.subscribe('WebChatService.ready', function(e){});

oMyPlugin.command('WebChat.open', {
userData: {},
form: {
autoSubmit: true,
firstname: " ",
lastname: " ",
email: " ",
subject: " "
},
})
.done(function(e){

})
.fail(function(e){});

but this option auto-submits and starts the chat before the user clicks the sidebar button.

Is there a way to auto-submit the form only after the user clicks the sidebar button?

Thank you in advance.

Hello,

Your code is requesting the chat to be opened and submitted as soon as the page load.
In "window._genesys.widgets.onReady = function(QuickBus)" [called when the widget core & plugins have finished to load], you are subscribing to the "WebChatService.ready" event [triggered when WebChatService plugin has been loaded] but on that event, you are calling a function which does nothing "function(e){}".
Then immediately after, you request the WebChat to be opened and submitted with your command "oMyPlugin.command('WebChat.open', ..."

I don't know if you mean clicking a button for chat in the Widget Sidebar plugin/UI, clicking the native Widget WebChat button (on right hand-side of the page).

But yes, there are several ways to auto-submit the chat form when the user clicks the sidebar button.

If you meant the Widget Sidebar plugin, you have a channel defined for your chat button.

A first approach with Widget Sidebar would be to have the clickCommand set to "WebChat.open", and clickOptions set to:

{
    userData: {},
    form: {
        autoSubmit: true,
        firstname: "abcd",
        lastname: "efgh",
        email: "ijkl",
        subject: "mnop"
    }
}

A second approach with Widget Sidebar would be to implement the onClick function (in the Sidebar channel configuration) and request the WebChat from there.

onClick: function($, CXBus, Common) {
    CXBus.command('WebChat.open', {
        userData: {},
        form: {
            autoSubmit: true,
            firstname: "abcd",
            lastname: "efgh",
            email: "ijkl",
            subject: "mnop"
        }
    });
}

A third approach could consist in "intercepting" the "WebChat.open" command, using the before method(), and in modifying the input object to force the autoSubmit: true.
As soon as the WebChat is requested from anywhere (Sidebar WebChat.open, native WebChat button, custom buttons), the function would be triggered, and you could update the autoSubmit attribute to true so that the registration form is skipped.

Regards,

1 Like

Hi Jerome,

First of all thanks for the reply. I chose the second approach (implement the onClick function) and it worked. Now, when the chat page gets loaded, the side-bar button appears, and when I click this button the form is auto-submitted.
The issue I'm facing now is that the chat session after a few minutes expires and then, if the user chooses to start a new one (by clicking the start chat button), the form fields appear on screen instead of auto-submission like above.
So I have 2 questions:

  1. Is there a way to set the expiration time for the chat session?
  2. Is there a way to auto-submit the form after the user clicks on "start chat" button in the above scenario?
    Thank you in advance.

Hello,

1 - I don't understand what you mean by the "chat session after a few minutes expires".
What is the scenario?
There are some timers that cannot be changed on Genesys Cloud.
But it is something like:

  • maximum 10 hours to connect a customer to an agent (I mean max time in Queue),
  • or while connected to an agent, if the guest does not send any messages for 15 minutes, the guest will be automatically disconnected
  • and a couple of minutes to re-establish a chat session (if the user has moved to a page without WebChat widget and then comes back) [when the websocket connection is closed]

2 - I assume the Start Chat button is the one you get on expire.
First, I would say that I don't understand in which scenario you are facing an expire of the session - as you mention a couple of minutes.
If this is something "normal" in your scenario, and you want to take care of it, then the approach would have to be the one leveraging the before method()
https://developer.mypurecloud.com/api/webchat/widget-version2.html#intercept_and_override_data_based_on_before___method

You would have to use this method instead of the SideBar click.
The before method applied to WebChat.open would then cover both scenario (the initial click from sidebar, and the start chat if the chat has expired/been closed).

Regards,

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.