Guide
MOI
Send a Message
16min
sending a message in its simplest form, the backend expects a plain text message written in a natural language and when sending this message, it is important to add the sessionid and klevuapikey in the context request { "context" { "sessionid" "e7e0b73b e160 4585 98b8 f50cbfdfe9ba", "klevuapikey" "\<store's api key>" }, "message" "do you have dresses?" } understanding the response json with every message sent to the backend, in its response, it will always return the context containing the respective sessionid and the klevuapikey additionally, it may come back with different types of data elements it may look like the following with one or more elements of each type response { "data" \[ { "context" { … } }, { "message" { } }, { "filter" { } }, { "productdata" { }}, { "genericoptions" { }}, { "actions" { }} ] } lets have a look at each data type in the response context "context" { "sessionid" "\<some session id>", "klevuapikey" "\<store's api key>", "ipaddressv4" "xxx xxx xxx xxx", "ipaddressv6" "x\ x x\ x x\ x x\ x", "dataprotection"\ true/false, "country" "fr", "city" "paris", 	 	 "klevu uuid" "0ff61cc7 4a55 4b3a b9f8 975ea2b248ea" } parameter description sessionid the sessionid assigned to the current user and should be used for any subsequent interactions by this user klevuapikey the klevu api key used for the session message "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 } parameter description id every message is assigned a unique id this is used when submitting shopper’s feedback for this particular message we will see an example of the same a bit later in the document type in the current version, the value of this remains as "text" value the message you want to show to the shopper the value here is usually a plain text but can also contain urls and therefore the respective html anchors in it note this is like a fine print or an instruction or a general note that you may want to show as a fine print to the current message explain why the system has produced the answer it has, the explanation of the same is provided in this element it details the reasoning the backend system has followed in our uis we show them behind the info icon collectfeedback if set to true , this is an instruction to the frontend that feedback should be collected for this particular message there can be one or more of this in a single request when rendering messages on the front, please show them in the order they are provided in the response filter these are different filtering options the moi backend likes to present to the shopper and ask to choose from for example, if a shopper has asked for dresses, the moi application may want to show some colors or sizes or other attributes to collect shopper’s preferences "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 } filter settings parameter description label shows a message to be shown to the shopper before listing down the options key the id/key of the filter chatformat when a shopper has selected an option, there are two things we like to do show in the chat message the option that the shopper has selected send a filter selection to the moi backend the chatformat here shows the template that can be used to prepare a message that should be shown to the shopper here, for example, the chat format is "$value$ please!" the $value$ should be replaced with the actual option (or options) selected for example "small and medium please!" chatformatempty this is for future reference and can be ignored for now filter options parameter description name caption of the option (e g "s", "m") value if a customer chooses this option, the value to be sent to the backend we will see later in the documentation how to use this value selected if this option was already selected by the shopper it comes as true or false/null count the number of products moi has for this option productdata this is where the actual products to be shown to the shopper are sent from the moi backend for each product it shows some product specific options as well { "productdata" { "products" \[{ "id" "40991197921373", "itemref" "p0", "itemgroupid" "7081251209309", "image" "\<url of the image>", "name" "\<product title>", "url" "\<product url>", "price" "98 00", "saleprice" "90 00", "currency" "usd", "shortdesc" "\<short description of the product>", "originalcontent" "\<long description of the product>", "noofvariants" 0, "options" \[{ "name" "product questions", "intent" "product specific question", "chat" "product questions" }, { "name" "more like this", "intent" "show similar products", "chat" "similar products to p0" } ] }, ], "totalresultsfound" "15", "typeofquery" "wildcard and", "note" "tip you can ask questions using product locators, e g what’s the difference between p0 and p1?" } } parameter description products the array of individual data points for each of the product records (see productdata products section below) totalresultsfound the total number of results found typeofquery you may ignore this as this is only used for debugging note a fine print that you may want to show to the shopper productdata products parameter description id the unique id of the product itemref this is a product locator (e g p0 and p1) shoppers can include these references in their question itemgroupid the parent group id of the product in case of a product having multiple variants, a group id is associated with every variant image the url of the image to be used to fetch product image name the title of the product url url of the product price retail price of the product saleprice price after discount currency 3 letter currency code shortdesc short description of the product originalcontent long description of the product noofvariants if there are other variants of this product available this field contains the count of these variants options the options to be shown in the ui for this product for each option, it contains the following sub elements options name caption for the option options intent when a shopper clicks on this option and when you send a call to answer this click, it will require you to submit the intent how exactly such a product specific option be handled is explained later in the document options chat the message to be posted in the chat window when handling this option genericoptions these are different dynamic options that are relevant in the current state after the last response was sent in our uis, we convert them into buttons { "genericoptions" { "options" \[{ "name" "back", "type" "message", "chat" "go back" }, { "name" "clear", "type" "clearchat", "chat" null }, ] }} parameter description name this is like a caption of a button type there are two types supported message if the type is “message”, when a shopper clicks on it, the associated chat should be posted in the chat window and sent as a message to the moi backend clearchat if the type is “clearchat”, the chat ui should be cleared no need to send any message to the moi backend chat when a shopper hits on the button for these options, the text provided here should be posted in the chat window and sent as a message to the moi backend actions the moi backend may want you to take certain actions such as redirect shoppers to a particular page or collect their order number for order tracking etc for such matters, it may include certain information in the response here, for example, the action is to redirect the shopper to a particular url { "actions" { "actions" \[{ "type" "redirecttourl", "context" { "link" "\<url of a page / product>" } }] } } parameter description actions there maybe more than one action available type there action type context the action context