Skip to content

Commit 9d19b3b

Browse files
feat: adding A/B testing SPIs to core package (#195)
Co-authored-by: Shreyas Govinda Raju <shreraju@amazon.com>
1 parent 3717aa5 commit 9d19b3b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

ask-sdk-core/ask_sdk_core/response_helper.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import typing
2020

2121
from ask_sdk_model import Response
22+
from ask_sdk_model.interfaces.alexa.experimentation.experiment_trigger_response import \
23+
ExperimentTriggerResponse
2224
from ask_sdk_model.interfaces.display import PlainText, RichText, TextContent
2325
from ask_sdk_model.ui import Reprompt, SsmlOutputSpeech
2426

@@ -51,7 +53,8 @@ def __init__(self):
5153
self.response = Response(
5254
output_speech=None, card=None, reprompt=None,
5355
directives=None, should_end_session=None,
54-
can_fulfill_intent=None, api_response=None)
56+
can_fulfill_intent=None, api_response=None,
57+
experimentation=None)
5558

5659
def speak(self, speech, play_behavior=None):
5760
# type: (str, PlayBehavior) -> 'ResponseFactory'
@@ -152,6 +155,22 @@ def add_directive_to_reprompt(self, directive):
152155
self.set_should_end_session(False)
153156
return self
154157

158+
def add_experiment_trigger(self, experiment_id):
159+
# type: (str) -> 'ResponseFactory'
160+
"""Adds experiment id to response.
161+
:param experiment_id: the identifier of the experiment.
162+
:type experiment_id: str
163+
:return: response factory with partial response being built and
164+
access from self.response.
165+
:rtype: ResponseFactory
166+
"""
167+
if self.response.experimentation is None:
168+
triggered_experiments = [] # type: ignore
169+
self.response.experimentation = ExperimentTriggerResponse(triggered_experiments=triggered_experiments)
170+
171+
self.response.experimentation.triggered_experiments.append(experiment_id)
172+
return self
173+
155174
def set_should_end_session(self, should_end_session):
156175
# type: (bool) -> 'ResponseFactory'
157176
"""Sets shouldEndSession value to null/false/true.

ask-sdk-core/tests/unit/test_response_helper.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
CanUnderstandSlotValues)
3030
from ask_sdk_model.interfaces.alexa.presentation.apla.render_document_directive import \
3131
RenderDocumentDirective
32+
from ask_sdk_model.interfaces.alexa.experimentation.experiment_trigger_response import \
33+
ExperimentTriggerResponse
3234
from ask_sdk_model.interfaces.display import PlainText, RichText, TextContent
3335
from ask_sdk_model.interfaces.videoapp import (LaunchDirective, Metadata,
3436
VideoItem)
@@ -131,6 +133,15 @@ def test_add_reprompt_directive(self):
131133
"to add directive"
132134
)
133135

136+
def test_add_experiment_trigger_response(self):
137+
test_experiment_triggers = ["experimentId"]
138+
response_factory = self.response_factory.add_experiment_trigger(
139+
experiment_id="experimentId")
140+
141+
assert response_factory.response.experimentation.triggered_experiments == test_experiment_triggers, (
142+
"The add_experiment_trigger method of ResponseFactory fails to "
143+
"add experiment_trigger_response value")
144+
134145
def test_response_with_reprompt_directive(self):
135146
directive = RenderDocumentDirective()
136147
expected_response = Response(

0 commit comments

Comments
 (0)