Announcing Alexa Presentation Language (APL) 2024.1

Mrudula Singampalli Mar 12, 2024
Share:
Alexa Skills
Blog_Header_Post_Img

We’re pleased to announce Alexa Presentation Language (APL) 2024.1 that includes several new features. We are excited to also announce tools that boost developer productivity including pseudo localization. Additional details about each of these enhancements are included below.

Do more with ‘onChange’ handler on bound variables

Introducing the new the onChange event handler to bound property definitions. Developers can now automatically trigger the onChange event when the values of bound variables change. 

Developers can create self-contained APL components that automatically adjust to changes from within. This eliminates the need to duplicate the logic for component changes where the change was originally made. The onChange event handler is not available in AVG items.

A common use of the onChange event handler is to respond to changes in dynamic data sources. For example if the FishFeeder data object has a property named TankTemperature, then an onChange handler can be used to track the minimum and maximum tank temperatures:

Copied to clipboard
{
  "type": "Text",
  "bind": [
    {
      "name": "MIN_TEMP",
      "value": null
    },
    {
      "name": "MAX_TEMP",
      "value": null
    },
    {
      "name": "TEMP",
      "value": "${FishFeeder.TankTemperature}",
      "onChange": [
        {
          "type": "SetValue",
          "property": "MIN_TEMP",
          "value": "${MIN_TEMP == null || TEMP < MIN_TEMP ? TEMP : MIN_TEMP}"
        },
        {
          "type": "SetValue",
          "property": "MAX_TEMP",
          "value": "${MAX_TEMP == null || TEMP > MAX_TEMP ? TEMP : MAX_TEMP}"
        }
      ]
    }
  ],
  "text": "Current Temperature=${TEMP} Low=${MIN_TEMP} High=${MAX_TEMP}"
}

Track real-time updates on APL component visibility changes

We’re excited to introduce the handleVisibilityChange handler that runs in the component data-binding context and streamlines how you track component visibility and impressions. 

The handleVisibilityChange handler in APL offers developers practical advantages. It provides accurate updates on component visibility changes in real-time, improving the responsiveness of APL documents. Developers can exercise granular control by tailoring visibility tracking to focus on essential elements, reducing unnecessary computations and enhancing overall performance. The handler simplifies the management of complexities like occlusion and cumulative transforms, ensuring a clearer view of components. Additionally, it enhances accessibility, allowing developers to effortlessly access information, make informed decisions, and seamlessly integrate data with external systems.

Using this handler ensures you receive accurate updates on your component's positioning, clipping, display, transformations, and animations. Simply add the handleVisibilityChange handler to your APL documents for improved visibility tracking and tailor it to focus on specific elements aligned with your development goals.

Dynamically iterate over the keys in your Map 

In APL development, we often encounter scenarios where customers utilize Map data structures to supply named objects, where the key represents the object's name and the value holds the data to be displayed.

Recognizing the need for enhanced flexibility, we're introducing the Map.keys(object) method. This method serves as a valuable asset for developers to dynamically iterate over the keys of an object, especially in instances where it's advantageous to display all items in the map without having to know the keys in advance. As an example, you can use this method to read out not just your own map objects but also the entirety of available viewport properties.

Copied to clipboard
{
    "type": "Container",
    "data": "${Map.keys(viewport)}",
    "items": [
        {
            "type": "Text",
            "text": "${data} = ${viewport[data]}"
        }
    ]
}

 

You can even use this method to read out and explore the properties of an event object.

Copied to clipboard
{
    "type": "Container",
    "bind": {
        "name": "EventSource",
        "value": ""
    },
    "onMount": {
        "type": "Sequential",
        "data": "${Map.keys(event.source)}",
        "commands": {
            "type": "SetValue",
            "property": "EventSource",
            "value": "${EventSource}<br>event.source.${data} = ${event.source[data]}"
        }
    },
    "item": {
        "type": "Text",
        "text": "${EventSource}"
    }
}

The Map.keys() method simplifies the process by returning an array of keys associated with a given map, eliminating the necessity of hard-coded key dependencies. With this enhancement, developers can now effortlessly showcase all items within the map, enhancing adaptability and efficiency in APL development.

Ensure software localizability with Pseudo localization (Alt: Optimize your localization testing with Pseudo Localization)

When adapting content for different languages, varying text lengths can disrupt layouts and readability, causing issues like truncation and overlapping. To address this, our new Pseudo Localization (PLn) feature allows developers to test software localizability without actual translations. PLn mimics new language space by controlled alterations to textual elements, avoiding the need for actual translations. For instance, it transforms an English phrase like "Children’s Privacy Disclosure" into "Ȧȧƈƈḗḗƞŧḗḗḓ Ḗḗƞɠŀīīşħ," readable to English-speaking developers. This 'accented English' helps test text expansion and other critical aspects.

Pseudo Localization enables dynamic testing during development, uncovering real-time issues not apparent in pre-built content. Developers can quickly switch between pseudo-localized and base content, saving time and facilitating rapid issue resolution without a full build. Accessible Pseudo-localization settings simulate text expansion, transformation, and test localization context across all viewports. Integrated into the APL rendering library, APLCoreEngine, it ensures comprehensive coverage and easy access to Pseudo-localization settings. To enable Pseudo Localization in your APL documents, simply toggle the pseudoLocalize flag in the skill manifest. This initiates the Pseudo Localization transformation for all APL documents in your skill.

Copied to clipboard
"mainTemplate": {
  "pseudoLocalize": true,
  "pseudoLocalization": {
    "enabled": true,
    "expansionPercentage": 40
  },
  .....
}

Debug APL documents with logging in the authoring tool

Introducing the new the Log command for developers to understand and isolate troublesome areas in your APL document. As a developer, you can now troubleshoot if a command is fired, verify the value of a parameter at runtime and thus better understand why interactions don’t work as expected or why events are not generated as expected. You can use the Log command in your APL document with log severity level and log message in addition to common command properties for better visibility on the execution of your APL document. To see the custom logs you added to the Log command, navigate to the authoring tool preview, that now includes a log window. Use the log window to display logging messages sent with the Log command. 

For details about defining log messages, see Log Command. For details about using the log window, see Debug a document with the log window.

Author APL documents easily with code snippets on VS Code

It has now got easier to author APL documents in VS Code Editor. The Alexa Skills (ASK) Toolkit for Visual Studio Code (VS Code) now includes APL commands and components as code snippets. Thus so developers can use auto-complete to finish their code. 

The Alexa Skills (ASK) Toolkit for Visual Studio Code (VS Code) now supports now supports automatic completion of APL language constructs, including components and commands. The tool suggests APL properties as you type your APL document on VS Code Editor. This feature saves you time and effort by reducing the need to refer to APL tech documentation. With the intelligent suggestions, you can easily and accurately author your APL document without syntactical errors. Read more about the code snippets here.

Getting Started with APL 2024.1

To begin building with APL 2024.1 features and ensure backward compatibility of your experience, please visit work with APL versions. You may also check the version of APL supported on Amazon devices by following instructions here: APL versions and Amazon device support. We have updated APL authoring tools and documentation to help you take advantage of new APL 2024.1 features so you can build new documents or add the new features to existing documents with Visual Studio Code with ASK toolkit or APL Authoring tool. Our quick reference APL Cheat Sheetsguide and APL technical documentation have also been updated to include 2024.1 features. If you’re new to learning APL, start off here. More info on versioning is available on our “What’s New” page.

Help us build better for you!

APL enhancements are made possible through your continued partnership and feedback. Please take a moment to tell us how we can better help you by providing feedback via our developer survey. You can also continue learning about APL features in our technical documentation. Please come find us and other multimodal developers on Alexa Community Slack or on X ( @smrudula@pkarthikr) if you need if you need assistance. 

Recommended Reading

3 questions with Labinot Bytyqi, CEO and Founder of virtual healthcare delivery platform hellocare.ai
Learn more about Alexa Smart Properties
New developer tools to build LLM-powered experiences with Alexa

Subscribe