Developers

Cross Domain

Introduction

This adapter redirects the user to another domain, and allows them to continue the previous conversation with the Chat SDK.

Adapter code and public Github repository

This adapter can be found in the Github crossDomain adapter adapters repository.

Click here to see the adapter code

How does it work ?

  1. It displays an initial message, using the onReady subscription, and displayChatbotMessage action, that explains that upon writing the cross-domain, the user will be redirected.

  2. If the user asks to go cross-domain, we detect it through the sendMessage subscription. We then perform the getSessionData action to retrieve all the relevant information of the conversation (previous messages, sessionToken, position, etc.), and store it in a variable called sessionData.

  3. A systemMessage with a button displays with a link to the new website and adds this information in the link.

  4. When the user clicks on the button, we detect it with the onSelectSystemMessageOption subscription. We then use a POST method to submit a form that contains all the sessionData information.

  5. Afterwards, we redirect the user with the onReady subscription. upon detection that the sessionData was sent with a POST method, we perform a setSessionData action to set the Chat SDK in the same state as it was in the source website.

Procedure

To do this, we use the following actions:

In addition to the actions, we use the following subscriptions:

configuration parameters:

  • redirectUrl: This is the target URL, where the user is redirected after they request to go cross-domain.
  • testData: We capture the input data using the $_POST['sessionData']php method. If no data was sent, we set it as a fakeData string. In the first domain example:
  • Adapter array build configuration:
  adapters: [
      PostCrossDomain(redirectUrl, inputData),
  ]

In the second one, where we get the data info with the following adapter:

  adapters: [
    crossdomain(testData)
  ]