Clean type definitions generated from the files in staging with tsd-jsdoc

This commit is contained in:
Joel Hegg 2017-10-20 02:41:47 -04:00
parent 4a6480cbb3
commit e568cc22cc
5 changed files with 3149 additions and 0 deletions

View File

@ -0,0 +1,545 @@
/**
* @typedef {object} ActionsSdkAppOptions JSON configuration.
* @property {TODO} request - Express HTTP request object.
* @property {TODO} response - Express HTTP response object.
* @property {TODO=} sessionStarted - Function callback when session starts.
*/
declare type ActionsSdkAppOptions = {
request: any;
response: any;
sessionStarted: any;
};
/**
* This is the class that handles the conversation API directly from Assistant,
* providing implementation for all the methods available in the API.
*/
declare class ActionsSdkApp {
constructor(options: ActionsSdkAppOptions);
/**
* Validates whether request is from Assistant through signature verification.
* Uses Google-Auth-Library to verify authorization token against given
* Google Cloud Project ID. Auth token is given in request header with key,
* "Authorization".
* @example
* const app = new ActionsSdkApp({request, response});
* app.isRequestFromAssistant('nodejs-cloud-test-project-1234')
* .then(() => {
* app.ask('Hey there, thanks for stopping by!');
* })
* .catch(err => {
* response.status(400).send();
* });
* @param {string} projectId Google Cloud Project ID for the Assistant app.
* @return {TODO} Promise resolving with google-auth-library LoginTicket
* if request is from a valid source, otherwise rejects with the error reason
* for an invalid token.
* @actionssdk
*/
isRequestFromAssistant(projectId: string): any;
/**
* Gets the request Conversation API version.
* @example
* const app = new ActionsSdkApp({request: request, response: response});
* const apiVersion = app.getApiVersion();
* @return {string} Version value or null if no value.
* @actionssdk
*/
getApiVersion(): string;
/**
* Gets the user's raw input query.
* @example
* const app = new ActionsSdkApp({request: request, response: response});
* app.tell('You said ' + app.getRawInput());
* @return {string} User's raw query or null if no value.
* @actionssdk
*/
getRawInput(): string;
/**
* Gets previous JSON dialog state that the app sent to Assistant.
* Alternatively, use the app.data field to store JSON values between requests.
* @example
* const app = new ActionsSdkApp({request: request, response: response});
* const dialogState = app.getDialogState();
* @return {any} JSON object provided to the Assistant in the previous
* user turn or {} if no value.
* @actionssdk
*/
getDialogState(): any;
/**
* Gets the "versionLabel" specified inside the Action Package.
* Used by app to do version control.
* @example
* const app = new ActionsSdkApp({request: request, response: response});
* const actionVersionLabel = app.getActionVersionLabel();
* @return {string} The specified version label or null if unspecified.
* @actionssdk
*/
getActionVersionLabel(): string;
/**
* Gets the unique conversation ID. It's a new ID for the initial query,
* and stays the same until the end of the conversation.
* @example
* const app = new ActionsSdkApp({request: request, response: response});
* const conversationId = app.getConversationId();
* @return {string} Conversation ID or null if no value.
* @actionssdk
*/
getConversationId(): string;
/**
* Get the current intent. Alternatively, using a handler Map with
* {@link AssistantApp#handleRequest|handleRequest}, the client library will
* automatically handle the incoming intents.
* @example
* const app = new ActionsSdkApp({request: request, response: response});
* function responseHandler (app) {
* const intent = app.getIntent();
* switch (intent) {
* case app.StandardIntents.MAIN:
* const inputPrompt = app.buildInputPrompt(false, 'Welcome to action snippets! Say anything.');
* app.ask(inputPrompt);
* break;
* case app.StandardIntents.TEXT:
* app.tell('You said ' + app.getRawInput());
* break;
* }
* }
* app.handleRequest(responseHandler);
* @return {string} Intent id or null if no value.
* @actionssdk
*/
getIntent(): string;
/**
* Get the argument value by name from the current intent. If the argument
* is not a text argument, the entire argument object is returned.
* Note: If incoming request is using an API version under 2 (e.g. 'v1'),
* the argument object will be in Proto2 format (snake_case, etc).
* @param {string} argName Name of the argument.
* @return {string} Argument value matching argName
* or null if no matching argument.
* @actionssdk
*/
getArgument(argName: string): string;
/**
* Returns the option key user chose from options response.
* @example
* const app = new App({request: req, response: res});
* function pickOption (app) {
* if (app.hasSurfaceCapability(app.SurfaceCapabilities.SCREEN_OUTPUT)) {
* app.askWithCarousel('Which of these looks good?',
* app.buildCarousel().addItems(
* app.buildOptionItem('another_choice', ['Another choice']).
* setTitle('Another choice').setDescription('Choose me!')));
* } else {
* app.ask('What would you like?');
* }
* }
* function optionPicked (app) {
* app.ask('You picked ' + app.getSelectedOption());
* }
* const actionMap = new Map();
* actionMap.set(app.StandardIntents.TEXT, pickOption);
* actionMap.set(app.StandardIntents.OPTION, optionPicked);
* app.handleRequest(actionMap);
* @return {string} Option key of selected item. Null if no option selected or
* if current intent is not OPTION intent.
* @actionssdk
*/
getSelectedOption(): string;
/**
* Asks to collect user's input; all user's queries need to be sent to
* the app.
* {@link https://developers.google.com/actions/policies/general-policies#user_experience|The guidelines when prompting the user for a response must be followed at all times}.
* @example
* const app = new ActionsSdkApp({request: request, response: response});
* function mainIntent (app) {
* const inputPrompt = app.buildInputPrompt(true, '<speak>Hi! <break time="1"/> ' +
* 'I can read out an ordinal like ' +
* '<say-as interpret-as="ordinal">123</say-as>. Say a number.</speak>',
* ['I didn\'t hear a number', 'If you\'re still there, what\'s the number?', 'What is the number?']);
* app.ask(inputPrompt);
* }
* function rawInput (app) {
* if (app.getRawInput() === 'bye') {
* app.tell('Goodbye!');
* } else {
* const inputPrompt = app.buildInputPrompt(true, '<speak>You said, <say-as interpret-as="ordinal">' +
* app.getRawInput() + '</say-as></speak>',
* ['I didn\'t hear a number', 'If you\'re still there, what\'s the number?', 'What is the number?']);
* app.ask(inputPrompt);
* }
* }
* const actionMap = new Map();
* actionMap.set(app.StandardIntents.MAIN, mainIntent);
* actionMap.set(app.StandardIntents.TEXT, rawInput);
* app.handleRequest(actionMap);
* @param {InputPrompt|SimpleResponse|RichResponse} inputPrompt Holding initial and
* no-input prompts.
* @param {DialogState=} dialogState JSON object the app uses to hold dialog state that
* will be circulated back by App.
* @return {AskTellResponse} The response that is sent to Assistant to ask user to provide input.
* @actionssdk
*/
ask(inputPrompt: InputPrompt | SimpleResponse | RichResponse, dialogState?: DialogState): AskTellResponse;
/**
* Asks to collect user's input with a list.
* @example
* const app = new ActionsSdkApp({request, response});
* function welcomeIntent (app) {
* app.askWithlist('Which of these looks good?',
* app.buildList('List title')
* .addItems([
* app.buildOptionItem(SELECTION_KEY_ONE,
* ['synonym of KEY_ONE 1', 'synonym of KEY_ONE 2'])
* .setTitle('Number one'),
* app.buildOptionItem(SELECTION_KEY_TWO,
* ['synonym of KEY_TWO 1', 'synonym of KEY_TWO 2'])
* .setTitle('Number two'),
* ]));
* }
* function optionIntent (app) {
* if (app.getSelectedOption() === SELECTION_KEY_ONE) {
* app.tell('Number one is a great choice!');
* } else {
* app.tell('Number two is a great choice!');
* }
* }
* const actionMap = new Map();
* actionMap.set(app.StandardIntents.TEXT, welcomeIntent);
* actionMap.set(app.StandardIntents.OPTION, optionIntent);
* app.handleRequest(actionMap);
* @param {InputPrompt|SimpleResponse|RichResponse} inputPrompt Holding initial and
* no-input prompts. Cannot contain basic card.
* @param {List} list List built with {@link AssistantApp#buildList|buildList}.
* @param {DialogState=} dialogState JSON object the app uses to hold dialog state that
* will be circulated back by Assistant.
* @return {AskTellResponse} The response that is sent to Assistant to ask user to provide input.
* @actionssdk
*/
askWithList(inputPrompt: InputPrompt | SimpleResponse | RichResponse, list: List, dialogState?: DialogState): AskTellResponse;
/**
* Asks to collect user's input with a carousel.
* @example
* const app = new ActionsSdkApp({request, response});
* function welcomeIntent (app) {
* app.askWithCarousel('Which of these looks good?',
* app.buildCarousel()
* .addItems([
* app.buildOptionItem(SELECTION_KEY_ONE,
* ['synonym of KEY_ONE 1', 'synonym of KEY_ONE 2'])
* .setTitle('Number one'),
* app.buildOptionItem(SELECTION_KEY_TWO,
* ['synonym of KEY_TWO 1', 'synonym of KEY_TWO 2'])
* .setTitle('Number two'),
* ]));
* }
* function optionIntent (app) {
* if (app.getSelectedOption() === SELECTION_KEY_ONE) {
* app.tell('Number one is a great choice!');
* } else {
* app.tell('Number two is a great choice!');
* }
* }
* const actionMap = new Map();
* actionMap.set(app.StandardIntents.TEXT, welcomeIntent);
* actionMap.set(app.StandardIntents.OPTION, optionIntent);
* app.handleRequest(actionMap);
* @param {InputPrompt|SimpleResponse|RichResponse} inputPrompt Holding initial and
* no-input prompts. Cannot contain basic card.
* @param {Carousel} carousel Carousel built with
* {@link AssistantApp#buildCarousel|buildCarousel}.
* @param {DialogState=} dialogState JSON object the app uses to hold dialog state that
* will be circulated back by Assistant.
* @return {AskTellResponse} The response that is sent to Assistant to ask user to provide input.
* @actionssdk
*/
askWithCarousel(inputPrompt: InputPrompt | SimpleResponse | RichResponse, carousel: Carousel, dialogState?: DialogState): AskTellResponse;
/**
* Tells Assistant to render the speech response and close the mic.
* @example
* const app = new ActionsSdkApp({request: request, response: response});
* function mainIntent (app) {
* const inputPrompt = app.buildInputPrompt(true, '<speak>Hi! <break time="1"/> ' +
* 'I can read out an ordinal like ' +
* '<say-as interpret-as="ordinal">123</say-as>. Say a number.</speak>',
* ['I didn\'t hear a number', 'If you\'re still there, what\'s the number?', 'What is the number?']);
* app.ask(inputPrompt);
* }
* function rawInput (app) {
* if (app.getRawInput() === 'bye') {
* app.tell('Goodbye!');
* } else {
* const inputPrompt = app.buildInputPrompt(true, '<speak>You said, <say-as interpret-as="ordinal">' +
* app.getRawInput() + '</say-as></speak>',
* ['I didn\'t hear a number', 'If you\'re still there, what\'s the number?', 'What is the number?']);
* app.ask(inputPrompt);
* }
* }
* const actionMap = new Map();
* actionMap.set(app.StandardIntents.MAIN, mainIntent);
* actionMap.set(app.StandardIntents.TEXT, rawInput);
* app.handleRequest(actionMap);
* @param {string|SimpleResponse|RichResponse} textToSpeech Final response.
* Spoken response can be SSML.
* @return {AskTellResponse} The HTTP response that is sent back to Assistant.
* @actionssdk
*/
tell(textToSpeech: string | SimpleResponse | RichResponse): AskTellResponse;
/**
* Builds the {@link https://developers.google.com/actions/reference/conversation#InputPrompt|InputPrompt object}
* from initial prompt and no-input prompts.
* The App needs one initial prompt to start the conversation. If there is no user response,
* the App re-opens the mic and renders the no-input prompts three times
* (one for each no-input prompt that was configured) to help the user
* provide the right response.
* Note: we highly recommend app to provide all the prompts required here in order to ensure a
* good user experience.
* @example
* const inputPrompt = app.buildInputPrompt(false, 'Welcome to action snippets! Say a number.',
* ['Say any number', 'Pick a number', 'What is the number?']);
* app.ask(inputPrompt);
* @param {boolean} isSsml Indicates whether the text to speech is SSML or not.
* @param {string} initialPrompt The initial prompt the App asks the user.
* @param {Array<string>=} noInputs Array of re-prompts when the user does not respond (max 3).
* @return {InputPrompt} An {@link https://developers.google.com/actions/reference/conversation#InputPrompt|InputPrompt object}.
* @actionssdk
*/
buildInputPrompt(isSsml: boolean, initialPrompt: string, noInputs?: string[]): InputPrompt;
}
/**
* List of standard intents that the app provides.
* @readonly
* @enum {string}
* @actionssdk
* @dialogflow
*/
declare const enum StandardIntents {
/**
* App fires MAIN intent for queries like [talk to $app].
*/
MAIN,
/**
* App fires TEXT intent when action issues ask intent.
*/
TEXT,
/**
* App fires PERMISSION intent when action invokes askForPermission.
*/
PERMISSION,
/**
* App fires OPTION intent when user chooses from options provided.
*/
OPTION,
/**
* App fires TRANSACTION_REQUIREMENTS_CHECK intent when action sets up transaction.
*/
TRANSACTION_REQUIREMENTS_CHECK,
/**
* App fires DELIVERY_ADDRESS intent when action asks for delivery address.
*/
DELIVERY_ADDRESS,
/**
* App fires TRANSACTION_DECISION intent when action asks for transaction decision.
*/
TRANSACTION_DECISION,
/**
* App fires CONFIRMATION intent when requesting affirmation from user.
*/
CONFIRMATION,
/**
* App fires DATETIME intent when requesting date/time from user.
*/
DATETIME,
/**
* App fires SIGN_IN intent when requesting sign-in from user.
*/
SIGN_IN,
/**
* App fires NO_INPUT intent when user doesn't provide input.
*/
NO_INPUT,
/**
* App fires CANCEL intent when user exits app mid-dialog.
*/
CANCEL,
/**
* App fires NEW_SURFACE intent when requesting handoff to a new surface from user.
*/
NEW_SURFACE,
}
/**
* List of supported permissions the app supports.
* @readonly
* @enum {string}
* @actionssdk
* @dialogflow
*/
declare const enum SupportedPermissions {
/**
* The user's name as defined in the
* {@link https://developers.google.com/actions/reference/conversation#UserProfile|UserProfile object}
*/
NAME,
/**
* The location of the user's current device, as defined in the
* {@link https://developers.google.com/actions/reference/conversation#Location|Location object}.
*/
DEVICE_PRECISE_LOCATION,
/**
* City and zipcode corresponding to the location of the user's current device, as defined in the
* {@link https://developers.google.com/actions/reference/conversation#Location|Location object}.
*/
DEVICE_COARSE_LOCATION,
}
/**
* List of built-in argument names.
* @readonly
* @enum {string}
* @actionssdk
* @dialogflow
*/
declare const enum BuiltInArgNames {
/**
* Permission granted argument.
*/
PERMISSION_GRANTED,
/**
* Option selected argument.
*/
OPTION,
/**
* Transaction requirements check result argument.
*/
TRANSACTION_REQ_CHECK_RESULT,
/**
* Delivery address value argument.
*/
DELIVERY_ADDRESS_VALUE,
/**
* Transactions decision argument.
*/
TRANSACTION_DECISION_VALUE,
/**
* Confirmation argument.
*/
CONFIRMATION,
/**
* DateTime argument.
*/
DATETIME,
/**
* Sign in status argument.
*/
SIGN_IN,
/**
* Reprompt count for consecutive NO_INPUT intents.
*/
REPROMPT_COUNT,
/**
* Flag representing finality of NO_INPUT intent.
*/
IS_FINAL_REPROMPT,
/**
* New surface value argument.
*/
NEW_SURFACE,
}
/**
* List of possible conversation stages, as defined in the
* {@link https://developers.google.com/actions/reference/conversation#Conversation|Conversation object}.
* @readonly
* @enum {number}
* @actionssdk
* @dialogflow
*/
declare const enum ConversationStages {
/**
* Unspecified conversation state.
*/
UNSPECIFIED,
/**
* A new conversation.
*/
NEW,
/**
* An active (ongoing) conversation.
*/
ACTIVE,
}
/**
* List of surface capabilities supported by the app.
* @readonly
* @enum {string}
* @actionssdk
* @dialogflow
*/
declare const enum SurfaceCapabilities {
/**
* The ability to output audio.
*/
AUDIO_OUTPUT,
/**
* The ability to output on a screen
*/
SCREEN_OUTPUT,
}
/**
* List of possible user input types.
* @readonly
* @enum {number}
* @actionssdk
* @dialogflow
*/
declare const enum InputTypes {
/**
* Unspecified.
*/
UNSPECIFIED,
/**
* Input given by touch.
*/
TOUCH,
/**
* Input given by voice (spoken).
*/
VOICE,
/**
* Input given by keyboard (typed).
*/
KEYBOARD,
}
/**
* List of possible sign in result status values.
* @readonly
* @enum {string}
* @actionssdk
* @dialogflow
*/
declare const enum SignInStatus {
UNSPECIFIED,
OK,
CANCELLED,
ERROR,
}

1032
types/actions-on-google/assistant-app.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,475 @@
/**
* @typedef {object} DialogflowAppOptions JSON configuration.
* @property {TODO} request - Express HTTP request object.
* @property {TODO} response - Express HTTP response object.
* @property {TODO=} sessionStarted - Function callback when session starts.
* Only called if webhook is enabled for welcome/triggering intents, and
* called from Web Simulator or Google Home device (i.e., not Dialogflow simulator).
*/
declare type DialogflowAppOptions = {
request: any;
response: any;
sessionStarted: any;
};
/**
* This is the class that handles the communication with Dialogflow's fulfillment API.
*/
declare class DialogflowApp {
constructor(options: DialogflowAppOptions);
/**
* @deprecated
* Verifies whether the request comes from Dialogflow.
* @param {string} key The header key specified by the developer in the
* Dialogflow Fulfillment settings of the app.
* @param {string} value The private value specified by the developer inside the
* fulfillment header.
* @return {boolean} True if the request comes from Dialogflow.
* @dialogflow
*/
isRequestFromApiAi(key: string, value: string): boolean;
/**
* Verifies whether the request comes from Dialogflow.
* @param {string} key The header key specified by the developer in the
* Dialogflow Fulfillment settings of the app.
* @param {string} value The private value specified by the developer inside the
* fulfillment header.
* @return {boolean} True if the request comes from Dialogflow.
* @dialogflow
*/
isRequestFromDialogflow(key: string, value: string): boolean;
/**
* Get the current intent. Alternatively, using a handler Map with
* {@link AssistantApp#handleRequest|handleRequest},
* the client library will automatically handle the incoming intents.
* 'Intent' in the Dialogflow context translates into the current action.
* @example
* const app = new DialogflowApp({request: request, response: response});
* function responseHandler (app) {
* const intent = app.getIntent();
* switch (intent) {
* case WELCOME_INTENT:
* app.ask('Welcome to action snippets! Say a number.');
* break;
* case NUMBER_INTENT:
* const number = app.getArgument(NUMBER_ARGUMENT);
* app.tell('You said ' + number);
* break;
* }
* }
* app.handleRequest(responseHandler);
* @return {string} Intent id or null if no value (action name).
* @dialogflow
*/
getIntent(): string;
/**
* Get the argument value by name from the current intent. If the argument
* is included in originalRequest, and is not a text argument, the entire
* argument object is returned.
* Note: If incoming request is using an API version under 2 (e.g. 'v1'),
* the argument object will be in Proto2 format (snake_case, etc).
* @example
* const app = new DialogflowApp({request: request, response: response});
* const WELCOME_INTENT = 'input.welcome';
* const NUMBER_INTENT = 'input.number';
* function welcomeIntent (app) {
* app.ask('Welcome to action snippets! Say a number.');
* }
* function numberIntent (app) {
* const number = app.getArgument(NUMBER_ARGUMENT);
* app.tell('You said ' + number);
* }
* const actionMap = new Map();
* actionMap.set(WELCOME_INTENT, welcomeIntent);
* actionMap.set(NUMBER_INTENT, numberIntent);
* app.handleRequest(actionMap);
* @param {string} argName Name of the argument.
* @return {Object} Argument value matching argName
* or null if no matching argument.
* @dialogflow
*/
getArgument(argName: string): any;
/**
* Get the context argument value by name from the current intent. Context
* arguments include parameters collected in previous intents during the
* lifespan of the given context. If the context argument has an original
* value, usually representing the underlying entity value, that will be given
* as part of the return object.
* @example
* const app = new DialogflowApp({request: request, response: response});
* const WELCOME_INTENT = 'input.welcome';
* const NUMBER_INTENT = 'input.number';
* const OUT_CONTEXT = 'output_context';
* const NUMBER_ARG = 'myNumberArg';
* function welcomeIntent (app) {
* const parameters = {};
* parameters[NUMBER_ARG] = '42';
* app.setContext(OUT_CONTEXT, 1, parameters);
* app.ask('Welcome to action snippets! Ask me for your number.');
* }
* function numberIntent (app) {
* const number = app.getContextArgument(OUT_CONTEXT, NUMBER_ARG);
* // number === { value: 42 }
* app.tell('Your number is ' + number.value);
* }
* const actionMap = new Map();
* actionMap.set(WELCOME_INTENT, welcomeIntent);
* actionMap.set(NUMBER_INTENT, numberIntent);
* app.handleRequest(actionMap);
* @param {string} contextName Name of the context.
* @param {string} argName Name of the argument.
* @return {Object} Object containing value property and optional original
* property matching context argument. Null if no matching argument.
* @dialogflow
*/
getContextArgument(contextName: string, argName: string): any;
/**
* Returns the RichResponse constructed in Dialogflow response builder.
* @example
* const app = new App({request: req, response: res});
* function tellFact (app) {
* let fact = 'Google was founded in 1998';
* if (app.hasSurfaceCapability(app.SurfaceCapabilities.SCREEN_OUTPUT)) {
* app.ask(app.getIncomingRichResponse().addSimpleResponse('Here\'s a ' +
* 'fact for you. ' + fact + ' Which one do you want to hear about ' +
* 'next, Google\'s history or headquarters?'));
* } else {
* app.ask('Here\'s a fact for you. ' + fact + ' Which one ' +
* 'do you want to hear about next, Google\'s history or headquarters?');
* }
* }
* const actionMap = new Map();
* actionMap.set('tell.fact', tellFact);
* app.handleRequest(actionMap);
* @return {RichResponse} RichResponse created in Dialogflow. If no RichResponse was
* created, an empty RichResponse is returned.
* @dialogflow
*/
getIncomingRichResponse(): RichResponse;
/**
* Returns the List constructed in Dialogflow response builder.
* @example
* const app = new App({request: req, response: res});
* function pickOption (app) {
* if (app.hasSurfaceCapability(app.SurfaceCapabilities.SCREEN_OUTPUT)) {
* app.askWithList('Which of these looks good?',
* app.getIncomingList().addItems(
* app.buildOptionItem('another_choice', ['Another choice']).
* setTitle('Another choice')));
* } else {
* app.ask('What would you like?');
* }
* }
* const actionMap = new Map();
* actionMap.set('pick.option', pickOption);
* app.handleRequest(actionMap);
* @return {List} List created in Dialogflow. If no List was created, an empty
* List is returned.
* @dialogflow
*/
getIncomingList(): List;
/**
* Returns the Carousel constructed in Dialogflow response builder.
* @example
* const app = new App({request: req, response: res});
* function pickOption (app) {
* if (app.hasSurfaceCapability(app.SurfaceCapabilities.SCREEN_OUTPUT)) {
* app.askWithCarousel('Which of these looks good?',
* app.getIncomingCarousel().addItems(
* app.buildOptionItem('another_choice', ['Another choice']).
* setTitle('Another choice').setDescription('Choose me!')));
* } else {
* app.ask('What would you like?');
* }
* }
* const actionMap = new Map();
* actionMap.set('pick.option', pickOption);
* app.handleRequest(actionMap);
* @return {Carousel} Carousel created in Dialogflow. If no Carousel was created,
* an empty Carousel is returned.
* @dialogflow
*/
getIncomingCarousel(): Carousel;
/**
* Returns the option key user chose from options response.
* @example
* const app = new App({request: req, response: res});
* function pickOption (app) {
* if (app.hasSurfaceCapability(app.SurfaceCapabilities.SCREEN_OUTPUT)) {
* app.askWithCarousel('Which of these looks good?',
* app.getIncomingCarousel().addItems(
* app.buildOptionItem('another_choice', ['Another choice']).
* setTitle('Another choice').setDescription('Choose me!')));
* } else {
* app.ask('What would you like?');
* }
* }
* function optionPicked (app) {
* app.ask('You picked ' + app.getSelectedOption());
* }
* const actionMap = new Map();
* actionMap.set('pick.option', pickOption);
* actionMap.set('option.picked', optionPicked);
* app.handleRequest(actionMap);
* @return {string} Option key of selected item. Null if no option selected or
* if current intent is not OPTION intent.
* @dialogflow
*/
getSelectedOption(): string;
/**
* Asks to collect the user's input.
* {@link https://developers.google.com/actions/policies/general-policies#user_experience|The guidelines when prompting the user for a response must be followed at all times}.
* NOTE: Due to a bug, if you specify the no-input prompts,
* the mic is closed after the 3rd prompt, so you should use the 3rd prompt
* for a bye message until the bug is fixed.
* @example
* const app = new DialogflowApp({request: request, response: response});
* const WELCOME_INTENT = 'input.welcome';
* const NUMBER_INTENT = 'input.number';
* function welcomeIntent (app) {
* app.ask('Welcome to action snippets! Say a number.',
* ['Say any number', 'Pick a number', 'We can stop here. See you soon.']);
* }
* function numberIntent (app) {
* const number = app.getArgument(NUMBER_ARGUMENT);
* app.tell('You said ' + number);
* }
* const actionMap = new Map();
* actionMap.set(WELCOME_INTENT, welcomeIntent);
* actionMap.set(NUMBER_INTENT, numberIntent);
* app.handleRequest(actionMap);
* @param {string|SimpleResponse|RichResponse} inputPrompt The input prompt
* response.
* @param {Array<string>=} noInputs Array of re-prompts when the user does not respond (max 3).
* @return {AskTellResponse} HTTP response.
* @dialogflow
*/
ask(inputPrompt: string | SimpleResponse | RichResponse, noInputs?: string[]): AskTellResponse;
/**
* Asks to collect the user's input with a list.
* @example
* const app = new DialogflowApp({request, response});
* const WELCOME_INTENT = 'input.welcome';
* const OPTION_INTENT = 'option.select';
* function welcomeIntent (app) {
* app.askWithList('Which of these looks good?',
* app.buildList('List title')
* .addItems([
* app.buildOptionItem(SELECTION_KEY_ONE,
* ['synonym of KEY_ONE 1', 'synonym of KEY_ONE 2'])
* .setTitle('Title of First List Item'),
* app.buildOptionItem(SELECTION_KEY_TWO,
* ['synonym of KEY_TWO 1', 'synonym of KEY_TWO 2'])
* .setTitle('Title of Second List Item'),
* ]));
* }
* function optionIntent (app) {
* if (app.getSelectedOption() === SELECTION_KEY_ONE) {
* app.tell('Number one is a great choice!');
* } else {
* app.tell('Number two is a great choice!');
* }
* }
* const actionMap = new Map();
* actionMap.set(WELCOME_INTENT, welcomeIntent);
* actionMap.set(OPTION_INTENT, optionIntent);
* app.handleRequest(actionMap);
* @param {string|RichResponse|SimpleResponse} inputPrompt The input prompt
* response.
* @param {List} list List built with {@link AssistantApp#buildList|buildList}.
* @return {AskTellResponse} HTTP response.
* @dialogflow
*/
askWithList(inputPrompt: string | RichResponse | SimpleResponse, list: List): AskTellResponse;
/**
* Asks to collect the user's input with a carousel.
* @example
* const app = new DialogflowApp({request, response});
* const WELCOME_INTENT = 'input.welcome';
* const OPTION_INTENT = 'option.select';
* function welcomeIntent (app) {
* app.askWithCarousel('Which of these looks good?',
* app.buildCarousel()
* .addItems([
* app.buildOptionItem(SELECTION_KEY_ONE,
* ['synonym of KEY_ONE 1', 'synonym of KEY_ONE 2'])
* .setTitle('Number one'),
* app.buildOptionItem(SELECTION_KEY_TWO,
* ['synonym of KEY_TWO 1', 'synonym of KEY_TWO 2'])
* .setTitle('Number two'),
* ]));
* }
* function optionIntent (app) {
* if (app.getSelectedOption() === SELECTION_KEY_ONE) {
* app.tell('Number one is a great choice!');
* } else {
* app.tell('Number two is a great choice!');
* }
* }
* const actionMap = new Map();
* actionMap.set(WELCOME_INTENT, welcomeIntent);
* actionMap.set(OPTION_INTENT, optionIntent);
* app.handleRequest(actionMap);
* @param {string|RichResponse|SimpleResponse} inputPrompt The input prompt
* response.
* @param {Carousel} carousel Carousel built with
* {@link AssistantApp#buildCarousel|buildCarousel}.
* @return {AskTellResponse} HTTP response.
* @dialogflow
*/
askWithCarousel(inputPrompt: string | RichResponse | SimpleResponse, carousel: Carousel): AskTellResponse;
/**
* Tells the Assistant to render the speech response and close the mic.
* @example
* const app = new DialogflowApp({request: request, response: response});
* const WELCOME_INTENT = 'input.welcome';
* const NUMBER_INTENT = 'input.number';
* function welcomeIntent (app) {
* app.ask('Welcome to action snippets! Say a number.');
* }
* function numberIntent (app) {
* const number = app.getArgument(NUMBER_ARGUMENT);
* app.tell('You said ' + number);
* }
* const actionMap = new Map();
* actionMap.set(WELCOME_INTENT, welcomeIntent);
* actionMap.set(NUMBER_INTENT, numberIntent);
* app.handleRequest(actionMap);
* @param {string|SimpleResponse|RichResponse} speechResponse Final response.
* Spoken response can be SSML.
* @return {AskTellResponse} The response that is sent back to Assistant.
* @dialogflow
*/
tell(speechResponse: string | SimpleResponse | RichResponse): AskTellResponse;
/**
* Set a new context for the current intent.
* @example
* const app = new DialogflowApp({request: request, response: response});
* const CONTEXT_NUMBER = 'number';
* const NUMBER_ARGUMENT = 'myNumber';
* function welcomeIntent (app) {
* app.setContext(CONTEXT_NUMBER);
* app.ask('Welcome to action snippets! Say a number.');
* }
* function numberIntent (app) {
* const number = app.getArgument(NUMBER_ARGUMENT);
* app.tell('You said ' + number);
* }
* const actionMap = new Map();
* actionMap.set(WELCOME_INTENT, welcomeIntent);
* actionMap.set(NUMBER_INTENT, numberIntent);
* app.handleRequest(actionMap);
* @param {string} name Name of the context. Dialogflow converts to lowercase.
* @param {number} [lifespan=1] Context lifespan.
* @param {Object=} parameters Context JSON parameters.
* @return {null|undefined} Null if the context name is not defined.
* @dialogflow
*/
setContext(name: string, lifespan?: number, parameters?: any): any | any;
/**
* Returns the incoming contexts for this intent.
* @example
* const app = new DialogflowApp({request: request, response: response});
* const CONTEXT_NUMBER = 'number';
* const NUMBER_ARGUMENT = 'myNumber';
* function welcomeIntent (app) {
* app.setContext(CONTEXT_NUMBER);
* app.ask('Welcome to action snippets! Say a number.');
* }
* function numberIntent (app) {
* let contexts = app.getContexts();
* // contexts === [{
* // name: 'number',
* // lifespan: 0,
* // parameters: {
* // myNumber: '23',
* // myNumber.original: '23'
* // }
* // }]
* const number = app.getArgument(NUMBER_ARGUMENT);
* app.tell('You said ' + number);
* }
* const actionMap = new Map();
* actionMap.set(WELCOME_INTENT, welcomeIntent);
* actionMap.set(NUMBER_INTENT, numberIntent);
* app.handleRequest(actionMap);
* @return {Context[]} Empty if no active contexts.
* @dialogflow
*/
getContexts(): (Context)[];
/**
* Returns the incoming context by name for this intent.
* @example
* const app = new DialogflowApp({request: request, response: response});
* const CONTEXT_NUMBER = 'number';
* const NUMBER_ARGUMENT = 'myNumber';
* function welcomeIntent (app) {
* app.setContext(CONTEXT_NUMBER);
* app.ask('Welcome to action snippets! Say a number.');
* }
* function numberIntent (app) {
* let context = app.getContext(CONTEXT_NUMBER);
* // context === {
* // name: 'number',
* // lifespan: 0,
* // parameters: {
* // myNumber: '23',
* // myNumber.original: '23'
* // }
* // }
* const number = app.getArgument(NUMBER_ARGUMENT);
* app.tell('You said ' + number);
* }
* const actionMap = new Map();
* actionMap.set(WELCOME_INTENT, welcomeIntent);
* actionMap.set(NUMBER_INTENT, numberIntent);
* app.handleRequest(actionMap);
* @param {string} name The name of the Context to retrieve.
* @return {Object} Context value matching name
* or null if no matching context.
* @dialogflow
*/
getContext(name: string): any;
/**
* Gets the user's raw input query.
* @example
* const app = new DialogflowApp({request: request, response: response});
* app.tell('You said ' + app.getRawInput());
* @return {string} User's raw query or null if no value.
* @dialogflow
*/
getRawInput(): string;
}
/**
* Dialogflow {@link https://dialogflow.com/docs/concept-contexts|Context}.
* @typedef {object} Context
* @property {string} name - Full name of the context.
* @property {Object} parameters - Parameters carried within this context.
* See {@link https://dialogflow.com/docs/concept-actions#section-extracting-values-from-contexts|here}.
* @property {number} lifespan - Remaining number of intents
*/
declare type Context = {
name: string;
parameters: any;
lifespan: number;
};

View File

@ -0,0 +1,360 @@
/**
* Simple Response type.
* @typedef {object} SimpleResponse
* @property {string} speech - Speech to be spoken to user. SSML allowed.
* @property {string} [displayText] - Optional text to be shown to user
*/
declare type SimpleResponse = {
speech: string;
displayText: string;
};
/**
* Suggestions to show with response.
* @typedef {object} Suggestion
* @property {string} title - Text of the suggestion.
*/
declare type Suggestion = {
title: string;
};
/**
* Link Out Suggestion. Used in rich response as a suggestion chip which, when
* selected, links out to external URL.
* @typedef {object} LinkOutSuggestion
* @property {string} title - Text shown on the suggestion chip.
* @property {string} url - String URL to open.
*/
declare type LinkOutSuggestion = {
title: string;
url: string;
};
/**
* Image type shown on visual elements.
* @typedef {object} Image
* @property {string} url - Image source URL.
* @property {string} accessibilityText - Text to replace for image for
* accessibility.
* @property {number} width - Width of the image.
* @property {number} height - Height of the image.
*/
declare type Image = {
url: string;
accessibilityText: string;
width: number;
height: number;
};
/**
* Basic Card Button. Shown below basic cards. Open a URL when selected.
* @typedef {object} Button
* @property {string} title - Text shown on the button.
* @property {Object} openUrlAction - Action to take when selected.
* @property {string} openUrlAction.url - String URL to open.
*/
declare type Button = {
title: string;
openUrlAction: any;
"openUrlAction.url": string;
};
/**
* Option info. Provides unique identifier for a given OptionItem.
* @typedef {object} OptionInfo
* @property {string} key - Unique string ID for this option.
* @property {Array<string>} synonyms - Synonyms that can be used by the user
* to indicate this option if they do not use the key.
*/
declare type OptionInfo = {
key: string;
synonyms: string[];
};
/**
* Class for initializing and constructing Rich Responses with chainable interface.
*/
declare class RichResponse {
constructor(richResponse?: RichResponse);
/**
* Ordered list of either SimpleResponse objects or BasicCard objects.
* First item must be SimpleResponse. There can be at most one card.
* @type {Array<SimpleResponse|BasicCard>}
*/
items: (SimpleResponse | BasicCard)[];
/**
* Ordered list of text suggestions to display. Optional.
* @type {Array<Suggestion>}
*/
suggestions: (Suggestion)[];
/**
* Link Out Suggestion chip for this rich response. Optional.
* @type {LinkOutSuggestion}
*/
linkOutSuggestion: LinkOutSuggestion;
/**
* Adds a SimpleResponse to list of items.
* @param {string|SimpleResponse} simpleResponse Simple response to present to
* user. If just a string, display text will not be set.
* @return {RichResponse} Returns current constructed RichResponse.
*/
addSimpleResponse(simpleResponse: string | SimpleResponse): RichResponse;
/**
* Adds a BasicCard to list of items.
* @param {BasicCard} basicCard Basic card to include in response.
* @return {RichResponse} Returns current constructed RichResponse.
*/
addBasicCard(basicCard: BasicCard): RichResponse;
/**
* Adds a single suggestion or list of suggestions to list of items.
* @param {string|Array<string>} suggestions Either a single string suggestion
* or list of suggestions to add.
* @return {RichResponse} Returns current constructed RichResponse.
*/
addSuggestions(suggestions: string | string[]): RichResponse;
/**
* Returns true if the given suggestion text is valid to be added to the suggestion list. A valid
* text string is not longer than 25 characters.
* @param {string} suggestionText Text to validate as suggestion.
* @return {boolean} True if the text is valid, false otherwise.s
*/
isValidSuggestionText(suggestionText: string): boolean;
/**
* Sets the suggestion link for this rich response.
* @param {string} destinationName Name of the link out destination.
* @param {string} suggestionUrl - String URL to open when suggestion is used.
* @return {RichResponse} Returns current constructed RichResponse.
*/
addSuggestionLink(destinationName: string, suggestionUrl: string): RichResponse;
/**
* Adds an order update to this response. Use after a successful transaction
* decision to confirm the order.
* @param {OrderUpdate} orderUpdate OrderUpdate object to add.
* @return {RichResponse} Returns current constructed RichResponse.
*/
addOrderUpdate(orderUpdate: OrderUpdate): RichResponse;
}
/**
* Class for initializing and constructing Basic Cards with chainable interface.
*/
declare class BasicCard {
constructor(basicCard?: BasicCard);
/**
* Title of the card. Optional.
* @type {string}
*/
title: string;
/**
* Body text to show on the card. Required, unless image is present.
* @type {string}
*/
formattedText: string;
/**
* Subtitle of the card. Optional.
* @type {string}
*/
subtitle: string;
/**
* Image to show on the card. Optional.
* @type {Image}
*/
image: Image;
/**
* Ordered list of buttons to show below card. Optional.
* @type {Array<Button>}
*/
buttons: (Button)[];
/**
* Sets the title for this Basic Card.
* @param {string} title Title to show on card.
* @return {BasicCard} Returns current constructed BasicCard.
*/
setTitle(title: string): BasicCard;
/**
* Sets the subtitle for this Basic Card.
* @param {string} subtitle Subtitle to show on card.
* @return {BasicCard} Returns current constructed BasicCard.
*/
setSubtitle(subtitle: string): BasicCard;
/**
* Sets the body text for this Basic Card.
* @param {string} bodyText Body text to show on card.
* @return {BasicCard} Returns current constructed BasicCard.
*/
setBodyText(bodyText: string): BasicCard;
/**
* Sets the image for this Basic Card.
* @param {string} url Image source URL.
* @param {string} accessibilityText Text to replace for image for
* accessibility.
* @param {number=} width Width of the image.
* @param {number=} height Height of the image.
* @return {BasicCard} Returns current constructed BasicCard.
*/
setImage(url: string, accessibilityText: string, width?: number, height?: number): BasicCard;
/**
* Adds a button below card.
* @param {string} text Text to show on button.
* @param {string} url URL to open when button is selected.
* @return {BasicCard} Returns current constructed BasicCard.
*/
addButton(text: string, url: string): BasicCard;
}
/**
* Class for initializing and constructing Lists with chainable interface.
*/
declare class List {
constructor(list?: List | string | (OptionItem)[]);
/**
* Title of the list. Optional.
* @type {string}
*/
title: string;
/**
* List of 2-20 items to show in this list. Required.
* @type {Array<OptionItem>}
*/
items: (OptionItem)[];
/**
* Sets the title for this List.
* @param {string} title Title to show on list.
* @return {List} Returns current constructed List.
*/
setTitle(title: string): List;
/**
* Adds a single item or list of items to the list.
* @param {OptionItem|Array<OptionItem>} optionItems OptionItems to add.
* @return {List} Returns current constructed List.
*/
addItems(optionItems: OptionItem | (OptionItem)[]): List;
}
/**
* Class for initializing and constructing Carousel with chainable interface.
*/
declare class Carousel {
constructor(carousel?: Carousel | (OptionItem)[]);
/**
* List of 2-20 items to show in this carousel. Required.
* @type {Array<OptionItem>}
*/
items: (OptionItem)[];
/**
* Adds a single item or list of items to the carousel.
* @param {OptionItem|Array<OptionItem>} optionItems OptionItems to add.
* @return {Carousel} Returns current constructed Carousel.
*/
addItems(optionItems: OptionItem | (OptionItem)[]): Carousel;
}
/**
* Class for initializing and constructing Option Items with chainable interface.
*/
declare class OptionItem {
constructor(optionItem?: OptionItem);
/**
* Option info of the option item. Required.
* @type {OptionInfo}
*/
optionInfo: OptionInfo;
/**
* Title of the option item. Required.
* @type {string}
*/
title: string;
/**
* Description text of the item. Optional.
* @type {string}
*/
description: string;
/**
* Image to show on item. Optional.
* @type {Image}
*/
image: Image;
/**
* Sets the title for this Option Item.
* @param {string} title Title to show on item.
* @return {OptionItem} Returns current constructed OptionItem.
*/
setTitle(title: string): OptionItem;
/**
* Sets the description for this Option Item.
* @param {string} description Description to show on item.
* @return {OptionItem} Returns current constructed OptionItem.
*/
setDescription(description: string): OptionItem;
/**
* Sets the image for this Option Item.
* @param {string} url Image source URL.
* @param {string} accessibilityText Text to replace for image for
* accessibility.
* @param {number=} width Width of the image.
* @param {number=} height Height of the image.
* @return {OptionItem} Returns current constructed OptionItem.
*/
setImage(url: string, accessibilityText: string, width?: number, height?: number): OptionItem;
/**
* Sets the key for the OptionInfo of this Option Item. This will be returned
* as an argument in the resulting actions.intent.OPTION intent.
* @param {string} key Key to uniquely identify this item.
* @return {OptionItem} Returns current constructed OptionItem.
*/
setKey(key: string): OptionItem;
/**
* Adds a single synonym or list of synonyms to item.
* @param {string|Array<string>} synonyms Either a single string synonyms
* or list of synonyms to add.
* @return {OptionItem} Returns current constructed OptionItem.
*/
addSynonyms(synonyms: string | string[]): OptionItem;
}
/**
* Check if given text contains SSML.
* @param {string} text Text to check.
* @return {boolean} True if text contains SSML, false otherwise.
*/
declare function isSsml(text: string): boolean;

View File

@ -0,0 +1,737 @@
/**
* Amount type.
* @typedef {object} Amount
* @property {string} currencyCode - Currency code of price.
* @property {number} units - Unit count of price.
* @property {number} [nanos] - Partial unit count of price.
*/
declare type Amount = {
currencyCode: string;
units: number;
nanos: number;
};
/**
* Price type.
* @typedef {object} Price
* @property {string} type - One of Transaction.PriceType.
* @property {Amount} amount
*/
declare type Price = {
type: string;
amount: Amount;
};
/**
* Order rejection info.
* @typedef {object} RejectionInfo
* @property {string} type - One of Transaction.RejectionType.
* @property {string} reason - Reason for the order rejection.
*/
declare type RejectionInfo = {
type: string;
reason: string;
};
/**
* Order receipt info.
* @typedef {object} ReceiptInfo
* @property {string} confirmedActionOrderId - Action provided order ID. Used
* when the order has been received by the integrator.
*/
declare type ReceiptInfo = {
confirmedActionOrderId: string;
};
/**
* Order cancellation info.
* @typedef {object} CancellationInfo
* @property {string} reason - Reason for the cancellation.
*/
declare type CancellationInfo = {
reason: string;
};
/**
* UTC timestamp.
* @typedef {object} Timestamp
* @property {number} seconds - Seconds since Unix epoch.
* @property {number} [nanos] - Partial seconds since Unix epoch.
*/
declare type Timestamp = {
seconds: number;
nanos: number;
};
/**
* Order transit info.
* @typedef {object} TransitInfo
* @property {Timestamp} updatedTime - UTC timestamp of the transit update.
*/
declare type TransitInfo = {
updatedTime: Timestamp;
};
/**
* Order fulfillment info.
* @typedef {object} FulfillmentInfo
* @property {Timestamp} deliveryTime - UTC timestamp of the fulfillment update.
*/
declare type FulfillmentInfo = {
deliveryTime: Timestamp;
};
/**
* Order return info.
* @typedef {object} ReturnInfo
* @property {string} reason - Reason for the return.
*/
declare type ReturnInfo = {
reason: string;
};
/**
* Transaction config for transactions not involving a Google provided
* payment instrument.
* @typedef {object} ActionPaymentTransactionConfig
* @property {boolean} deliveryAddressRequired - True if delivery address is
* required for the transaction.
* @property {boolean} type - One of Transactions.PaymentType.
* @property {string} displayName - The name of the instrument displayed on
* receipt. For example, for card payment, could be "VISA-1234".
* @property {CustomerInfoOptions=} customerInfoOptions
*/
declare type ActionPaymentTransactionConfig = {
deliveryAddressRequired: boolean;
type: boolean;
displayName: string;
customerInfoOptions: CustomerInfoOptions;
};
/**
* Transaction config for transactions involving a Google provided payment
* instrument.
* @typedef {object} GooglePaymentTransactionConfig
* @property {boolean} deliveryAddressRequired - True if delivery address is
* required for the transaction.
* @property {Object} tokenizationParameters - Tokenization parameters provided
* by payment gateway.
* @property {Array<string>} cardNetworks - List of accepted card networks.
* Must be any number of Transactions.CardNetwork.
* @property {boolean} prepaidCardDisallowed - True if prepaid cards are not
* allowed for transaction.
* @property {CustomerInfoOptions=} customerInfoOptions
*/
declare type GooglePaymentTransactionConfig = {
deliveryAddressRequired: boolean;
tokenizationParameters: any;
cardNetworks: string[];
prepaidCardDisallowed: boolean;
customerInfoOptions: CustomerInfoOptions;
};
/**
* Customer information requested as part of the transaction
* @typedef {object} CustomerInfoOptions
* @property {Array<string>} customerInfoProperties - one of
* Transactions.CustomerInfoProperties
*/
declare type CustomerInfoOptions = {
customerInfoProperties: string[];
};
/**
* Postal address type.
* @typedef {object} PostalAddress
* @property {string} regionCode
* @property {string} languageCode
* @property {string} postalCode
* @property {string} administrativeArea
* @property {string} locality
* @property {Array<string>} addressLines
* @property {string} recipients
*/
declare type PostalAddress = {
regionCode: string;
languageCode: string;
postalCode: string;
administrativeArea: string;
locality: string;
addressLines: string[];
recipients: string;
};
/**
* Generic Location type.
* @typedef {object} Location
* @property {PostalAddress} postalAddress
* @property {string} phoneNumber
* @property {string} notes
*/
declare type Location = {
postalAddress: PostalAddress;
phoneNumber: string;
notes: string;
};
/**
* Decision and order information returned when calling getTransactionDecision().
* @typedef {object} TransactionDecision
* @property {string} userDecision - One of Transactions.ConfirmationDecision.
* @property {Object} checkResult
* @property {string} checkResult.resultType - One of Transactions.ResultType.
* @property {Object} order
* @property {Order} order.finalOrder - The proposed order used in the transaction
* decision.
* @property {string} order.googleOrderId - Order ID assigned by Google.
* @property {string} order.actionOrderId - User visible order ID set in proposed
* order.
* @property {Object} order.orderDate
* @property {string} order.orderDate.seconds
* @property {number} order.orderDate.nanos
* @property {Object} order.paymentInfo
* @property {Object} order.customerInfo
* @property {string} order.customerInfo.email - Customer email.
* @property {Location} deliveryAddress - The delivery address if user
* requested. Will appear if userDecision is
* Transactions.DELIVERY_ADDRESS_UPDATED.
*/
declare type TransactionDecision = {
userDecision: string;
checkResult: any;
"checkResult.resultType": string;
order: any;
"order.finalOrder": Order;
"order.googleOrderId": string;
"order.actionOrderId": string;
"order.orderDate": any;
"order.orderDate.seconds": string;
"order.orderDate.nanos": number;
"order.paymentInfo": any;
"order.customerInfo": any;
"order.customerInfo.email": string;
deliveryAddress: Location;
};
/**
* Values related to supporting transactions.
* @readonly
* @typedef {object} TransactionValues
* @property {any} CardNetwork - List of transaction card networks available when paying with Google.
* @property {any} ItemType - List of possible item types.
* @property {any} PriceType - List of price types.
* @property {any} PaymentType - List of possible item types.
* @property {any} CustomerInfoProperties - List of customer information properties that can be requested.
* @property {any} ConfirmationDecision - List of possible order confirmation user decisions
* @property {any} OrderState - List of possible order states.
* @property {any} OrderAction - List of possible actions to take on the order.
* @property {any} RejectionType - List of possible types of order rejection.
* @property {any} OrderStateInfo - List of possible order state objects.
* @property {any} ResultType - List of possible order transaction requirements check result types.
* @property {any} DeliveryAddressDecision - List of possible user decisions to give delivery address.
* @property {any} LocationType - List of possible order location types.
* @property {any} TimeType - List of possible order time types.
*/
declare type TransactionValues = {
CardNetwork: any;
ItemType: any;
PriceType: any;
PaymentType: any;
CustomerInfoProperties: any;
ConfirmationDecision: any;
OrderState: any;
OrderAction: any;
RejectionType: any;
OrderStateInfo: any;
ResultType: any;
DeliveryAddressDecision: any;
LocationType: any;
TimeType: any;
};
/**
* List of transaction card networks available when paying with Google.
* @readonly
* @enum {string}
*/
declare const enum CardNetwork {
/**
* Unspecified.
*/
UNSPECIFIED,
/**
* American Express.
*/
AMEX,
/**
* Discover.
*/
DISCOVER,
/**
* Master Card.
*/
MASTERCARD,
/**
* Visa.
*/
VISA,
/**
* JCB.
*/
JCB,
}
/**
* Valid keys for the TransactionValues.OrderStateInfo enum.
* @readonly
* @enum {string}
*/
declare const enum reverseOrderStateInfo {
}
/**
* Class for initializing and constructing Order with chainable interface.
*/
declare class Order {
constructor(orderId: string);
/**
* ID for the order. Required.
* @type {string}
*/
id: string;
/**
* Cart for the order.
* @type {Cart}
*/
cart: Cart;
/**
* Items not held in the order cart.
* @type {Array<LineItem>}
*/
otherItems: (LineItem)[];
/**
* Image for the order.
* @type {Image}
*/
image: Image;
/**
* TOS for the order.
* @type {string}
*/
termsOfServiceUrl: string;
/**
* Total price for the order.
* @type {Price}
*/
totalPrice: Price;
/**
* Extensions for this order. Used for vertical-specific order attributes,
* like times and locations.
* @type {Object}
*/
extension: any;
/**
* Set the cart for this order.
* @param {Cart} cart Cart for this order.
* @return {Order} Returns current constructed Order.
*/
setCart(cart: Cart): Order;
/**
* Adds a single item or list of items to the non-cart items list.
* @param {LineItem|Array<LineItem>} items Line Items to add.
* @return {Order} Returns current constructed Order.
*/
addOtherItems(items: LineItem | (LineItem)[]): Order;
/**
* Sets the image for this order.
* @param {string} url Image source URL.
* @param {string} accessibilityText Text to replace for image for
* accessibility.
* @param {number=} width Width of the image.
* @param {number=} height Height of the image.
* @return {Order} Returns current constructed Order.
*/
setImage(url: string, accessibilityText: string, width?: number, height?: number): Order;
/**
* Set the TOS for this order.
* @param {string} url String URL of the TOS.
* @return {Order} Returns current constructed Order.
*/
setTermsOfService(url: string): Order;
/**
* Sets the total price for this order.
* @param {string} priceType One of TransactionValues.PriceType.
* @param {string} currencyCode Currency code of price.
* @param {number} units Unit count of price.
* @param {number=} nanos Partial unit count of price.
* @return {Order} Returns current constructed Order.
*/
setTotalPrice(priceType: string, currencyCode: string, units: number, nanos?: number): Order;
/**
* Adds an associated location to the order. Up to 2 locations can be added.
* @param {string} type One of TransactionValues.LocationType.
* @param {Location} location Location to add.
* @return {Order} Returns current constructed Order.
*/
addLocation(type: string, location: Location): Order;
/**
* Sets an associated time to the order.
* @param {string} type One of TransactionValues.TimeType.
* @param {string} time Time to add. Time should be ISO 8601 representation
* of time value. Could be date, datetime, or duration.
* @return {Order} Returns current constructed Order.
*/
setTime(type: string, time: string): Order;
}
/**
* Class for initializing and constructing Cart with chainable interface.
*/
declare class Cart {
constructor(cartId?: string);
/**
* ID for the cart. Optional.
* @type {string}
*/
id: string;
/**
* Merchant providing the cart.
* @type {Object}
*/
merchant: any;
/**
* Optional notes about the cart.
* @type {string}
*/
notes: string;
/**
* Items held in the order cart.
* @type {Array<LineItem>}
*/
lineItems: (LineItem)[];
/**
* Non-line items.
* @type {Array<LineItem>}
*/
otherItems: (LineItem)[];
/**
* Set the merchant for this cart.
* @param {string} id Merchant ID.
* @param {string} name Name of the merchant.
* @return {Cart} Returns current constructed Cart.
*/
setMerchant(id: string, name: string): Cart;
/**
* Set the notes for this cart.
* @param {string} notes Notes.
* @return {Cart} Returns current constructed Cart.
*/
setNotes(notes: string): Cart;
/**
* Adds a single item or list of items to the cart.
* @param {LineItem|Array<LineItem>} items Line Items to add.
* @return {Cart} Returns current constructed Cart.
*/
addLineItems(items: LineItem | (LineItem)[]): Cart;
/**
* Adds a single item or list of items to the non-items list of this cart.
* @param {LineItem|Array<LineItem>} items Line Items to add.
* @return {Cart} Returns current constructed Cart.
*/
addOtherItems(items: LineItem | (LineItem)[]): Cart;
}
/**
* Class for initializing and constructing LineItem with chainable interface.
*/
declare class LineItem {
constructor(lineItemId: string, name: string);
/**
* Item ID.
* @type {string}
*/
id: string;
/**
* Name of the item.
* @type {string}
*/
name: string;
/**
* Item price.
* @type {Price}
*/
price: Price;
/**
* Sublines for current item. Only valid if item type is REGULAR.
* @type {Array<string|LineItem>}
*/
subLines: (string | LineItem)[];
/**
* Image of the item.
* @type {Image}
*/
image: Image;
/**
* Type of the item. One of TransactionValues.ItemType.
* @type {string}
*/
type: string;
/**
* Quantity of the item.
* @type {number}
*/
quantity: number;
/**
* Description for the item.
* @type {string}
*/
description: string;
/**
* Offer ID for the item.
* @type {string}
*/
offerId: string;
/**
* Adds a single item or list of items or notes to the sublines. Only valid
* if item type is REGULAR.
* @param {string|LineItem|Array<string|LineItem>} items Sublines to add.
* @return {LineItem} Returns current constructed LineItem.
*/
addSublines(items: string | LineItem | (string | LineItem)[]): LineItem;
/**
* Sets the image for this item.
* @param {string} url Image source URL.
* @param {string} accessibilityText Text to replace for image for
* accessibility.
* @param {number=} width Width of the image.
* @param {number=} height Height of the image.
* @return {LineItem} Returns current constructed LineItem.
*/
setImage(url: string, accessibilityText: string, width?: number, height?: number): LineItem;
/**
* Sets the price of this item.
* @param {string} priceType One of TransactionValues.PriceType.
* @param {string} currencyCode Currency code of price.
* @param {number} units Unit count of price.
* @param {number=} nanos Partial unit count of price.
* @return {LineItem} Returns current constructed LineItem.
*/
setPrice(priceType: string, currencyCode: string, units: number, nanos?: number): LineItem;
/**
* Set the type of the item.
* @param {string} type Type of the item. One of TransactionValues.ItemType.
* @return {LineItem} Returns current constructed LineItem.
*/
setType(type: string): LineItem;
/**
* Set the quantity of the item.
* @param {number} quantity Quantity of the item.
* @return {LineItem} Returns current constructed LineItem.
*/
setQuantity(quantity: number): LineItem;
/**
* Set the description of the item.
* @param {string} description Description of the item.
* @return {LineItem} Returns current constructed LineItem.
*/
setDescription(description: string): LineItem;
/**
* Set the Offer ID of the item.
* @param {string} offerId Offer ID of the item.
* @return {LineItem} Returns current constructed LineItem.
*/
setOfferId(offerId: string): LineItem;
}
/**
* Class for initializing and constructing OrderUpdate with chainable interface.
*/
declare class OrderUpdate {
constructor(orderId: string, isGoogleOrderId: boolean);
/**
* Google provided identifier of the order.
* @type {string}
*/
googleOrderId: string;
/**
* App provided identifier of the order.
* @type {string}
*/
actionOrderId: string;
/**
* State of the order.
* @type {Object}
*/
orderState: any;
/**
* Updates for items in the order. Mapped by item id to state or price.
* @type {Object}
*/
lineItemUpdates: any;
/**
* UTC timestamp of the order update.
* @type {Timestamp}
*/
updateTime: Timestamp;
/**
* Actionable items presented to the user to manage the order.
* @type {Object}
*/
orderManagementActions: any;
/**
* Notification content to the user for the order update.
* @type {Object}
*/
userNotification: any;
/**
* Updated total price of the order.
* @type {Price}
*/
totalPrice: Price;
/**
* Set the Google provided order ID of the order.
* @param {string} orderId Google provided order ID.
* @return {OrderUpdate} Returns current constructed OrderUpdate.
*/
setGoogleOrderId(orderId: string): OrderUpdate;
/**
* Set the Action provided order ID of the order.
* @param {string} orderId Action provided order ID.
* @return {OrderUpdate} Returns current constructed OrderUpdate.
*/
setActionOrderId(orderId: string): OrderUpdate;
/**
* Set the state of the order.
* @param {string} state One of TransactionValues.OrderState.
* @param {string} label Label for the order state.
* @return {OrderUpdate} Returns current constructed OrderUpdate.
*/
setOrderState(state: string, label: string): OrderUpdate;
/**
* Set the update time of the order.
* @param {number} seconds Seconds since Unix epoch.
* @param {number=} nanos Partial time units.
* @return {OrderUpdate} Returns current constructed OrderUpdate.
*/
setUpdateTime(seconds: number, nanos?: number): OrderUpdate;
/**
* Set the user notification content of the order update.
* @param {string} title Title of the notification.
* @param {Object} text Text of the notification.
* @return {OrderUpdate} Returns current constructed OrderUpdate.
*/
setUserNotification(title: string, text: any): OrderUpdate;
/**
* Sets the total price for this order.
* @param {string} priceType One of TransactionValues.PriceType.
* @param {string} currencyCode Currency code of price.
* @param {number} units Unit count of price.
* @param {number=} nanos Partial unit count of price.
* @return {OrderUpdate} Returns current constructed OrderUpdate.
*/
setTotalPrice(priceType: string, currencyCode: string, units: number, nanos?: number): OrderUpdate;
/**
* Adds an actionable item for the user to manage the order.
* @param {string} type One of TransactionValues.OrderActions.
* @param {string} label Button label.
* @param {string} url URL to open when button is clicked.
* @return {OrderUpdate} Returns current constructed OrderUpdate.
*/
addOrderManagementAction(type: string, label: string, url: string): OrderUpdate;
/**
* Adds a single price update for a particular line item in the order.
* @param {string} itemId Line item ID for the order item updated.
* @param {string} priceType One of TransactionValues.PriceType.
* @param {string} currencyCode Currency code of new price.
* @param {number} units Unit count of new price.
* @param {number=} nanos Partial unit count of new price.
* @param {string=} reason Reason for the price change. Required unless a
* reason for this line item change was already declared in
* addLineItemStateUpdate.
* @return {OrderUpdate} Returns current constructed OrderUpdate.
*/
addLineItemPriceUpdate(itemId: string, priceType: string, currencyCode: string, units: number, nanos?: number, reason?: string): OrderUpdate;
/**
* Adds a single state update for a particular line item in the order.
* @param {string} itemId Line item ID for the order item updated.
* @param {string} state One of TransactionValues.OrderState.
* @param {string} label Label for the new item state.
* @param {string=} reason Reason for the price change. This will overwrite
* any reason given in addLineitemPriceUpdate.
* @return {OrderUpdate} Returns current constructed OrderUpdate.
*/
addLineItemStateUpdate(itemId: string, state: string, label: string, reason?: string): OrderUpdate;
/**
* Sets some extra information about the order. Takes an order update info
* type, and any accompanying data. This should only be called once per
* order update.
* @param {string} type One of TransactionValues.OrderStateInfo.
* @param {Object} data Proper Object matching the data necessary for the info
* type. For instance, for the TransactionValues.OrderStateInfo.RECEIPT info
* type, use the {@link ReceiptInfo} data type.
* @return {OrderUpdate} Returns current constructed OrderUpdate.
*/
setInfo(type: string, data: any): OrderUpdate;
}