actions-on-google
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -19,3 +19,3 @@ /** | ||
export { Response, Conversation, LinkOutSuggestionOptions, LinkOutSuggestion, SimpleResponseOptions, SimpleResponse, ImageOptions, Image, OpenUrlActionOptions, OpenUrlAction, ButtonOptions, Button, BasicCardOptions, BasicCard, TableOptions, Table, TableRow, TableColumn, BrowseCarouselItemOptions, BrowseCarouselItem, BrowseCarouselOptions, BrowseCarousel, MediaObjectOptions, MediaObject, MediaResponseOptions, MediaResponse, OrderUpdate, RichResponseItem, RichResponseOptions, RichResponse, Suggestions, SurfaceCapability } from './service/actionssdk'; | ||
export { Argument, RepromptArgument, FinalRepromptArgument, OptionItem, CarouselOptionItem, CarouselArgument, CarouselOptions, Carousel, ConfirmationArgument, Confirmation, DateTimeArgument, DateTimeOptions, DateTime, ListArgument, ListOptions, List, NewSurfaceArgument, NewSurfaceOptions, NewSurface, OptionArgument, PermissionArgument, PermissionOptions, Permission, SignInArgument, SignIn, UpdatePermissionUserIdArgument, UpdatePermissionOptions, UpdatePermission, RegisterUpdateArgument, RegisterUpdateOptions, RegisterUpdate, PlaceArgument, Place, DeepLinkArgument, DeepLinkOptions, DeepLink, TransactionDecisionArgument, TransactionDecision, TransactionRequirementsArgument, TransactionRequirements, DeliveryAddressArgument, DeliveryAddress, MediaStatusArgument } from './service/actionssdk'; | ||
export { Argument, RepromptArgument, FinalRepromptArgument, OptionItem, CarouselOptionItem, CarouselArgument, CarouselOptions, Carousel, ConfirmationArgument, Confirmation, DateTimeArgument, DateTimeOptions, DateTime, ListArgument, ListOptions, List, NewSurfaceArgument, NewSurfaceOptions, NewSurface, OptionArgument, PermissionArgument, PermissionOptions, Permission, SignInArgument, SignIn, UpdatePermissionUserIdArgument, UpdatePermissionOptions, UpdatePermission, RegisterUpdateArgument, RegisterUpdateOptions, RegisterUpdate, PlaceArgument, Place, DeepLinkArgument, DeepLinkOptions, DeepLink, TransactionDecisionArgument, TransactionDecision, TransactionRequirementsArgument, TransactionRequirements, DeliveryAddressArgument, DeliveryAddress, CompletePurchaseArgument, CompletePurchase, MediaStatusArgument, HelperOptions, Helper, SoloHelper } from './service/actionssdk'; | ||
export { Contexts, OutputContexts, Context, OutputContext, Parameters, DialogflowConversationOptions, DialogflowConversation, DialogflowIntentHandler, DialogflowMiddleware, DialogflowApp, DialogflowVerification, DialogflowOptions, Dialogflow, dialogflow } from './service/dialogflow'; | ||
@@ -22,0 +22,0 @@ export * from './service/dialogflow/api/v1'; |
@@ -49,2 +49,5 @@ "use strict"; | ||
exports.DeliveryAddress = actionssdk_2.DeliveryAddress; | ||
exports.CompletePurchase = actionssdk_2.CompletePurchase; | ||
exports.Helper = actionssdk_2.Helper; | ||
exports.SoloHelper = actionssdk_2.SoloHelper; | ||
var dialogflow_1 = require("./service/dialogflow"); | ||
@@ -51,0 +54,0 @@ exports.DialogflowConversation = dialogflow_1.DialogflowConversation; |
@@ -17,3 +17,3 @@ /** | ||
import * as Api from '../../api/v2'; | ||
import { NewSurfaceArgument, PermissionArgument, OptionArgument, ConfirmationArgument, DateTimeArgument, SignInArgument, PlaceArgument, DeepLinkArgument, TransactionDecisionArgument, TransactionRequirementsArgument, DeliveryAddressArgument, RegisterUpdateArgument, UpdatePermissionUserIdArgument } from '..'; | ||
import { NewSurfaceArgument, PermissionArgument, OptionArgument, ConfirmationArgument, DateTimeArgument, SignInArgument, PlaceArgument, DeepLinkArgument, TransactionDecisionArgument, TransactionRequirementsArgument, DeliveryAddressArgument, RegisterUpdateArgument, UpdatePermissionUserIdArgument, CompletePurchaseArgument } from '..'; | ||
import { RepromptArgument, FinalRepromptArgument } from './noinput'; | ||
@@ -64,2 +64,8 @@ import { MediaStatusArgument } from './media'; | ||
/** | ||
* The complete purchase information. | ||
* Only use after calling {@link CompletePurchase|conv.ask(new CompletePurchase)}. | ||
* @public | ||
*/ | ||
COMPLETE_PURCHASE_VALUE?: CompletePurchaseArgument; | ||
/** | ||
* The confirmation decision. | ||
@@ -66,0 +72,0 @@ * Use after {@link Confirmation|conv.ask(new Confirmation)} |
@@ -21,3 +21,3 @@ /** | ||
import { Image, RichResponse, Suggestions, RichResponseItem, MediaObject, SimpleResponse } from './response'; | ||
import { Question } from './question'; | ||
import { Helper } from './helper'; | ||
import { Arguments } from './argument'; | ||
@@ -30,9 +30,9 @@ import { Device } from './device'; | ||
/** @public */ | ||
export declare type Intent = 'actions.intent.MAIN' | 'actions.intent.TEXT' | 'actions.intent.PERMISSION' | 'actions.intent.OPTION' | 'actions.intent.TRANSACTION_REQUIREMENTS_CHECK' | 'actions.intent.DELIVERY_ADDRESS' | 'actions.intent.TRANSACTION_DECISION' | 'actions.intent.CONFIRMATION' | 'actions.intent.DATETIME' | 'actions.intent.SIGN_IN' | 'actions.intent.NO_INPUT' | 'actions.intent.CANCEL' | 'actions.intent.NEW_SURFACE' | 'actions.intent.REGISTER_UPDATE' | 'actions.intent.CONFIGURE_UPDATES' | 'actions.intent.PLACE' | 'actions.intent.LINK' | 'actions.intent.MEDIA_STATUS'; | ||
export declare type Intent = 'actions.intent.MAIN' | 'actions.intent.TEXT' | 'actions.intent.PERMISSION' | 'actions.intent.OPTION' | 'actions.intent.TRANSACTION_REQUIREMENTS_CHECK' | 'actions.intent.DELIVERY_ADDRESS' | 'actions.intent.TRANSACTION_DECISION' | 'actions.intent.CONFIRMATION' | 'actions.intent.DATETIME' | 'actions.intent.SIGN_IN' | 'actions.intent.NO_INPUT' | 'actions.intent.CANCEL' | 'actions.intent.NEW_SURFACE' | 'actions.intent.REGISTER_UPDATE' | 'actions.intent.CONFIGURE_UPDATES' | 'actions.intent.PLACE' | 'actions.intent.LINK' | 'actions.intent.MEDIA_STATUS' | 'actions.intent.COMPLETE_PURCHASE'; | ||
/** @hidden */ | ||
export declare type InputValueSpec = 'type.googleapis.com/google.actions.v2.PermissionValueSpec' | 'type.googleapis.com/google.actions.v2.OptionValueSpec' | 'type.googleapis.com/google.actions.v2.TransactionRequirementsCheckSpec' | 'type.googleapis.com/google.actions.v2.DeliveryAddressValueSpec' | 'type.googleapis.com/google.actions.v2.TransactionDecisionValueSpec' | 'type.googleapis.com/google.actions.v2.ConfirmationValueSpec' | 'type.googleapis.com/google.actions.v2.DateTimeValueSpec' | 'type.googleapis.com/google.actions.v2.NewSurfaceValueSpec' | 'type.googleapis.com/google.actions.v2.RegisterUpdateValueSpec' | 'type.googleapis.com/google.actions.v2.SignInValueSpec' | 'type.googleapis.com/google.actions.v2.PlaceValueSpec' | 'type.googleapis.com/google.actions.v2.LinkValueSpec'; | ||
export declare type InputValueSpec = 'type.googleapis.com/google.actions.v2.PermissionValueSpec' | 'type.googleapis.com/google.actions.v2.OptionValueSpec' | 'type.googleapis.com/google.actions.v2.TransactionRequirementsCheckSpec' | 'type.googleapis.com/google.actions.v2.DeliveryAddressValueSpec' | 'type.googleapis.com/google.actions.v2.TransactionDecisionValueSpec' | 'type.googleapis.com/google.actions.v2.ConfirmationValueSpec' | 'type.googleapis.com/google.actions.v2.DateTimeValueSpec' | 'type.googleapis.com/google.actions.v2.NewSurfaceValueSpec' | 'type.googleapis.com/google.actions.v2.RegisterUpdateValueSpec' | 'type.googleapis.com/google.actions.v2.SignInValueSpec' | 'type.googleapis.com/google.actions.v2.PlaceValueSpec' | 'type.googleapis.com/google.actions.v2.LinkValueSpec' | 'type.googleapis.com/google.actions.transactions.v3.CompletePurchaseValueSpec'; | ||
/** @hidden */ | ||
export declare type DialogSpec = 'type.googleapis.com/google.actions.v2.PlaceValueSpec.PlaceDialogSpec' | 'type.googleapis.com/google.actions.v2.LinkValueSpec.LinkDialogSpec'; | ||
/** @public */ | ||
export declare type Response = RichResponse | RichResponseItem | Image | Suggestions | MediaObject | Question<Intent, JsonObject>; | ||
export declare type Response = RichResponse | RichResponseItem | Image | Suggestions | MediaObject | Helper<Intent, JsonObject>; | ||
/** @hidden */ | ||
@@ -39,0 +39,0 @@ export interface ConversationResponse { |
@@ -21,3 +21,3 @@ "use strict"; | ||
const response_1 = require("./response"); | ||
const question_1 = require("./question"); | ||
const helper_1 = require("./helper"); | ||
const argument_1 = require("./argument"); | ||
@@ -205,6 +205,6 @@ const device_1 = require("./device"); | ||
} | ||
if (response instanceof question_1.Question) { | ||
if (response instanceof helper_1.Helper) { | ||
expectedIntent = response; | ||
if (response instanceof question_1.SoloQuestion) { | ||
// SoloQuestions don't require a SimpleResponse | ||
if (response instanceof helper_1.SoloHelper) { | ||
// SoloHelper classes don't require a SimpleResponse | ||
// but API still requires a SimpleResponse | ||
@@ -211,0 +211,0 @@ // so a placeholder is added to not error |
@@ -17,5 +17,5 @@ /** | ||
export * from './conversation'; | ||
export * from './question'; | ||
export * from './helper'; | ||
export * from './argument'; | ||
export * from './response'; | ||
export * from './surface'; |
@@ -22,3 +22,3 @@ "use strict"; | ||
__export(require("./conversation")); | ||
__export(require("./question")); | ||
__export(require("./helper")); | ||
__export(require("./argument")); | ||
@@ -25,0 +25,0 @@ __export(require("./response")); |
@@ -144,2 +144,4 @@ /** | ||
version: number; | ||
/** @hidden */ | ||
_followup?: Api.GoogleCloudDialogflowV2EventInput | ApiV1.DialogflowV1FollowupEvent; | ||
/** @public */ | ||
@@ -149,2 +151,5 @@ constructor(options: DialogflowConversationOptions<TConvData, TUserStorage>); | ||
* Triggers an intent of your choosing by sending a followup event from the webhook. | ||
* Final response can theoretically include responses but these will not be handled | ||
* by Dialogflow. Dialogflow will not pass anything back to Google Assistant, therefore | ||
* Google Assistant specific information, most notably conv.user.storage, is ignored. | ||
* | ||
@@ -151,0 +156,0 @@ * @example |
@@ -21,5 +21,16 @@ "use strict"; | ||
const incoming_1 = require("./incoming"); | ||
const APP_DATA_CONTEXT = '_actions_on_google'; | ||
const APP_DATA_CONTEXT_LIFESPAN = 99; | ||
const CONV_DATA_CONTEXT = '_actions_on_google'; | ||
const CONV_DATA_CONTEXT_LIFESPAN = 99; | ||
const SIMULATOR_WARNING = 'Cannot display response in Dialogflow simulator. ' + | ||
'Please test on the Google Assistant simulator instead.'; | ||
const isV1 = (body) => !!body.result; | ||
const isSimulator = (body) => { | ||
if (isV1(body)) { | ||
return !body.originalRequest; | ||
} | ||
if (!body.originalDetectIntentRequest) { | ||
return false; | ||
} | ||
return Object.keys(body.originalDetectIntentRequest.payload).length === 0; | ||
}; | ||
const getRequest = (body) => { | ||
@@ -78,3 +89,3 @@ if (isV1(body)) { | ||
this.data = (init && init.data) || {}; | ||
const context = this.contexts.input[APP_DATA_CONTEXT]; | ||
const context = this.contexts.input[CONV_DATA_CONTEXT]; | ||
if (context) { | ||
@@ -89,2 +100,5 @@ const { data } = context.parameters; | ||
* Triggers an intent of your choosing by sending a followup event from the webhook. | ||
* Final response can theoretically include responses but these will not be handled | ||
* by Dialogflow. Dialogflow will not pass anything back to Google Assistant, therefore | ||
* Google Assistant specific information, most notably conv.user.storage, is ignored. | ||
* | ||
@@ -117,18 +131,17 @@ * @example | ||
followup(event, parameters, lang) { | ||
this._responded = true; | ||
if (this.version === 1) { | ||
return this.json({ | ||
followupEvent: { | ||
name: event, | ||
data: parameters, | ||
}, | ||
}); | ||
this._followup = { | ||
name: event, | ||
data: parameters, | ||
}; | ||
return this; | ||
} | ||
const body = this.body; | ||
return this.json({ | ||
followupEventInput: { | ||
name: event, | ||
parameters, | ||
languageCode: lang || body.queryResult.languageCode, | ||
}, | ||
}); | ||
this._followup = { | ||
name: event, | ||
parameters, | ||
languageCode: lang || body.queryResult.languageCode, | ||
}; | ||
return this; | ||
} | ||
@@ -154,5 +167,6 @@ /** @public */ | ||
}; | ||
this.contexts.set(APP_DATA_CONTEXT, APP_DATA_CONTEXT_LIFESPAN, { | ||
this.contexts.set(CONV_DATA_CONTEXT, CONV_DATA_CONTEXT_LIFESPAN, { | ||
data: JSON.stringify(this.data), | ||
}); | ||
const simulator = !this._followup && isSimulator(this.body); | ||
if (this.version === 1) { | ||
@@ -163,3 +177,12 @@ const contextOut = this.contexts._serializeV1(); | ||
contextOut, | ||
followupEvent: this._followup, | ||
}; | ||
if (simulator) { | ||
const items = payload.google.richResponse.items; | ||
response.displayText = | ||
(payload.google.systemIntent || items.length > 1) ? | ||
SIMULATOR_WARNING : | ||
(items[0].simpleResponse.displayText || | ||
items[0].simpleResponse.textToSpeech); | ||
} | ||
return response; | ||
@@ -171,3 +194,12 @@ } | ||
outputContexts, | ||
followupEventInput: this._followup, | ||
}; | ||
if (simulator) { | ||
const items = payload.google.richResponse.items; | ||
response.fulfillmentText = | ||
(payload.google.systemIntent || items.length > 1) ? | ||
SIMULATOR_WARNING : | ||
(items[0].simpleResponse.displayText || | ||
items[0].simpleResponse.textToSpeech); | ||
} | ||
return response; | ||
@@ -174,0 +206,0 @@ } |
@@ -134,2 +134,5 @@ "use strict"; | ||
if (!this._handlers.fallback) { | ||
if (!intent) { | ||
throw new Error('No intent was provided and fallback handler is not defined.'); | ||
} | ||
throw new Error(`Dialogflow IntentHandler not found for intent: ${intent}`); | ||
@@ -136,0 +139,0 @@ } |
@@ -90,3 +90,3 @@ /** | ||
export interface SmartHomeV1SyncPayload { | ||
agentUserId: string; | ||
agentUserId?: string; | ||
errorCode?: string; | ||
@@ -93,0 +93,0 @@ debugString?: string; |
@@ -140,9 +140,14 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.key) { | ||
throw new Error(`An API key was not specified. ` + | ||
`Please visit https://console.cloud.google.com/apis/api/homegraph.googleapis.com/overview`); | ||
if (this.jwt) { | ||
return yield makeApiCall('/v1/devices:requestSync', { | ||
agent_user_id: agentUserId, | ||
}, this.jwt); | ||
} | ||
return yield makeApiCall(`/v1/devices:requestSync?key=${encodeURIComponent(this.key)}`, { | ||
agent_user_id: agentUserId, | ||
}); | ||
if (this.key) { | ||
return yield makeApiCall(`/v1/devices:requestSync?key=${encodeURIComponent(this.key)}`, { | ||
agent_user_id: agentUserId, | ||
}); | ||
} | ||
throw new Error(`An API key was not specified. ` + | ||
`Please visit https://console.cloud.google.com/apis/api/homegraph.googleapis.com/overview`); | ||
}); | ||
@@ -149,0 +154,0 @@ }, |
@@ -6,3 +6,3 @@ { | ||
"types": "dist/index.d.ts", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"license": "Apache-2.0", | ||
@@ -24,4 +24,5 @@ "author": "Google Inc.", | ||
"test:ci": "yarn test", | ||
"docs": "typedoc --options typedoc.json", | ||
"docs:clean": "rm -rf docs && mkdir docs && touch docs/.nojekyll && yarn docs", | ||
"docs:redirect": "node script/redirect.js", | ||
"docs": "typedoc --options typedoc.json && touch docs/.nojekyll && yarn docs:redirect", | ||
"docs:clean": "rm -rf docs && yarn docs", | ||
"docs:serve": "yarn docs:clean && live-server docs", | ||
@@ -28,0 +29,0 @@ "coverage": "yarn coverage:serve", |
@@ -18,6 +18,7 @@ # Actions on Google Client Library | ||
### Dialogflow | ||
### Conversational Services | ||
#### Dialogflow | ||
```javascript | ||
// Import the appropriate service and chosen wrappers | ||
const { | ||
@@ -29,3 +30,2 @@ dialogflow, | ||
// Create an app instance | ||
const app = dialogflow() | ||
@@ -54,6 +54,5 @@ | ||
### Actions SDK | ||
#### Actions SDK | ||
```javascript | ||
// Import the appropriate service and chosen wrappers | ||
const { | ||
@@ -65,3 +64,2 @@ actionssdk, | ||
// Create an app instance | ||
const app = actionssdk() | ||
@@ -88,10 +86,23 @@ | ||
#### Notes about the code snippet | ||
* [`conv.ask`](https://actions-on-google.github.io/actions-on-google-nodejs/classes/conversation.conversation-1.html#ask)/[`conv.close`](https://actions-on-google.github.io/actions-on-google-nodejs/classes/conversation.conversation-1.html#close) | ||
can be called with any of the [`Response`](https://actions-on-google.github.io/actions-on-google-nodejs/modules/conversation.html#response) types. | ||
* All [`Helper`](https://actions-on-google.github.io/actions-on-google-nodejs/modules/conversation_helper.html) classes are of the `Response` type. | ||
##### Dialogflow | ||
* `app` is an instance of type [`DialogflowApp`](https://actions-on-google.github.io/actions-on-google-nodejs/interfaces/dialogflow.dialogflowapp.html#catch). | ||
* `app` accepts options of type [`DialogflowOptions`](https://actions-on-google.github.io/actions-on-google-nodejs/interfaces/dialogflow.dialogflowoptions.html#clientid). | ||
* `conv` is an instance of type [`DialogflowConversation`](https://actions-on-google.github.io/actions-on-google-nodejs/classes/dialogflow.dialogflowconversation.html). | ||
##### Actions SDK | ||
* `app` is an instance of type [`ActionsSdkApp`](https://actions-on-google.github.io/actions-on-google-nodejs/interfaces/actionssdk.actionssdkapp.html#catch). | ||
* `app` accepts options of type [`ActionsSdkOptions`](https://actions-on-google.github.io/actions-on-google-nodejs/interfaces/actionssdk.actionssdkoptions.html#clientid). | ||
* `conv` is an instance of type [`ActionsSdkConversation`](https://actions-on-google.github.io/actions-on-google-nodejs/classes/actionssdk.actionssdkconversation.html). | ||
### Smart Home | ||
```javascript | ||
// Import the appropriate service | ||
const { smarthome } = require('actions-on-google') | ||
// Create an app instance | ||
const app = smarthome() | ||
@@ -129,2 +140,6 @@ | ||
#### Notes about the code snippet | ||
* `app` is an instance of type [`SmartHomeApp`](https://actions-on-google.github.io/actions-on-google-nodejs/interfaces/smarthome.smarthomeapp.html#onexecute). | ||
* `app` accepts options of type [`SmartHomeOptions`](https://actions-on-google.github.io/actions-on-google-nodejs/interfaces/smarthome.smarthomeoptions.html#debug). | ||
### Frameworks | ||
@@ -131,0 +146,0 @@ |
@@ -110,3 +110,8 @@ /** | ||
DeliveryAddress, | ||
CompletePurchaseArgument, | ||
CompletePurchase, | ||
MediaStatusArgument, | ||
HelperOptions, | ||
Helper, | ||
SoloHelper, | ||
} from './service/actionssdk' | ||
@@ -113,0 +118,0 @@ |
@@ -32,2 +32,3 @@ /** | ||
UpdatePermissionUserIdArgument, | ||
CompletePurchaseArgument, | ||
} from '..' | ||
@@ -94,2 +95,9 @@ import { | ||
/** | ||
* The complete purchase information. | ||
* Only use after calling {@link CompletePurchase|conv.ask(new CompletePurchase)}. | ||
* @public | ||
*/ | ||
COMPLETE_PURCHASE_VALUE?: CompletePurchaseArgument | ||
/** | ||
* The confirmation decision. | ||
@@ -96,0 +104,0 @@ * Use after {@link Confirmation|conv.ask(new Confirmation)} |
@@ -31,3 +31,3 @@ /** | ||
} from './response' | ||
import { Question, SoloQuestion } from './question' | ||
import { Helper, SoloHelper } from './helper' | ||
import { Arguments } from './argument' | ||
@@ -59,3 +59,4 @@ import { Device } from './device' | ||
'actions.intent.LINK' | | ||
'actions.intent.MEDIA_STATUS' | ||
'actions.intent.MEDIA_STATUS' | | ||
'actions.intent.COMPLETE_PURCHASE' | ||
@@ -75,3 +76,4 @@ /** @hidden */ | ||
'type.googleapis.com/google.actions.v2.PlaceValueSpec' | | ||
'type.googleapis.com/google.actions.v2.LinkValueSpec' | ||
'type.googleapis.com/google.actions.v2.LinkValueSpec' | | ||
'type.googleapis.com/google.actions.transactions.v3.CompletePurchaseValueSpec' | ||
@@ -90,3 +92,3 @@ /** @hidden */ | ||
MediaObject | | ||
Question<Intent, JsonObject> | ||
Helper<Intent, JsonObject> | ||
@@ -400,6 +402,6 @@ /** @hidden */ | ||
} | ||
if (response instanceof Question) { | ||
if (response instanceof Helper) { | ||
expectedIntent = response | ||
if (response instanceof SoloQuestion) { | ||
// SoloQuestions don't require a SimpleResponse | ||
if (response instanceof SoloHelper) { | ||
// SoloHelper classes don't require a SimpleResponse | ||
// but API still requires a SimpleResponse | ||
@@ -406,0 +408,0 @@ // so a placeholder is added to not error |
@@ -18,5 +18,5 @@ /** | ||
export * from './conversation' | ||
export * from './question' | ||
export * from './helper' | ||
export * from './argument' | ||
export * from './response' | ||
export * from './surface' |
@@ -25,4 +25,6 @@ /** | ||
const APP_DATA_CONTEXT = '_actions_on_google' | ||
const APP_DATA_CONTEXT_LIFESPAN = 99 | ||
const CONV_DATA_CONTEXT = '_actions_on_google' | ||
const CONV_DATA_CONTEXT_LIFESPAN = 99 | ||
const SIMULATOR_WARNING = 'Cannot display response in Dialogflow simulator. ' + | ||
'Please test on the Google Assistant simulator instead.' | ||
@@ -63,2 +65,14 @@ /** @hidden */ | ||
const isSimulator = ( | ||
body: Api.GoogleCloudDialogflowV2WebhookRequest | ApiV1.DialogflowV1WebhookRequest, | ||
) => { | ||
if (isV1(body)) { | ||
return !body.originalRequest | ||
} | ||
if (!body.originalDetectIntentRequest) { | ||
return false | ||
} | ||
return Object.keys(body.originalDetectIntentRequest.payload!).length === 0 | ||
} | ||
const getRequest = ( | ||
@@ -188,2 +202,5 @@ body: Api.GoogleCloudDialogflowV2WebhookRequest | ApiV1.DialogflowV1WebhookRequest, | ||
/** @hidden */ | ||
_followup?: Api.GoogleCloudDialogflowV2EventInput | ApiV1.DialogflowV1FollowupEvent | ||
/** @public */ | ||
@@ -253,3 +270,3 @@ constructor(options: DialogflowConversationOptions<TConvData, TUserStorage>) { | ||
const context = this.contexts.input[APP_DATA_CONTEXT] | ||
const context = this.contexts.input[CONV_DATA_CONTEXT] | ||
if (context) { | ||
@@ -265,2 +282,5 @@ const { data } = context.parameters | ||
* Triggers an intent of your choosing by sending a followup event from the webhook. | ||
* Final response can theoretically include responses but these will not be handled | ||
* by Dialogflow. Dialogflow will not pass anything back to Google Assistant, therefore | ||
* Google Assistant specific information, most notably conv.user.storage, is ignored. | ||
* | ||
@@ -293,18 +313,17 @@ * @example | ||
followup(event: string, parameters?: Parameters, lang?: string) { | ||
this._responded = true | ||
if (this.version === 1) { | ||
return this.json<ApiV1.DialogflowV1WebhookResponse>({ | ||
followupEvent: { | ||
this._followup = { | ||
name: event, | ||
data: parameters, | ||
}, | ||
}) | ||
} | ||
return this | ||
} | ||
const body = this.body as Api.GoogleCloudDialogflowV2WebhookRequest | ||
return this.json<Api.GoogleCloudDialogflowV2WebhookResponse>({ | ||
followupEventInput: { | ||
name: event, | ||
parameters, | ||
languageCode: lang || body.queryResult!.languageCode, | ||
}, | ||
}) | ||
this._followup = { | ||
name: event, | ||
parameters, | ||
languageCode: lang || body.queryResult!.languageCode, | ||
} | ||
return this | ||
} | ||
@@ -337,5 +356,6 @@ | ||
} | ||
this.contexts.set(APP_DATA_CONTEXT, APP_DATA_CONTEXT_LIFESPAN, { | ||
this.contexts.set(CONV_DATA_CONTEXT, CONV_DATA_CONTEXT_LIFESPAN, { | ||
data: JSON.stringify(this.data), | ||
}) | ||
const simulator = !this._followup && isSimulator(this.body) | ||
if (this.version === 1) { | ||
@@ -346,3 +366,12 @@ const contextOut = this.contexts._serializeV1() | ||
contextOut, | ||
followupEvent: this._followup, | ||
} | ||
if (simulator) { | ||
const items = payload.google.richResponse.items! | ||
response.displayText = | ||
(payload.google.systemIntent || items.length > 1) ? | ||
SIMULATOR_WARNING : | ||
(items[0].simpleResponse!.displayText || | ||
items[0].simpleResponse!.textToSpeech) | ||
} | ||
return response | ||
@@ -354,5 +383,14 @@ } | ||
outputContexts, | ||
followupEventInput: this._followup, | ||
} | ||
if (simulator) { | ||
const items = payload.google.richResponse.items! | ||
response.fulfillmentText = | ||
(payload.google.systemIntent || items.length > 1) ? | ||
SIMULATOR_WARNING : | ||
(items[0].simpleResponse!.displayText || | ||
items[0].simpleResponse!.textToSpeech) | ||
} | ||
return response | ||
} | ||
} |
@@ -442,2 +442,5 @@ /** | ||
if (!this._handlers.fallback) { | ||
if (!intent) { | ||
throw new Error('No intent was provided and fallback handler is not defined.') | ||
} | ||
throw new Error(`Dialogflow IntentHandler not found for intent: ${intent}`) | ||
@@ -444,0 +447,0 @@ } |
@@ -119,3 +119,3 @@ /** | ||
export interface SmartHomeV1SyncPayload { | ||
agentUserId: string, | ||
agentUserId?: string, | ||
errorCode?: string, | ||
@@ -122,0 +122,0 @@ debugString?: string, |
@@ -397,9 +397,14 @@ /** | ||
async requestSync(this: SmartHomeApp, agentUserId) { | ||
if (!this.key) { | ||
throw new Error(`An API key was not specified. ` + | ||
if (this.jwt) { | ||
return await makeApiCall('/v1/devices:requestSync', { | ||
agent_user_id: agentUserId, | ||
}, this.jwt) | ||
} | ||
if (this.key) { | ||
return await makeApiCall(`/v1/devices:requestSync?key=${encodeURIComponent(this.key)}`, { | ||
agent_user_id: agentUserId, | ||
}) | ||
} | ||
throw new Error(`An API key was not specified. ` + | ||
`Please visit https://console.cloud.google.com/apis/api/homegraph.googleapis.com/overview`) | ||
} | ||
return await makeApiCall(`/v1/devices:requestSync?key=${encodeURIComponent(this.key)}`, { | ||
agent_user_id: agentUserId, | ||
}) | ||
}, | ||
@@ -406,0 +411,0 @@ async reportState(this: SmartHomeApp, reportedState) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
948065
268
20989
222