Example #1
0
 def fulfill(self, fulfillment_request: FulfillmentRequest) -> dict:
     logger.warning(
         "Authentication for Alexa fulfillment requests is NOT supported. Do not use AexaConnector in production."
     )
     body_dict = fulfillment_request.body
     request_body = fulfillment_schemas.from_dict(body_dict)
     response_body = self.fulfillment_component.handle_fulfillment(
         request_body)
     result = to_dict(response_body)
     return result
Example #2
0
def test_list_slot_list_value():

    LIST_SLOT_REQUEST__LIST_VALUE = json.loads("""{
        "type": "IntentRequest",
        "requestId": "amzn1.echo-api.request.258ed402-09b7-46f1-82e0-b01102829aa3",
        "locale": "en-US",
        "timestamp": "2021-08-11T21:58:24Z",
        "intent": {
            "name": "smalltalk_GreetFriends",
            "confirmationStatus": "NONE",
            "slots": {
                "friend_names": {
                    "name": "friend_names",
                    "confirmationStatus": "NONE",
                    "source": "USER",
                    "slotValue": {
                        "type": "List",
                        "values": [
                            {
                                "type": "Simple",
                                "value": "Al John",
                                "resolutions": {
                                    "resolutionsPerAuthority": [
                                        {
                                            "authority": "AlexaEntities",
                                            "status": {
                                                "code": "ER_SUCCESS_MATCH"
                                            },
                                            "values": [
                                                {
                                                    "value": {
                                                        "name": "Al St. John",
                                                        "id": "https://ld.amazonalexa.com/entities/v1/1684nfEDrbFDPS5zG3J9Xh"
                                                    }
                                                },
                                                {
                                                    "value": {
                                                        "name": "Al. John",
                                                        "id": "https://ld.amazonalexa.com/entities/v1/15clLtXk5V8G1eOUXS7e6U"
                                                    }
                                                },
                                                {
                                                    "value": {
                                                        "name": "Con Covert",
                                                        "id": "https://ld.amazonalexa.com/entities/v1/FQThPE13ILbFNfD9kAkQSA"
                                                    }
                                                },
                                                {
                                                    "value": {
                                                        "name": "Kenny Clarke",
                                                        "id": "https://ld.amazonalexa.com/entities/v1/2VrKlUBYfd4CCfrQaYXwhe"
                                                    }
                                                },
                                                {
                                                    "value": {
                                                        "name": "Holy Rage^Judas Priest^Atkins/May Project^",
                                                        "id": "https://ld.amazonalexa.com/entities/v1/5weB5rEfNVqDuk8WQEVprY"
                                                    }
                                                }
                                            ]
                                        }
                                    ]
                                }
                            },
                            {
                                "type": "Simple",
                                "value": "jack",
                                "resolutions": {
                                    "resolutionsPerAuthority": [
                                        {
                                            "authority": "AlexaEntities",
                                            "status": {
                                                "code": "ER_SUCCESS_MATCH"
                                            },
                                            "values": [
                                                {
                                                    "value": {
                                                        "name": "Jack",
                                                        "id": "https://ld.amazonalexa.com/entities/v1/3RAHxMlM8kNCNynNc67lEJ"
                                                    }
                                                },
                                                {
                                                    "value": {
                                                        "name": "Jack",
                                                        "id": "https://ld.amazonalexa.com/entities/v1/59kZG7GNVruEiv0I7DMyyn"
                                                    }
                                                },
                                                {
                                                    "value": {
                                                        "name": "Jack",
                                                        "id": "https://ld.amazonalexa.com/entities/v1/63nC6NdpAiDDfhWh3rH97o"
                                                    }
                                                },
                                                {
                                                    "value": {
                                                        "name": "Jack",
                                                        "id": "https://ld.amazonalexa.com/entities/v1/Aihij8TmUB7GGmc0NB2WAP"
                                                    }
                                                },
                                                {
                                                    "value": {
                                                        "name": "Jack",
                                                        "id": "https://ld.amazonalexa.com/entities/v1/IXkcQEfhx2kE8yHeOy5O9T"
                                                    }
                                                }
                                            ]
                                        }
                                    ]
                                }
                            }
                        ]
                    }
                },
                "__Conjunction": {
                    "name": "__Conjunction",
                    "value": "and",
                    "confirmationStatus": "NONE",
                    "source": "USER",
                    "slotValue": {
                        "type": "Simple",
                        "value": "and"
                    }
                }
            }
        }
    }""")
    fulfillment_component = _get_fulfillment_component()

    fulfillment_body_dict = _build_fulfillment_body_dict(
        LIST_SLOT_REQUEST__LIST_VALUE)
    body = fulfillment_schemas.from_dict(fulfillment_body_dict)
    intent = fulfillment_component.intent_from_fulfillment(
        body, lang=LanguageCode.ENGLISH)

    assert intent == MockGreetFriends(friend_names=["Al St. John", "Jack"])
Example #3
0
def test_list_slot_single_value():

    # Greet friends with a single friend
    LIST_SLOT_REQUEST__SINGLE_VALUE = json.loads("""{
        "type": "IntentRequest",
        "requestId": "amzn1.echo-api.request.fake-api-request",
        "locale": "en-US",
        "timestamp": "2021-08-11T21:46:11Z",
        "intent": {
            "name": "smalltalk_GreetFriends",
            "confirmationStatus": "NONE",
            "slots": {
                "friend_names": {
                    "name": "friend_names",
                    "value": "John",
                    "resolutions": {
                        "resolutionsPerAuthority": [
                            {
                                "authority": "AlexaEntities",
                                "status": {
                                    "code": "ER_SUCCESS_MATCH"
                                },
                                "values": [
                                    {
                                        "value": {
                                            "name": "John",
                                            "id": "https://ld.amazonalexa.com/entities/v1/1NaUgygHJx0BHxfQcKICqn"
                                        }
                                    },
                                    {
                                        "value": {
                                            "name": "John",
                                            "id": "https://ld.amazonalexa.com/entities/v1/5MPA8cqc69MBzaK3Z91KU9"
                                        }
                                    },
                                    {
                                        "value": {
                                            "name": "John",
                                            "id": "https://ld.amazonalexa.com/entities/v1/B2ebljbbk5pDAFEnHBPBXV"
                                        }
                                    },
                                    {
                                        "value": {
                                            "name": "John",
                                            "id": "https://ld.amazonalexa.com/entities/v1/HFaP3f1ENFoFfLQTbsC989"
                                        }
                                    },
                                    {
                                        "value": {
                                            "name": "John",
                                            "id": "https://ld.amazonalexa.com/entities/v1/uU6qXLKVIG9gK9jax0Lj00"
                                        }
                                    }
                                ]
                            }
                        ]
                    },
                    "confirmationStatus": "NONE",
                    "source": "USER",
                    "slotValue": {
                        "type": "Simple",
                        "value": "John",
                        "resolutions": {
                            "resolutionsPerAuthority": [
                                {
                                    "authority": "AlexaEntities",
                                    "status": {
                                        "code": "ER_SUCCESS_MATCH"
                                    },
                                    "values": [
                                        {
                                            "value": {
                                                "name": "John",
                                                "id": "https://ld.amazonalexa.com/entities/v1/1NaUgygHJx0BHxfQcKICqn"
                                            }
                                        },
                                        {
                                            "value": {
                                                "name": "John",
                                                "id": "https://ld.amazonalexa.com/entities/v1/5MPA8cqc69MBzaK3Z91KU9"
                                            }
                                        },
                                        {
                                            "value": {
                                                "name": "John",
                                                "id": "https://ld.amazonalexa.com/entities/v1/B2ebljbbk5pDAFEnHBPBXV"
                                            }
                                        },
                                        {
                                            "value": {
                                                "name": "John",
                                                "id": "https://ld.amazonalexa.com/entities/v1/HFaP3f1ENFoFfLQTbsC989"
                                            }
                                        },
                                        {
                                            "value": {
                                                "name": "John",
                                                "id": "https://ld.amazonalexa.com/entities/v1/uU6qXLKVIG9gK9jax0Lj00"
                                            }
                                        }
                                    ]
                                }
                            ]
                        }
                    }
                },
                "__Conjunction": {
                    "name": "__Conjunction",
                    "confirmationStatus": "NONE"
                }
            }
        }
    }""")
    fulfillment_component = _get_fulfillment_component()

    fulfillment_body_dict = _build_fulfillment_body_dict(
        LIST_SLOT_REQUEST__SINGLE_VALUE)
    body = fulfillment_schemas.from_dict(fulfillment_body_dict)
    with pytest.warns(None):
        intent = fulfillment_component.intent_from_fulfillment(
            body, lang=LanguageCode.ENGLISH)

    assert intent == MockGreetFriends(friend_names=["John"])
Example #4
0
def test_build_intent_normalizes_entity_values():
    # SolveMathOperation(first_operand=4, second_operand=5, operator="*")
    #                                                                 ^ must be normalized
    CALCULATOR_REQUEST = json.loads("""{
            "type": "IntentRequest",
            "requestId": "amzn1.echo-api.request.077b28ef-9c2b-4373-a250-d70d5b90a0bd",
            "locale": "en-US",
            "timestamp": "2021-08-12T20:07:38Z",
            "intent": {
                "name": "calculator_SolveMathOperation",
                "confirmationStatus": "NONE",
                "slots": {
                    "first_operand": {
                        "name": "first_operand",
                        "value": "4",
                        "confirmationStatus": "NONE",
                        "source": "USER",
                        "slotValue": {
                            "type": "Simple",
                            "value": "4"
                        }
                    },
                    "second_operand": {
                        "name": "second_operand",
                        "value": "5",
                        "confirmationStatus": "NONE",
                        "source": "USER",
                        "slotValue": {
                            "type": "Simple",
                            "value": "5"
                        }
                    },
                    "operator": {
                        "name": "operator",
                        "value": "times",
                        "resolutions": {
                            "resolutionsPerAuthority": [
                                {
                                    "authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.fake-application-id.CalculatorOperator",
                                    "status": {
                                        "code": "ER_SUCCESS_MATCH"
                                    },
                                    "values": [
                                        {
                                            "value": {
                                                "name": "multiplied by",
                                                "id": "CalculatorOperator-multipliedby"
                                            }
                                        }
                                    ]
                                }
                            ]
                        },
                        "confirmationStatus": "NONE",
                        "source": "USER",
                        "slotValue": {
                            "type": "Simple",
                            "value": "times",
                            "resolutions": {
                                "resolutionsPerAuthority": [
                                    {
                                        "authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.fake-application-id.CalculatorOperator",
                                        "status": {
                                            "code": "ER_SUCCESS_MATCH"
                                        },
                                        "values": [
                                            {
                                                "value": {
                                                    "name": "multiplied by",
                                                    "id": "CalculatorOperator-multipliedby"
                                                }
                                            }
                                        ]
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        }""")
    fulfillment_component = _get_fulfillment_component()

    fulfillment_body_dict = _build_fulfillment_body_dict(CALCULATOR_REQUEST)
    body = fulfillment_schemas.from_dict(fulfillment_body_dict)
    intent = fulfillment_component.intent_from_fulfillment(
        body, lang=LanguageCode.ENGLISH)

    assert intent == MockSolveMathOperation(first_operand=4,
                                            second_operand=5,
                                            operator="*")
Example #5
0
def test_build_intent_single_parameter():
    # OrderPizza(pizza_type="Margherita")
    ORDER_PIZZA_REQUEST = json.loads("""{
            "type": "IntentRequest",
            "requestId": "amzn1.echo-api.request.45f9da6f-f39b-41b4-b5fd-46d0cbf875cd",
            "locale": "en-US",
            "timestamp": "2021-08-12T20:02:52Z",
            "intent": {
                "name": "restaurant_OrderPizza",
                "confirmationStatus": "NONE",
                "slots": {
                    "amount": {
                        "name": "amount",
                        "confirmationStatus": "NONE"
                    },
                    "pizza_type": {
                        "name": "pizza_type",
                        "value": "margherita",
                        "resolutions": {
                            "resolutionsPerAuthority": [
                                {
                                    "authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.fake-application-id.PizzaType",
                                    "status": {
                                        "code": "ER_SUCCESS_MATCH"
                                    },
                                    "values": [
                                        {
                                            "value": {
                                                "name": "Margherita",
                                                "id": "PizzaType-Margherita"
                                            }
                                        }
                                    ]
                                }
                            ]
                        },
                        "confirmationStatus": "NONE",
                        "source": "USER",
                        "slotValue": {
                            "type": "Simple",
                            "value": "margherita",
                            "resolutions": {
                                "resolutionsPerAuthority": [
                                    {
                                        "authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.fake-application-id.PizzaType",
                                        "status": {
                                            "code": "ER_SUCCESS_MATCH"
                                        },
                                        "values": [
                                            {
                                                "value": {
                                                    "name": "Margherita",
                                                    "id": "PizzaType-Margherita"
                                                }
                                            }
                                        ]
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        }
    """)
    fulfillment_component = _get_fulfillment_component()

    fulfillment_body_dict = _build_fulfillment_body_dict(ORDER_PIZZA_REQUEST)
    body = fulfillment_schemas.from_dict(fulfillment_body_dict)
    intent = fulfillment_component.intent_from_fulfillment(
        body, lang=LanguageCode.ENGLISH)

    assert intent == MockOrderPizza(pizza_type="Margherita")
Example #6
0
def test_parse_docs_request():
    """
    This is the request at
    https://developer.amazon.com/en-US/docs/alexa/custom-skills/request-and-response-json-reference.html#request-body-syntax
    
    Request field has been replaced with actual IntentRequest
    """

    body = json.loads("""{
        "version": "1.0",
        "session": {
            "new": true,
            "sessionId": "amzn1.echo-api.session.[unique-value-here]",
            "application": {
            "applicationId": "amzn1.ask.skill.[unique-value-here]"
        },
        "attributes": {
            "key": "string value"
        },
        "user": {
            "userId": "amzn1.ask.account.[unique-value-here]",
            "accessToken": "Atza|AAAAAAAA...",
            "permissions": {
                "consentToken": "ZZZZZZZ..."
            }
        }
        },
        "context": {
            "System": {
            "device": {
                "deviceId": "string",
                "supportedInterfaces": {
                "AudioPlayer": {}
                }
            },
            "application": {
                "applicationId": "amzn1.ask.skill.[unique-value-here]"
            },
            "user": {
                "userId": "amzn1.ask.account.[unique-value-here]",
                "accessToken": "Atza|AAAAAAAA...",
                "permissions": {
                "consentToken": "ZZZZZZZ..."
                }
            },
            "person": {
                "personId": "amzn1.ask.person.[unique-value-here]",
                "accessToken": "Atza|BBBBBBB..."
            },
            "unit": {
                "unitId": "amzn1.ask.unit.[unique-value-here]",
                "persistentUnitId" : "amzn1.alexa.unit.did.[unique-value-here]"
            },
            "apiEndpoint": "https://api.amazonalexa.com",
            "apiAccessToken": "AxThk..."
            },
            "AudioPlayer": {
                "playerActivity": "PLAYING",
                "token": "audioplayer-token",
                "offsetInMilliseconds": 0
            }
        },
        "request": {
            "type": "IntentRequest",
            "requestId": "amzn1.echo-api.request.fake-request-id",
            "locale": "en-US",
            "timestamp": "2021-08-10T19:12:25Z",
            "intent": {
                "name": "smalltalk_hello",
                "confirmationStatus": "NONE"
            }
        }
    }""")

    expected = fs.FulfillmentBody(
        version="1.0",
        session=fs.FulfillmentSession(
            new=True,
            sessionId="amzn1.echo-api.session.[unique-value-here]",
            application=fs.FulfillmentSessionApplication(
                applicationId="amzn1.ask.skill.[unique-value-here]"),
            attributes={"key": "string value"},
            user=fs.FulfillmentSessionUser(
                userId="amzn1.ask.account.[unique-value-here]",
                accessToken="Atza|AAAAAAAA...",
                permissions={"consentToken": "ZZZZZZZ..."})),
        context=fs.
        FulfillmentContext(System=fs.FulfillmentContextSystem(
            apiAccessToken="AxThk...",
            apiEndpoint="https://api.amazonalexa.com",
            application=fs.FulfillmentContextSystemApplication(
                applicationId="amzn1.ask.skill.[unique-value-here]"),
            device=fs.FulfillmentContextSystemDevice(
                deviceId="string", supportedInterfaces={"AudioPlayer": {}}),
            unit=fs.FulfillmentContextSystemUnit(
                unitId="amzn1.ask.unit.[unique-value-here]",
                persistentUnitId="amzn1.alexa.unit.did.[unique-value-here]"),
            person=fs.FulfillmentContextSystemPerson(
                personId="amzn1.ask.person.[unique-value-here]",
                accessToken="Atza|BBBBBBB..."),
            user=fs.FulfillmentContextSystemUser(
                userId="amzn1.ask.account.[unique-value-here]",
                accessToken="Atza|AAAAAAAA...",
                permissions={"consentToken": "ZZZZZZZ..."})),
                           AudioPlayer=fs.FulfillmentContextAudioPlayer(
                               token="audioplayer-token",
                               playerActivity=fs.PlayerActivity.PLAYING,
                               offsetInMilliseconds=0)),
        request=fs.FulfillmentIntentRequest(
            type=fs.RequestType.INTENT,
            requestId="amzn1.echo-api.request.fake-request-id",
            timestamp=datetime(year=2021,
                               month=8,
                               day=10,
                               hour=19,
                               minute=12,
                               second=25),
            locale="en-US",
            intent=fs.FulfillmentIntentRequestIntent(
                name="smalltalk_hello",
                confirmationStatus=fs.IntentConfirmationStatus.NONE)))

    assert fs.from_dict(body) == expected