Shopping Muse Using Kotlin SDK
Get response variations for Shopping Muse campaigns.
Powered by the Assistant endpoint, Shopping Muse provides your site visitors with a conversational product discovery experience. The API processes user inputs in real time, identifying intent and contextual cues to deliver highly relevant, personalized product suggestions.
For more information see the following:
Parameters
| Parameter | Data Structure Type | Mandatory? | Description |
|---|---|---|---|
| page | Page | Yes | Information about the current page (for example, homePage, categoryPage). Used for campaign targeting and context. |
| text | String | Yes | The user’s message sent to the Shopping Muse assistant. |
| chatId | String? | No | Identifier of an existing conversation. Pass this to continue a previous chat; omit it to start a new conversation. |
| pageAttributes | Map<String, PageAttribute>? | No | Additional page‑level attributes (for example, category, user intent) used for targeting and personalization. |
| branchId | String? | No | Branch identifier for multi‑branch setups (stores, financial institutions, restaurants). |
| options | AssistantOptions? | No | Additional configuration for the assistant request (for example, analytics or behavior flags, when available). |
Code example
suspend fun chatWithAssistant() {
val result =
DYSdk.getInstance()
.assistant
.chatWithAssistant(
page =
Page.categoryPage(pageLocation = "category-page", categories = listOf("bla")),
text = "I want to buy something nice"
)
when (result.status) {
ResultStatus.SUCCESS,
ResultStatus.WARNING -> {
val variation =
result.choices?.firstOrNull()?.variations?.firstOrNull()
?: run {
Log.w("Assistant", "No choices/variations returned for assistant response")
return
}
val data = variation.payload.data
val assistant = data.assistant
val chatId = data.chatId
val support = data.support
Log.d(
"Assistant",
"Assistant response: chatId=$chatId, assistant=$assistant, support=$support"
)
// Handle widgets and their product slots
data.widgets?.forEach { widget ->
val title = widget.title
Log.d("Assistant", "Widget: title=$title")
widget.slots.forEach { slot ->
val productData = slot.productData as? DefaultRecsProductData ?: return@forEach
val groupId = productData.group_id
val name = productData.name
val url = productData.url
val price = productData.price
val inStock = productData.in_stock
val imageUrl = productData.image_url
val categories = productData.categories
val keywords = productData.keywords
Log.d(
"Assistant",
"Widget product: groupId=$groupId, name=$name, price=$price, inStock=$inStock, url=$url"
)
Log.v(
"Assistant",
"Widget product details: imageUrl=$imageUrl, categories=$categories, keywords=$keywords"
)
}
}
}
ResultStatus.ERROR -> {
result.error?.let { exception ->
Log.e("Assistant", "Assistant error: ${exception.message}", exception)
} ?: Log.e("Assistant", "Assistant error: unknown error")
}
}
}Updated 5 days ago