Handle User Actions
Filter Selection
As an example, let us assume that the shopper was presented different sizes as options based on the earlier response provided by the Moi backend.
...
"filter": {
"settings": {
"label": "Please select a size:",
"key": "size",
"chatFormat": "$VALUE$ please!",
"chatFormatEmpty": "Any Size would do!"
},
"options": [{
"name": "s",
"value": "size:s",
"selected": "false",
"count": "31"
},
{
"name": "m",
"value": "size:m",
"selected": "false",
"count": "30"
},
...
],
"note": null
}
...
When a shopper selects a filter option, for example, size "s", we expect a request such as the following to be submitted to the Moi backend.
{
"context": { ... },
"message": "s please!",
"filter": {
"value": "size:s"
}
}Please note how the message is submitted and the filter element with the value "size:s" is submitted. This is the value of the option that was sent in the original response.
If customer chooses two sizes “s” and “m”, the request for the same should look like the following:
{
"context": { ... },
"message": "s and m please!",
"filter": {
"value": "size:s;size:m"
}
}Please note how the value element inside the filter element now has two semicolon separated values.
Product Questions
This particular option requires a special way of handling. When a shopper clicks on this option, in our current (default) interface we open a separate tab, where we allow shoppers to ask questions about the respective product (see below).
Within this new tab, now when a shopper asks a question, a request such as the following should be made:
Request:
{
"context": {
"sessionId": "<sessionId>",
"klevuApiKey": "<store's api key>",
"url": "<url of the product>",
"productId": "39941324767325",
"mode": "product-specific-question"
},
"message": "what is the material?"
}
Here, as can be seen, we have included three more parameters in the context as well as the shopper's question as message
Parameter | Description |
|---|---|
url | The respective product's url |
productId | The respective product's id |
mode | Must have the value "product-specific-question" |
message | The customers question *Note: must be sent outside of the context clause |
Response:
The Moi backend produces a standard response as it does for any other requests.
{
"data": [{
"context": {
"mode": "product-specific-question",
"productId": "39941324767325",
"url": "<url of the product>",
"sessionId": "<sessionId>",
"klevuApiKey": "<store's api key>"
}
},
{
"message": {
"id": "627cbfb7-c239-4b45-93b0-1f45b3c41037",
"type": "text",
"value": "The Uptown Messenger Purse is made of faux leather.",
"note": null,
"explain": null,
"collectFeedback": true
}
},
...
]
}
Product Click
It could be as easy as taking customers to the respective product URL, however, the Moi backend needs to know the products that the shoppers are clicking on to collect analytics events and provide:
- Personalized search experience
- Reports on conversions that were driven by the Moi application.
For this reason, when a shopper clicks on a product, we ask you to submit the following request:
Request:
{
"context": {
"sessionId": "<sessionId>",
"klevuApiKey": "<store's api key>"
},
"product": {
"id": "<id of the product>",
"intent": "redirect",
"context": {
"url": "<url of the product>"
}
}
}
Response:
{
"data": [{
"context": {
"sessionId": "<sessionId>",
"klevuApiKey": "<store's api key>"
}
},
{
"genericOptions": { ... }
},
{
"actions": {
"actions": [{
"type": "redirectToUrl",
"context": {
"link": "<url of a page / product>"
}
}]
}
}
]
}
Feedback
It is important to get shopper feedback on the responses the Moi engine produces.
For example, not integrated in Moi but in another application of ours, currently, we show the thumbs up and down as below:
Feedback Needed
Every message we return would have an id associated with it and an element called collectFeedback with its value either set to "true" or "false".
If it is set to "true", we request you to collect feedback from the shopper.
...
{
"message": {
"id": "6aed823a-1ecc-457a-8d60-d32972408d78",
"type": "text",
"value": "I am your shopping assistant. How can I help you?",
"note": null,
"explain": null,
"collectFeedback": false
}
},
...
Once the feedback is collected, it can be sent as the following request.
Send Feedback
Important
- The endpoint to submit feedback is different.
- the messageId here must be the same as the id of the message sent in the response. The value of the thumbs parameter must be either "UP" or "DOWN".
{
"context": { ... },
"feedback": {
"messageId": "a75715e0-70d7-4741-b8b2-06710e6b36bb",
"thumbs": "DOWN"
}
}