Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.
This repository was archived by the owner on Oct 2, 2023. It is now read-only.

Bug: Extensions to add new request type only work after handling a built in (core) request type.  #201

@cheruvian

Description

@cheruvian

Bug Report

Litexa generates the following code:

  ...
  switch (request.type) {
    case 'IntentRequest':
    case 'LaunchRequest':
      ...
    case 'Connections.Response':
      ...
    default:
      stateContext.intent = request.type;
      stateContext.handoffIntent = true;
      stateContext.handoffState = stateContext.currentState;
      stateContext.nextState = null;
      handled = false;
      for (extensionName in extensionRequests) {
        requests = extensionRequests[extensionName];
        if (request.type in requests) {
          handled = true;
          func = requests[request.type];
          if (typeof func === 'function') {
            func(request);
          }
        }
      }
      if (ref18 = request.type, indexOf.call(litexa.extendedEventNames, ref18) >= 0) {
        handled = true;
      }
      if (!handled) {
        throw new Error(`unrecognized event type: ${request.type}`);
      }
  }
  return  initializeExtensionObjects(stateContext);
}
...

Notice that initializeExtensionObjects is called after the switch statement, this means that the extension types are not added unless a built in request.type is called first.

Litexa Version

0.7.1

Current Behavior

Custom request.type is not installed unless a built in intent is called first.

Expected Behavior

Custom request.type should be installed immediately rather than defer until after the first request.

Steps to Reproduce

Create a custom extension

//litexa.extension.js
module.exports = function (options, lib) {
  return {
    runtime: {
      apiName: "MyExtension", // extension namespace: see 'userFacing' below, for application
      source: require("./handler.js")// source code for extension handler
    }
  }
}
// handler.js
module.exports = function (context) {
  return {
    requests: {
      'CustomIntentRequest': function (request) {
        console.log("i wont be installed until after a built in request type");
      }
  }
}

Additional Information

This is easily resolve by moving initializeExtensionObjects to before the switch statement.

  ...
 // MOVED HERE
 initializeExtensionObjects(stateContext);
  switch (request.type) {
    case 'IntentRequest':
    case 'LaunchRequest':
      ...
    case 'Connections.Response':
      ...
    default:
      stateContext.intent = request.type;
      stateContext.handoffIntent = true;
      stateContext.handoffState = stateContext.currentState;
      stateContext.nextState = null;
      handled = false;
      for (extensionName in extensionRequests) {
        requests = extensionRequests[extensionName];
        if (request.type in requests) {
          handled = true;
          func = requests[request.type];
          if (typeof func === 'function') {
            func(request);
          }
        }
      }
      if (ref18 = request.type, indexOf.call(litexa.extendedEventNames, ref18) >= 0) {
        handled = true;
      }
      if (!handled) {
        throw new Error(`unrecognized event type: ${request.type}`);
      }
  }
  return 
}
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions