Retrieving an Interaction response

The Medallia Experience Orchestration SDK considers iOS View Controllers as Interactions. When configured correctly the SDK will automatically send an Interaction request to Medallia Experience Orchestration and process the response which may contain Points (Optimizations, Capture, etc). If desired, you can be notified of these automatic Interactions to take additional action on each Interaction request, by using the automatic Interaction callback API.

It is incumbent on you to then process the response in order for the Medallia Experience Orchestration SDK to perform automatic Capture and Optimization.

Important: Assigning a manual/custom Interaction to a view should be done before setting an automatic Interaction callback. If you set a callback for an automatically triggered Interaction, you are advised to remove that callback as soon as it is no longer needed.

The response can be passed to the process method, as shown below. By calling this method the response is returned to the SDK to process, attaching any Captures, Trackers, and/or Optimizations to the Interaction.

This functionality will not work if automatic Interaction detection is disabled. For retrieving the response in sending programmatic Interactions, see sending an Interaction request and retrieve the response.

Retrieving a response for an automatic Interaction request

var subscription: MXOAutomaticInteractionSubscription?
if let interaction = try? MXOInteraction(withViewController: self) {
	subscription = try? MedalliaMXO.subscribe(toAutomaticInteraction: MXOAutomaticInteractionSubscriber { builder in
		builder.interaction = interaction
		builder.onResponse = { response in
			do {
				try MedalliaMXO.process(response: response)
                	} catch {
				print("Error processing response: \(error.localizedDescription)")
			}
        	}
	})
}
__block NSError *error;
__block MXOInteraction *interaction = [MXOInteraction initWithViewController:self error:&error];
id subscription = [MedalliaMXO subscribeToAutomaticInteraction:[MXOAutomaticInteractionSubscriber initWithBuilder:^(MXOAutomaticInteractionSubscriberBuilder * _Nonnull builder) {
	builder.interaction = interaction;
        builder.onResponse = ^(MXOInteractionResponse *response) {
        	[MedalliaMXO processResponse:response error:&error];
        };
}] error:&error];

To unsubscribe from sending an automatic Interaction request, simply call the code below:

if let subscription = subscription {
	subscription.unsubscribe()
}
[subscription unsubscribe];

Retrieving a response for a manually assigned Interaction request

The response can be passed to the process Swift method or processResponse Objective-C method, as shown below. By calling this method the response is returned to the SDK to process, attaching any Captures, Trackers, and/or Optimizations to an Interaction.

if let interaction = try? MXOInteraction(withString: "/InteractionPath") {
	do {
		try MedalliaMXO.sendInteraction(request: MXOInteractionRequest { builder in
			builder.interaction = interaction
			builder.onError = { error in
                        	print("Error sending interaction: \(error.localizedDescription)")
                    	}
                    	builder.onSuccess = { response in
                        	do {
                           		try MedalliaMXO.process(response: response)
                        	} catch {
                            		print("Error processing response: \(error.localizedDescription)")
                        	}
                    	}
                })
	} catch {
         	print("Error sending interaction: \(error.localizedDescription)")
	}
}
__block NSError *error;
__block MXOInteraction *interaction = [MXOInteraction initWithString:@"/InteractionPath" error:&error];
[MedalliaMXO sendInteraction:[MXOInteractionRequest initWithBuilder:^(MXOInteractionRequestBuilder * _Nonnull builder) {
	builder.interaction = interaction;
        builder.onError = ^(NSError *error) {
		NSLog(@"Error sending interaction: %@", [error debugDescription]);
        };
        builder.onSuccess = ^(MXOInteractionResponse *response) {
            [MedalliaMXO processResponse:response error:&error];
        };
}] error:&error];