---
title: Handle User Actions
slug: apis/handle-user-actions
docTags: 
createdAt: 2024-03-04T17:32:44.410Z
---



## 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.

```json
...

     "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.

```json
{

  "context": { ... },

  "message": "s please!",

  "filter": {

    "value": "size:s"

  }

}
```

:::hint{type="warning"}
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.&#x20;
:::

If customer chooses two sizes “s” and “m”, the request for the same should look like the following:

```json

{

  "context": { ... },

  "message": "s and m please!",

  "filter": {

    "value": "size:s;size:m"

  }

}
```

:::hint{type="info"}
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). 



![](https://lh7-us.googleusercontent.com/LYyQlIitm5DmtJkD01FQKJFNgVoxGSnkNSraMRZE0FG1QqoPseqZKFEK_bDFZDvscg7dCkvscrVQ6LqgHHiVA-DLkQTxdHXHG-EaCnvpqnSDP8ViGYoIvFH9GK6Fs2U-mpRI3-N7innp7JtnZHToG60)

Within this new tab, now when a shopper asks a question, a request such as the following should be made:

**Request:**

```json
{

  "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<br />\*Note: must be sent  outside of the **`context`** clause |



**Response:**

The Moi backend produces a standard response as it does for any other requests.

```json
{

  "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:&#x20;

1. Personalized search experience&#x20;
2. 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:**

```json
{

  "context": {

    "sessionId": "<sessionId>",

    "klevuApiKey": "<store's api key>"

  },

  "product": {

    "id": "<id of the product>",

    "intent": "redirect",

    "context": {

      "url": "<url of the product>"

    }

  }

}


```



**Response:**

```json
{

  "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.&#x20;

For example, not integrated in Moi but in another application of ours, currently, we show the thumbs **up** and **down** as below:

::Image[]{src="https://lh7-us.googleusercontent.com/_x6DDKg0mfHUdYeKmCGIF0M0F5cxmk-LGWwodFtc3cS3W7Z4J7C6iCF2g6SZgvaLncWwtMsPp2_wvzRALgj04mWeA-I0kO5Pt63548ET9GCZbKGiSTl0OqbbXLgAFwF03jYjuexrPTfH40C8q5frj28" size="80" width="501" height="206" position="center" showCaption="false"}

### 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.

```json
...

    {

      "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

:::hint{type="warning"}
**Important** 

1. The endpoint to submit feedback is different.
2. 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"**.
:::

**POST** [https://moi-ai.ksearchnet.com/chat/feedback](https://moi-ai.ksearchnet.com/chat/feedback)  

```json
{

    "context": { ... },

    "feedback": {

        "messageId": "a75715e0-70d7-4741-b8b2-06710e6b36bb",

        "thumbs": "DOWN"

    }

}


```

