Sending a response code

Sending an Interaction response code can be useful when displaying Optimizations programmatically and capturing the user's response.

const interactionRequest = {
	interaction: 'cordova://app-test/interaction1',
    		properties: {
      		key1: 'value1',
      		key2: 'value2'
	}
}
const setButtonSentiment = (response) => {
	const singleOptimizationPoint = response.optimizationPoints[0]
        const firstAction = singleOptimizationPoint.actions[0]
        const firstActionAsset = firstAction.asset
        let positive, negative, neutral
        firstActionAsset.responses.forEach((sentimentResponse) => {
		if (!positive && sentimentResponse.sentiment === 'POSITIVE') {
              		positive = sentimentResponse.code
		}
		if (!negative && sentimentResponse.sentiment === 'NEGATIVE') {
              		negative = sentimentResponse.code
            	}
		if (!neutral && sentimentResponse.sentiment === 'NEUTRAL') {
              		neutral = sentimentResponse.code
            	}
        })
        
        // assign on-click with sentiment to UI elements
	document.getElementById('positiveButton')
            	.addEventListener('click', () => {
              		MedalliaMXO.sendInteractionResponseCode({
                		interaction: response.interaction,
                		responseCode: positive
              		}).catch((error) => {
                		console.error(error)
              		})
            	})
        document.getElementById('neutralButton')
            	.addEventListener('click', () => {
              		MedalliaMXO.sendInteractionResponseCode({
                		interaction: response.interaction,
                		responseCode: neutral
              		}).catch((error) => {
                		console.error(error)
              		})
            })
        document.getElementById('negativeButton')
            	.addEventListener('click', () => {
              		MedalliaMXO.sendInteractionResponseCode({
                		interaction: response.interaction,
                		responseCode: negative
              		}).catch((error) => {
                		console.error(error)
              		})
            	})
	}
MedalliaMXO.sendInteraction(interactionRequest).then((response) => {
	return MedalliaMXO.processResponse(response)
	.then(() => response)
})
.then(setButtonSentiment)
.catch((error) => {
	// do something with the error
	console.error(error)
})