Shopping Muse Using Swift SDK
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 | [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
func chatWithAssistant() async {
let result = await DYSdk.shared().assistant.chatWithAssistant(
page: Page.categoryPage(
pageLocation: "category-page",
categories: ["bla"]
),
text: "I want to buy something nice"
)
switch result.status {
case .success, .warning:
guard
let choice = result.choices?.first,
let variation = choice.variations.first
else {
print("Assistant: No choices or variations returned for assistant response")
return
}
let data = variation.payload.data
let assistantString = data.assistant
let chatId = data.chatId
let support = data.support
let widgets = data.widgets
print(
"""
Assistant response:
chatId=\(String(describing: chatId))
assistant=\(String(describing: assistantString))
support=\(String(describing: support))
widgetsCount=\(widgets?.count ?? 0)
"""
)
// MARK: - Widgets and Product Slots
data.widgets?.forEach { widget in
let title = widget.title
print("Assistant widget: title=\(String(describing: title))")
widget.slots.forEach { slot in
let slotId = slot.slotId
let sku = slot.sku
print(
"Assistant widget slot: slotId=\(String(describing: slotId)), sku=\(String(describing: sku))"
)
guard let productData = slot.productData as? DefaultRecsProductData else {
print("Assistant: productData is not DefaultRecsProductData for slot \(String(describing: slotId))")
return
}
let groupId = productData.groupId
let name = productData.name
let url = productData.url
let price = productData.price
let inStock = productData.inStock
let imageUrl = productData.imageUrl
let categories = productData.categories
let keywords = productData.keywords
print(
"""
Assistant widget product:
groupId=\(String(describing: groupId)),
name=\(String(describing: name)),
price=\(String(describing: price)),
inStock=\(String(describing: inStock)),
url=\(String(describing: url))
"""
)
print(
"""
Assistant widget product details:
imageUrl=\(String(describing: imageUrl)),
categories=\(String(describing: categories)),
keywords=\(String(describing: keywords))
"""
)
}
}
// MARK: - Warnings
if result.status == .warning, let warnings = result.warnings {
warnings.forEach { warning in
print("Assistant warning: \(warning)")
}
}
case .error:
if let error = result.error {
print("Assistant error: \(error)")
} else {
print("Assistant error: unknown error")
}
}
} Updated 5 days ago