Guide
MOI
Send a Message
16 min
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" } true false 148false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type 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 } true false 148false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type 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 true false 165false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type filter options true false 165false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type 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?" } } true false 165false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type productdata products true false 165false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type 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 }, ] }} true false 165false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type 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>" } }] } } true false 165false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type false unhandled content type