This adapter redirects the user to another domain, and allows them to continue the previous conversation with the Chatbot SDK.
This adapter can be found in the Github crossDomain adapter adapters repository.
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.
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
.
A systemMessage
with a button displays with a link to the new website and adds this information in the link.
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.
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 chatbot SDK in the same state as it was in the source website.
To do this, we use the following actions:
getSessionData to get the information of the current conversation.
setSessionData to set the state of the Chatbot SDK with the previously stored information.
displayChatbotMessage to display a custom chatbot message.
In addition to the actions, we use the following subscriptions:
onSendMessage to detect when the user wants to be redirected.
onReady to detect when the build method is complete and display an initial message.
onSelectSystemMessageOption to detect when the user confirms the cross-domain action.
$_POST['sessionData']
php method. If no data was sent, we set it as a fakeData
string.
In the first domain example: adapters: [
PostCrossDomain(redirectUrl, inputData),
]
In the second one, where we get the data info with the following adapter:
adapters: [
crossdomain(testData)
]