Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for a fallback handler #393

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 4.3.0 (Next)

* [#388](https://github.com/alexa-js/alexa-app/pull/388): Updating typings for values of AuthorityResolution - [@camerongraybill](https://github.com/camerongraybill).
* [#393](https://github.com/alexa-js/alexa-app/pull/393): Add support for default/fallback handler for all intents - [@pariola](https://github.com/pariola).

### 4.2.3 (October 28, 2018)

Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,16 @@ alexa.session = function(session) {

alexa.router = function(app, request, response, request_json) {
this.intent = function(intent) {
request.intent = intent;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This modifies the incoming request, I don't think that's a good idea, at the very least it's an anti-pattern to be modifying something coming from the outside.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, i understand and already updated the code as that field is still accessible from the raw data

if (typeof app.intents[intent] !== "undefined" && typeof app.intents[intent].handler === "function") {
if (app.intents[intent].isDelegatedDialog() && !request.getDialog().isCompleted()) {
return Promise.resolve(request.getDialog().handleDialogDelegation(request, response));
} else {
return Promise.resolve(app.intents[intent].handler(request, response));
}
} else {
throw "NO_INTENT_FOUND";
if (!app.intents["__fallback__"]) throw "NO_INTENT_FOUND";
return Promise.resolve(app.intents["__fallback__"].handler(request, response));
}
};
this.launch = function() {
Expand Down
3 changes: 3 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ export class request {
/** Returns the request context */
context: alexa.Context;

/** Returns the matched intent name */
intent: string;

/** The raw request JSON object from Amazon */
data: alexa.RequestBody;

Expand Down