Skip to main content

Provide Search Data

Want to make it easier for agents to add products to a call? Read on.

To simplify the process of adding products for the agents, integration can be extended with the option to provide search data. Agents will be able to search for products in a flexible way with better support to find the best fit product.



When an agent types in a search term, the embed instance (BambuserOneToOneEmbed) will emit a provide-search-data event. By adding a listener for this event you can provide all necessary search details for the matching products to the search term the agent entered.

img

trigger of provide-search-data event

• When an agent types in a search term

note

When agent clicks on a product, provide-product-data event will get triggered.

Example:

// Inside onBambuserOneToOneReady method!
oneToOneEmbed.on('provide-search-data', (searchRequest, searchResponse) => {

// searchRequest.term contains the text that agent is searching for.
// searchRequest.page is the current page of results to be return if using
// pagination (see below).
// searchResponse() tells the player the search result

const { term, page } = searchRequest;

fetch(`/your/backend/for/product/search/?term=${term}&page=${page}`)
.then(res => res.json())
.then(yourSearchResponse => {
searchResponse(response => {

// If something is wrong with the search request,
// send a message to the sales-rep by throwing an error
if (!validSearch(yourSearchResponse)) throw new Error("Your error here");

return response.products(p => {
const results = yourSearchResponse.products.map(prod => {
/*
return p()
.name('White T-Shirt')
.imageUrl('http://www.example.com/white-t-shirt.png')
.sku('TSHIRT') // Can be string or number
.price(price => price
.current('123.99')
.original('173.99')
)
*/
return p()
.name(prod.name)
.imageUrl(prod.imageUrl)
.sku(prod.sku)
.price(price => price
.current(prod.price.current)
.original(prod.price.original || null)
)
});
return results;
})

// Set the currency used here using the standard ISO 4217
// three letter code.
.currency('EUR')
.locale('en-GB')

// If you would like to paginate search results also provide
// total number of pages, total number of matches and
// the current page.
.pagination(p => p
.totalPages(yourSearchResponse.pagination.totalPages)
.totalMatches(yourSearchResponse.pagination.totalMatches)
.currentPageIndex(yourSearchResponse.pagination.page)
)
})
})
})