Package: pyasista
Arcelik Asista Smart Assistant AWS Lambda Python LibrarySimple Python API wrapper for Arcelik Asista Smart Assistant AWS Lambda handlers.pyasistais an easy to use Python package to help developers implement their AWS lambda function with ease.InstallationTo install pyasista, simply usepip.pipinstallpyasistaUsageJust importpyasistainto your project and use the wrapper classes for easily implementing your lambda functions.frompyasistaimportAsistaInputfrompyasistaimportAsistaOutputfrompyasistaimportCommandfrompyasistaimportCommandType# Sample lambda handler to make Asista say `Hello, my name is Asista.`.deflambda_handler(event,context):asista_input=AsistaInput(event)asista_output=AsistaOutput()command=Command(CommandType.PLAY_ANNOUNCE,'Hello, my name is Asista.')asista_output.push_command(command)returndict(asista_output)DocumentationAsistaInputArcelik Asista Smart Assistant Lambda function has a standard event format.AsistaInputclass is a wrapper for the lambda function input. Just use theeventof the lambda function while initializing the object....deflambda_handler(event,context):asista_input=AsistaInput(event)...AsistaInput has the following properties and methods:customer_confirmed:Trueif the customer respondedyes;Falseif the customer respondedno;Noneif the customer has not responded to aYes/Noquestion.environment: Environment (DEVELOPMENT, TESTING or PRODUCTION). (See:Environment)ext_node_id: Node id of the detected NLP tree.serial_number: Serial number of the physical Asista device.session: A dictionary of the session variables.slot_values: A dictionary of detected dynamic variables. Slot values stored in lists, with the same order as it appeared in the event.sr_text: Actual speech detected with speech recognition.timeout: While waiting for user to respond your query, the Asista device timeouts after 10 seconds if it could not detect any speech. In that case, lambda function will be fed with timeout parameter is set to True.token: A helper object for holding OAuth2 token and refreshing the token. (See:AsistaToken)user_guide(): Retrieves the user guide of the skill. ReturnsNoneif the method encounters an error.All properties of AsistaInput are immutable....deflambda_handler(event,context):asista_input=AsistaInput(event)print(asista_input.serial_number)# Print the serial number of the deviceasista_input.serial_number='QWERTY123'# Raise an AttributeErrorIf your lambda strictly requires more of those parameters, you can pass them to the constructor and raise an error if the event lack any of those arguments....deflambda_handler(event,context):# If serial_number and token keys are missing in the event, raise an error.asista_input=AsistaInput(event,required_parameters=['serial_number','token'])...AsistaOutputA wrapper for Arcelik Asista Smart Assistant Lambda function standard output.frompyasistaimportAsistaInputfrompyasistaimportAsistaOutputdeflambda_handler(event,context):asista_input=AsistaInput(event)asista_output=AsistaOutput()returndict(asista_output)Due to the non-serializable structure of AsistaOutput, lambda functions should returndict(asista_output). [Under revision]AsistaOutput has the following methods:push_command(command): Add a command for Asista to perform. (See:Command)session(dict): A dictionary containing the session information. [default=dict()]session_continue(bool):Trueif the session should continue; elseFalse. [default=False]AsistaTokenFor the applications requiring OAuth2 access token, Asista lambda input contains the access token and all the required information on refreshing them. You can access the token from theAsistaInput.AsistaToken has the following property and methods:access_token: The property holds the actual access token. It is an immutable variable, trying to set it will raise an AttributeError.is_valid(): Checks whether the AsistaToken class structually valid. It is important to note that this method does not check whether the token itself is valid or not. It only checks whether the AsistaToken instance has access_token set and all the data present to refresh it.refresh(): Refreshs the access token. ReturnTrueif the token is refreshed successfully, elseFalse.Example usage of the AsistaToken as follows:frompyasistaimportAsistaInputfrompyasistaimportAsistaTokendeflambda_handler(event,context):asista_input=AsistaInput(event)asista_token=asista_input.token# The AsistaToken objectifasista_token.is_valid():# Checks access_token is structually validprint(asista_token.access_token)# Print the access_tokenifasista_token.refresh():# Refresh the access_tokenprint(asista_token.access_token)# Print the new access_tokenelse:print('Cannot refresh access token')# Error in refreshelse:print('Event does not have the token object')...CommandArcelik Asista Smart Assistant is capable of converting a text to speech using a TTS engine and play it out loud, and playing an audio stream for the customer. AsistaOutput has an array of commands for Asista to perform.Commandis a wrapper class for this purpose.Basically initialize the class with type (See:CommandType) and the data (either the text to be spoken or the stream to be streamed) and add it to the output usingAsistaOutput.push_command(command)method.An example usage of Command is below:frompyasistaimportAsistaOutputfrompyasistaimportCommandfrompyasistaimportCommandTypedeflambda_handler(event,context):# Parse event using AsistaInput# Implement your business logic...asista_output=AsistaOutput()# Create a command to make Asista say 'Hello, my name is Asista.'command=Command(CommandType.PLAY_ANNOUNCE,'Hello, my name is Asista.')asista_output.push_command(command)returndict(asista_output)CommandTypeAn enumeration of supported command types that Asista can perform:CommandType.PLAY_ANNOUNCE: Read a text out loud using TTS engine.CommandType.PLAY_STREAM: Stream an audio from a URL.CommandType.STOP: Stop Asista.CommandType.NOACTION: Make Asista take no action at all.EnvironmentAn enumeration of supported environments that current event of the lambda function is executed.Supported environments are:Environment.DEVELOPMENT: Development environment.Environment.TESTING: Test environment.Environment.PROD: Production environment.Accessing the environment is easy:frompyasistaimportAsistaInputfrompyasistaimportEnvironmentdeflambda_handler(event,context):asista_input=AsistaInput(event)environment=asista_input.environmentifenvironment==Environment.DEVELOPMENT:# Do tasks for developmentelifenvironment==Environment.TESTING:# Do tasks for testelifenvironment==Environment.PROD:# Do tasks for productionelse:# Undetermined environmentEXAMPLESLooking for more examples? Check out theexamplesfolder.Release History1.1.2 (2018-11-22)user_guide()method is added to theAsistaInput.1.1.1 (2018-10-22)timeoutproperty is added to theAsistaInput.1.1.0 (2018-09-25)Environment string for Environment.PROD changed fromPRODtoPRODUCTION. If you are usingEnvironmentyou should update yourpyasistaversion to keep things working.1.0.1 (2018-08-13)Following static methods are added toAsistaOutputto create lambda outputs easier:AsistaOutput.with_stream(data):Creates an instance ofAsistaOutputwith command PLAY_STREAM.AsistaOutput.with_announce(data):Creates an instance ofAsistaOutputwith command PLAY_ANNOUNCE.AsistaOutput.with_stop():Creates an instance ofAsistaOutputwith command STOP.AsistaOutput.with_noaction():Creates an instance ofAsistaOutputwith command NOACTION.1.0.0 (2018-08-10)Birth!