예제 #1
0
 def append(self, item) -> None:
     if isinstance(item, dict):
         input_item_object = self.InputItem()
         NestedObjectToDict.process_and_set_json_to_object(
             object_class_to_set_to=input_item_object,
             request_json_dict_stringed_dict_or_list=item,
             key_names_identifier_objects_to_go_into=["json_key"])
         super().append(input_item_object)
 def to_dict(self) -> dict:
     dict_object = NestedObjectToDict.get_dict_from_nested_object(
         object_to_process=self,
         key_names_identifier_objects_to_go_into=["json_key"])
     dict_object["version"] = "1.0"
     dict_object["sessionAttributes"] = dict()
     return dict_object
예제 #3
0
    def handle_any_platform(self, event: dict, context: dict):
        print(f"Event = {json_dumps(event)}\nContext = {context}")
        self.check_everything_implemented()
        event_safedict = SafeDict(classic_dict=event)

        # The 'rawPath' is for ApiGatewayV2, use the key 'resource' (without the comma) if using ApiGatewayV1
        if event_safedict.get(
                "rawPath").to_str() == "/googleAssistantDialogflowV1":
            # A google-assistant or dialogflow request always pass trough an API gateway
            self.handler_input.is_dialogflow_v1 = True
            event = NestedObjectToDict.get_dict_from_json(
                event_safedict.get("body").to_str())

        elif event_safedict.get("rawPath").to_str() == "/samsungBixbyV1":
            # A samsung bixby request always pass trough an API gateway
            self.handler_input.is_bixby_v1 = True
            from urllib import parse
            event = {
                "context":
                NestedObjectToDict.get_dict_from_json(
                    stringed_json_dict=event_safedict.get("body").to_str())
                ["$vivContext"],
                "parameters":
                dict(
                    parse.parse_qsl(
                        event_safedict.get("rawQueryString").to_str()))
            }

        elif "amzn1." in event_safedict.get("context").get("System").get(
                "application").get("applicationId").to_str():
            # Alexa always go last, since it do not pass trough an api resource, its a less robust identification than the other platforms.
            self.handler_input.is_alexa_v1 = True
        else:
            from inoft_vocal_framework.messages import ERROR_PLATFORM_NOT_SUPPORTED
            raise Exception(ERROR_PLATFORM_NOT_SUPPORTED)

        self.handler_input.load_event(event=event)
        return self.process_request()
    def load_event(self, event: dict) -> None:
        if self.is_alexa_v1 is True:
            from inoft_vocal_framework.platforms_handlers.alexa_v1.handler_input import AlexaHandlerInput
            self._alexaHandlerInput = AlexaHandlerInput(parent_handler_input=self)
            NestedObjectToDict.process_and_set_json_to_object(object_class_to_set_to=self.alexaHandlerInput,
                request_json_dict_stringed_dict_or_list=event, key_names_identifier_objects_to_go_into=["json_key"])

        elif self.is_dialogflow_v1 is True:
            from inoft_vocal_framework.platforms_handlers.dialogflow_v1.handler_input import DialogFlowHandlerInput
            self._dialogFlowHandlerInput = DialogFlowHandlerInput(parent_handler_input=self)
            NestedObjectToDict.process_and_set_json_to_object(object_class_to_set_to=self.dialogFlowHandlerInput.request,
                request_json_dict_stringed_dict_or_list=event, key_names_identifier_objects_to_go_into=["json_key"])

        elif self.is_bixby_v1 is True:
            from inoft_vocal_framework.platforms_handlers.samsungbixby_v1.handler_input import BixbyHandlerInput
            self._bixbyHandlerInput = BixbyHandlerInput(parent_handler_input=self)

            NestedObjectToDict.process_and_set_json_to_object(object_class_to_set_to=self.bixbyHandlerInput.request.context,
                request_json_dict_stringed_dict_or_list=event["context"], key_names_identifier_objects_to_go_into=["json_key"])
            NestedObjectToDict.process_and_set_json_to_object(object_class_to_set_to=self.bixbyHandlerInput.request,
                request_json_dict_stringed_dict_or_list=event["parameters"], key_names_identifier_objects_to_go_into=["json_key"])
    @card.setter
    def card(self, card: Card) -> None:
        raise_if_variable_not_expected_type(value=card,
                                            expected_type=Card,
                                            variable_name="card")
        self._card = card

    @property
    def shouldEndSession(self):
        return self._shouldEndSession

    @shouldEndSession.setter
    def shouldEndSession(self, shouldEndSession: bool) -> None:
        raise_if_variable_not_expected_type(value=shouldEndSession,
                                            expected_type=bool,
                                            variable_name="shouldEndSession")
        self._shouldEndSession = shouldEndSession

    def to_dict(self) -> dict:
        dict_object = NestedObjectToDict.get_dict_from_nested_object(
            object_to_process=self,
            key_names_identifier_objects_to_go_into=["json_key"])
        dict_object["version"] = "1.0"
        dict_object["sessionAttributes"] = dict()
        return dict_object


if __name__ == "__main__":
    NestedObjectToDict.get_dict_from_nested_object(Response(), ["json_key"])
예제 #6
0
 def to_dict(self) -> dict:
     return NestedObjectToDict.get_dict_from_nested_object(
         object_to_process=self,
         key_names_identifier_objects_to_go_into=["json_key"])
예제 #7
0
 def return_transformations(self):
     for i in range(len(self.items)):
         self.items[i] = NestedObjectToDict.get_dict_from_nested_object(
             object_to_process=self.items[i],
             key_names_identifier_objects_to_go_into=["json_key"])
예제 #8
0
        media_response_instance = None
        # todo: improve this loop so that we do not need to loop every time we add an item
        for response_item in self.payload.google.richResponse.items:
            if isinstance(response_item, MediaResponse):
                media_response_instance = response_item
                break
        if media_response_instance is None:
            media_response_instance = MediaResponse()
            self.payload.google.richResponse.items.append(
                media_response_instance)
        media_response_instance.add_audio_content(
            mp3_file_url=mp3_file_url,
            name=name,
            description=description,
            icon_image_url=icon_image_url,
            icon_accessibility_text=icon_accessibility_text)

    def request_push_notifications_permission(self) -> None:
        self.payload.google.systemIntent = SystemIntent(
            element_type=SystemIntent.element_type_ask_permission)

    def to_dict(self) -> dict:
        return NestedObjectToDict.get_dict_from_nested_object(
            object_to_process=self,
            key_names_identifier_objects_to_go_into=["json_key"
                                                     ])[self.json_key]


if __name__ == "__main__":
    NestedObjectToDict.get_dict_from_nested_object(Payload(), ["json_key"])
예제 #9
0
 def process_and_set_json_to_object(self, stringed_request_json_dict: str):
     NestedObjectToDict.process_and_set_json_to_object(object_class_to_set_to=self,
                                                       request_json_dict_stringed_dict_or_list=stringed_request_json_dict)
예제 #10
0
                list_object=self.RemoteEndpoint.AVAILABLE_METHODS,
                variable_name="endpoint_method")
            self._remote_endpoint = self.RemoteEndpoint

        def return_transformations(self):
            vars(self)["accepted-inputs"] = self.accepted_inputs
            del self.accepted_inputs
            vars(self)["local-endpoint"] = self.local_endpoint
            del self.local_endpoint

    def __init__(self):
        self.action_endpoints = self.NestedActionEndpoints()


from inoft_vocal_framework.platforms_handlers.nested_object_to_dict import NestedObjectToDict

endpoints = ActionEndpoints()
dict_object = NestedObjectToDict.get_dict_from_nested_object(
    object_to_process=ActionEndpoints(),
    key_names_identifier_objects_to_go_into=["json_key"])
print(dict_object)


def build_endpoints():
    endpoints = SafeDict()
    endpoints.get_set("action-endpoints", dict()).get_set("action-endpoints")


# from inoft_vocal_framework.utils.general import load_json
# current_template_infos_dict = load_json(filepath="F:\Inoft\skill_histoire_decryptage\inoft_vocal_framework\bixby_core\dummy_test.json")