Socket
Socket
Sign inDemoInstall

actions-on-google-ts

Package Overview
Dependencies
16
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1-12 to 1.2.1-0

484

build/actions-sdk-app.js

@@ -17,7 +17,2 @@ /**

/**
* This is the class that handles the converstaion API directly from Assistant, providing
* implementation for all the methods available in the API.
*/
'use strict';

@@ -43,3 +38,2 @@

var State = app.State;
var transformToSnakeCase = require('./utils/transform').transformToSnakeCase;
var transformToCamelCase = require('./utils/transform').transformToCamelCase;

@@ -61,19 +55,24 @@

/**
* Constructor for ActionsSdkApp object. To be used in the Actions SDK
* HTTP endpoint logic.
*
* @example
* const ActionsSdkApp = require('actions-on-google').ActionsSdkApp;
* const app = new ActionsSdkApp({request: request, response: response,
* sessionStarted:sessionStarted});
*
* @param {Object} options JSON configuration.
* @param {Object} options.request Express HTTP request object.
* @param {Object} options.response Express HTTP response object.
* @param {Function=} options.sessionStarted Function callback when session starts.
* @actionssdk
* This is the class that handles the conversation API directly from Assistant,
* providing implementation for all the methods available in the API.
*/
var ActionsSdkApp = function (_AssistantApp) {
_inherits(ActionsSdkApp, _AssistantApp);
/**
* Constructor for ActionsSdkApp object.
* To be used in the Actions SDK HTTP endpoint logic.
*
* @example
* const ActionsSdkApp = require('actions-on-google').ActionsSdkApp;
* const app = new ActionsSdkApp({request: request, response: response,
* sessionStarted:sessionStarted});
*
* @param {Object} options JSON configuration.
* @param {Object} options.request Express HTTP request object.
* @param {Object} options.response Express HTTP response object.
* @param {Function=} options.sessionStarted Function callback when session starts.
* @actionssdk
*/
function ActionsSdkApp(options) {

@@ -85,3 +84,5 @@ _classCallCheck(this, ActionsSdkApp);

// If request is from AoG and in Proto2 format, convert to Proto3.
var _this = _possibleConstructorReturn(this, (ActionsSdkApp.__proto__ || Object.getPrototypeOf(ActionsSdkApp)).call(this, options));
var _this = _possibleConstructorReturn(this, (ActionsSdkApp.__proto__ || Object.getPrototypeOf(ActionsSdkApp)).call(this, options, function () {
return _this.body_;
}));

@@ -136,7 +137,7 @@ if (_this.body_ && !_this.isNotApiVersionOne_()) {

if (!input) {
this.handleError_('Failed to get top Input.');
error('Failed to get top Input.');
return null;
}
if (!input.rawInputs || input.rawInputs.length === 0) {
this.handleError_('Missing user raw input');
error('Missing user raw input');
return null;

@@ -146,3 +147,3 @@ }

if (!rawInput.query) {
this.handleError_('Missing query for user raw input');
error('Missing query for user raw input');
return null;

@@ -177,251 +178,2 @@ }

/**
* Gets the {@link User} object.
* The user object contains information about the user, including
* a string identifier and personal information (requires requesting permissions,
* see {@link AssistantApp#askForPermissions|askForPermissions}).
*
* @example
* const app = new ActionsSdkApp({request: request, response: response});
* const userId = app.getUser().userId;
*
* @return {User} Null if no value.
* @actionssdk
*/
}, {
key: 'getUser',
value: function getUser() {
debug('getUser');
if (!this.body_.user) {
this.handleError_('No user object');
return null;
}
// User object includes original API properties
var user = {
userId: this.body_.user.userId,
user_id: this.body_.user.userId,
userName: this.body_.user.profile ? {
displayName: this.body_.user.profile.displayName,
givenName: this.body_.user.profile.givenName,
familyName: this.body_.user.profile.familyName
} : null,
profile: this.body_.user.profile,
accessToken: this.body_.user.accessToken,
access_token: this.body_.user.accessToken
};
return user;
}
/**
* If granted permission to device's location in previous intent, returns device's
* location (see {@link AssistantApp#askForPermissions|askForPermissoins}).
* If device info is unavailable, returns null.
*
* @example
* const app = new ActionsSdkApp({request: req, response: res});
* app.askForPermission("To get you a ride",
* app.SupportedPermissions.DEVICE_PRECISE_LOCATION);
* // ...
* // In response handler for subsequent intent:
* if (app.isPermissionGranted()) {
* sendCarTo(app.getDeviceLocation().coordinates);
* }
*
* @return {DeviceLocation} Null if location permission is not granted.
* @actionssdk
*/
}, {
key: 'getDeviceLocation',
value: function getDeviceLocation() {
debug('getDeviceLocation');
if (!this.body_.device || !this.body_.device.location) {
return null;
}
var deviceLocation = {
coordinates: this.body_.device.location.coordinates,
address: this.body_.device.location.formattedAddress,
zipCode: this.body_.device.location.zipCode,
city: this.body_.device.location.city
};
return deviceLocation;
}
/**
* Gets transactability of user. Only use after calling
* askForTransactionRequirements. Null if no result given.
*
* @return {string} One of Transactions.ResultType.
* @actionssdk
*/
}, {
key: 'getTransactionRequirementsResult',
value: function getTransactionRequirementsResult() {
debug('getTransactionRequirementsResult');
var result = this.getArgument_(this.BuiltInArgNames.TRANSACTION_REQ_CHECK_RESULT);
if (result && result.extension && result.extension.resultType) {
return result.extension.resultType;
}
debug('Failed to get transaction requirements result');
return null;
}
/**
* Gets transaction decision information. Only use after calling
* askForTransactionDecision.
*
* @return {TransactionDecision} Transaction decision data. Returns object with
* userDecision. userDecision will be one of
* Transactions.ConfirmationDecision. Null if no decision given.
* @actionssdk
*/
}, {
key: 'getTransactionDecision',
value: function getTransactionDecision() {
debug('getTransactionDecision');
var result = this.getArgument_(this.BuiltInArgNames.TRANSACTION_DECISION_VALUE);
if (result && result.extension) {
return result.extension;
}
debug('Failed to get transaction decision information');
return null;
}
/**
* Gets confirmation decision. Use after askForConfirmation.
*
* @return {boolean} True if the user replied with affirmative response.
* False if user replied with negative response. Null if no user
* confirmation decision given.
* @actionssdk
*/
}, {
key: 'getUserConfirmation',
value: function getUserConfirmation() {
debug('getUserConfirmation');
var result = this.getArgument_(this.BuiltInArgNames.CONFIRMATION);
if (result && result.boolValue !== undefined) {
return result.boolValue;
}
debug('Failed to get user confirmation information');
return null;
}
/**
* Gets user provided date and time. Use after askForDateTime.
*
* @return {DateTime} Date and time given by the user. Null if no user
* date and time given.
* @actionssdk
*/
}, {
key: 'getDateTime',
value: function getDateTime() {
debug('getDateTime');
var result = this.getArgument_(this.BuiltInArgNames.DATETIME);
if (result && result.datetimeValue) {
return result.datetimeValue;
}
debug('Failed to get date/time information');
return null;
}
/**
* Gets status of user sign in request.
*
* @return {string} Result of user sign in request. One of
* ActionsSdkApp.SignInStatus. Null if no sign in status.
* @actionssdk
*/
}, {
key: 'getSignInStatus',
value: function getSignInStatus() {
debug('getSignInStatus');
var result = this.getArgument_(this.BuiltInArgNames.SIGN_IN);
if (result && result.extension && result.extension.status) {
return result.extension.status;
}
debug('Failed to get sign in status');
return null;
}
/**
* Gets order delivery address. Only use after calling askForDeliveryAddress.
*
* @return {DeliveryAddress} Delivery address information. Null if user
* denies permission, or no address given.
* @actionssdk
*/
}, {
key: 'getDeliveryAddress',
value: function getDeliveryAddress() {
debug('getDeliveryAddress');
var result = this.getArgument_(this.BuiltInArgNames.DELIVERY_ADDRESS_VALUE) || this.getArgument_(this.BuiltInArgNames.TRANSACTION_DECISION_VALUE);
if (!result || !result.extension) {
debug('Failed to get order delivery address');
return null;
}
if (result.extension.userDecision === this.Transactions.DeliveryAddressDecision.ACCEPTED) {
var locationValue = result.extension.location;
if (!locationValue.postalAddress) {
debug('User accepted, but may not have configured address in app');
return null;
}
return locationValue;
} else {
debug('User rejected giving delivery address');
return null;
}
}
/**
* Returns true if the request follows a previous request asking for
* permission from the user and the user granted the permission(s). Otherwise,
* false. Use with {@link AssistantApp#askForPermissions|askForPermissions}.
*
* @example
* const app = new ActionsSdkApp({request: request, response: response});
* app.askForPermissions("To get you a ride", [
* app.SupportedPermissions.NAME,
* app.SupportedPermissions.DEVICE_PRECISE_LOCATION
* ]);
* // ...
* // In response handler for subsequent intent:
* if (app.isPermissionGranted()) {
* // Use the requested permission(s) to get the user a ride
* }
*
* @return {boolean} true if permissions granted.
* @actionssdk
*/
}, {
key: 'isPermissionGranted',
value: function isPermissionGranted() {
debug('isPermissionGranted');
return this.getArgument(this.BuiltInArgNames.PERMISSION_GRANTED) === 'true';
}
/**
* Returns true if the app is being tested in sandbox mode. Enable sandbox
* mode in the (Actions console)[console.actions.google.com] to test
* transactions.
*
* @return {boolean} True if app is being used in Sandbox mode.
* @actionssdk
*/
}, {
key: 'isInSandbox',
value: function isInSandbox() {
return this.body_ && this.body_.isInSandbox;
}
/**
* Gets the "versionLabel" specified inside the Action Package.

@@ -467,3 +219,3 @@ * Used by app to do version control.

if (!this.body_.conversation || !this.body_.conversation.conversationId) {
this.handleError_('No conversation ID');
error('No conversation ID');
return null;

@@ -508,3 +260,3 @@ }

if (!input) {
this.handleError_('Missing intent from request body');
error('Missing intent from request body');
return null;

@@ -516,118 +268,2 @@ }

/**
* Gets surface capabilities of user device.
*
* @return {Array<string>} Supported surface capabilities, as defined in
* ActionsSdkApp.SurfaceCapabilities.
* @actionssdk
*/
}, {
key: 'getSurfaceCapabilities',
value: function getSurfaceCapabilities() {
debug('getSurfaceCapabilities');
if (this.body_.surface && this.body_.surface.capabilities) {
var capabilities = [];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = this.body_.surface.capabilities[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var capability = _step.value;
capabilities.push(capability.name);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return capabilities;
} else {
error('No surface capabilities in incoming request');
return null;
}
}
/**
* Gets type of input used for this request.
*
* @return {number} One of ActionsSdkApp.InputTypes.
* Null if no input type given.
* @actionssdk
*/
}, {
key: 'getInputType',
value: function getInputType() {
debug('getInputType');
if (this.body_.inputs) {
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = this.body_.inputs[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var input = _step2.value;
if (input.rawInputs) {
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = input.rawInputs[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var rawInput = _step3.value;
if (rawInput.inputType) {
return rawInput.inputType;
}
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
} else {
error('No input type in incoming request');
return null;
}
}
/**
* Get the argument value by name from the current intent. If the argument

@@ -648,20 +284,3 @@ * is not a text argument, the entire argument object is returned.

value: function getArgument(argName) {
debug('getArgument: argName=%s', argName);
if (!argName) {
this.handleError_('Invalid argument name');
return null;
}
var argument = this.getArgument_(argName);
if (!argument) {
debug('Failed to get argument value: %s', argName);
return null;
} else if (argument.textValue) {
return argument.textValue;
} else {
if (!this.isNotApiVersionOne_()) {
return transformToSnakeCase(argument);
} else {
return argument;
}
}
return this.getArgumentCommon(argName);
}

@@ -715,2 +334,3 @@

* 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}.
*

@@ -1067,3 +687,3 @@ * @example

if (noInputs.length > INPUTS_MAX) {
this.handleError_('Invalid number of no inputs');
error('Invalid number of no inputs');
return null;

@@ -1106,3 +726,3 @@ }

if (!this.body_.inputs || this.body_.inputs.length === 0) {
this.handleError_('Missing inputs from request body');
error('Missing inputs from request body');
return null;

@@ -1155,3 +775,3 @@ }

if (!array) {
this.handleError_('Invalid array');
error('Invalid array');
return;

@@ -1167,38 +787,2 @@ }

/**
* Get the argument by name from the current action.
*
* @param {string} argName Name of the argument.
* @return {Object} Argument value matching argName
or null if no matching argument.
* @private
* @actionssdk
*/
}, {
key: 'getArgument_',
value: function getArgument_(argName) {
debug('getArgument_: argName=%s', argName);
if (!argName) {
this.handleError_('Invalid argument name');
return null;
}
var input = this.getTopInput_();
if (!input) {
this.handleError_('Missing action');
return null;
}
if (!arguments) {
debug('No arguments included in request');
return null;
}
for (var i = 0; i < input.arguments.length; i++) {
if (input.arguments[i].name === argName) {
return input.arguments[i];
}
}
debug('Failed to find argument: %s', argName);
return null;
}
/**
* Extract session data from the incoming JSON request.

@@ -1430,3 +1014,3 @@ *

if (!inputPrompt) {
this.handleError_('Invalid input prompt');
error('Invalid input prompt');
return null;

@@ -1449,3 +1033,3 @@ }

} else if (Array.isArray(dialogState)) {
this.handleError_('Invalid dialog state');
error('Invalid dialog state');
return null;

@@ -1482,3 +1066,3 @@ }

if (!intent || intent === '') {
this.handleError_('Invalid intent');
error('Invalid intent');
return null;

@@ -1485,0 +1069,0 @@ }

24

build/response-builder.js

@@ -31,2 +31,3 @@ /**

var debug = Debug('actions-on-google:debug');
var warn = Debug('actions-on-google:warn');
var error = Debug('actions-on-google:error');

@@ -297,3 +298,7 @@

this.suggestions.push({ title: suggestion });
if (this.isValidSuggestionText(suggestion)) {
this.suggestions.push({ title: suggestion });
} else {
warn('Suggestion text can\'t be longer than 25 characters: ' + suggestion + '. This suggestion won\'t be added to the list.');
}
}

@@ -315,3 +320,7 @@ } catch (err) {

} else {
this.suggestions.push({ title: suggestions });
if (this.isValidSuggestionText(suggestions)) {
this.suggestions.push({ title: suggestions });
} else {
warn('Suggestion text can\'t be longer than 25 characters: ' + suggestions + '. This suggestion won\'t be added to the list.');
}
}

@@ -322,2 +331,13 @@ return this;

/**
* 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.
*/
}, {
key: 'isValidSuggestionText',
value: function isValidSuggestionText(suggestionText) {
return suggestionText && suggestionText.length && suggestionText.length <= 25;
}
/**
* Sets the suggestion link for this rich response.

@@ -324,0 +344,0 @@ *

@@ -31,2 +31,5 @@ /**

var ORDER_LOCATION_LIMIT = 2;
var GENERIC_EXTENSION_TYPE = 'type.googleapis.com/google.actions.v2.orders.GenericExtension';
/**

@@ -93,2 +96,3 @@ * Price type.

* receipt. For example, for card payment, could be "VISA-1234".
* @property {CustomerInfoOptions=} customerInfoOptions
*/

@@ -108,9 +112,15 @@

* allowed for transaction.
* @property {CustomerInfoOptions=} customerInfoOptions
*/
/**
* Delivery address returned when calling getDeliveryAddress().
* @typedef {Object} DeliveryAddress
* @property {string} userDecision. - Either Transactions.ConfirmationDecision.ACCEPTED
* or Transactions.ConfirmationDecision.REJECTED.
* Customer information requested as part of the transaction
* @typedef {Object} CustomerInfoOptions
* @property {Array<string>} customerInfoProperties - one of
* Transactions.CustomerInfoProperties
*/
/**
* Generic Location type.
* @typedef {Object} Location
* @property {Object} postalAddress

@@ -122,3 +132,3 @@ * @property {string} postalAddress.regionCode

* @property {string} postalAddress.locality
* @property {string} postalAddress.addressLines
* @property {Array<string>} postalAddress.addressLines
* @property {string} postalAddress.recipients

@@ -279,2 +289,10 @@ * @property {string} phoneNumber

/**
* List of customer information properties that can be requested.
* @readonly
* @enum {string}
*/
CustomerInfoProperties: {
EMAIL: 'EMAIL'
},
/**
* List of possible order confirmation user decisions

@@ -310,6 +328,2 @@ * @readonly

/**
* Order was confirmed by user.
*/
CREATED: 'CREATED',
/**
* Order was rejected.

@@ -454,5 +468,4 @@ */

*/
REGION_NOT_SUPPORTED: 'ASSISTANT_SURFACE_NOT_SUPPORTED'
REGION_NOT_SUPPORTED: 'REGION_NOT_SUPPORTED'
},
/**

@@ -476,2 +489,52 @@ * List of possible user decisions to give delivery address.

REJECTED: 'REJECTED'
},
/**
* List of possible order location types.
* @readonly
* @enum {string}
*/
LocationType: {
/**
* Unknown.
*/
UNKNOWN: 'UNKNOWN',
/**
* Delivery location for an order.
*/
DELIVERY: 'DELIVERY',
/**
* Business location of order provider.
*/
BUSINESS: 'BUSINESS',
/**
* Origin of the order.
*/
ORIGIN: 'ORIGIN',
/**
* Destination of the order.
*/
DESTINATION: 'DESTINATION'
},
/**
* List of possible order time types.
* @readonly
* @enum {string}
*/
TimeType: {
/**
* Unknown.
*/
UNKNOWN: 'UNKNOWN',
/**
* Date of delivery for the order.
*/
DELIVERY_DATE: 'DELIVERY_DATE',
/**
* Estimated Time of Arrival for order.
*/
ETA: 'ETA',
/**
* Reservation time.
*/
RESERVATION_SLOT: 'RESERVATION_SLOT'
}

@@ -481,2 +544,12 @@ };

/**
* Valid keys for the TransactionValues.OrderStateInfo enum.
* @readonly
* @enum {string}
*/
var reverseOrderStateInfo = Object.keys(TransactionValues.OrderStateInfo).reduce(function (reverseValues, infoType) {
reverseValues[TransactionValues.OrderStateInfo[infoType]] = infoType;
return reverseValues;
}, {});
/**
* Class for initializing and constructing Order with chainable interface.

@@ -528,2 +601,9 @@ */

this.totalPrice = undefined;
/**
* Extensions for this order. Used for vertical-specific order attributes,
* like times and locations.
* @type {Object}
*/
this.extension = undefined;
}

@@ -666,3 +746,3 @@

}
if (!units) {
if (typeof units !== 'number' || Number.isNaN(units)) {
error('Invalid units');

@@ -681,2 +761,66 @@ return this;

}
/**
* 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.
*/
}, {
key: 'addLocation',
value: function addLocation(type, location) {
if (!type) {
error('type cannot be empty');
return this;
}
if (!location) {
error('location cannot be null');
return this;
}
if (!this.extension) {
this.extension = {
'@type': GENERIC_EXTENSION_TYPE
};
}
if (!this.extension.locations) {
this.extension.locations = [];
}
if (this.extension.locations.length >= ORDER_LOCATION_LIMIT) {
error('Order can have no more than ' + ORDER_LOCATION_LIMIT + ' associated locations');
return this;
}
this.extension.locations.push({ type: type, location: location });
return this;
}
/**
* 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.
*/
}, {
key: 'setTime',
value: function setTime(type, time) {
if (!type) {
error('type cannot be empty');
return this;
}
if (!time) {
error('time cannot be empty');
return this;
}
if (!this.extension) {
this.extension = {
'@type': GENERIC_EXTENSION_TYPE
};
}
this.extension.time = { type: type, time_iso8601: time };
return this;
}
}]);

@@ -1037,3 +1181,3 @@

}
if (!units) {
if (typeof units !== 'number' || Number.isNaN(units)) {
error('Invalid units');

@@ -1315,3 +1459,3 @@ return this;

}
if (!units) {
if (typeof units !== 'number' || Number.isNaN(units)) {
error('Invalid units');

@@ -1396,3 +1540,3 @@ return this;

}
if (!units) {
if (typeof units !== 'number' || Number.isNaN(units)) {
error('Invalid units');

@@ -1478,3 +1622,3 @@ return this;

value: function setInfo(type, data) {
if (!type || !TransactionValues.OrderStateInfo[type]) {
if (!type || !reverseOrderStateInfo[type]) {
error('Invalid info type');

@@ -1514,3 +1658,3 @@ return this;

this[TransactionValues.OrderStateInfo[type]] = data;
this[type] = data;
return this;

@@ -1517,0 +1661,0 @@ }

@@ -6,3 +6,3 @@ {

"types": "typings/actions-on-google.d.ts",
"version": "1.1.1-12",
"version": "1.2.1-0",
"license": "Apache-2.0",

@@ -14,6 +14,7 @@ "author": "Google Inc.",

"scripts": {
"build": "mkdir -p build && cp -r ../*.js ../utils build && babel -d . build/{,utils/}*.js",
"clean": "rm -fr build",
"lint": "semistandard --fix \"**/*.js\"",
"test": "npm run lint && ./node_modules/.bin/mocha --reporter spec ./test/*.js"
"lint": "eslint --fix \"*.js\" \"test/*.js\" \"utils/*.js\"",
"test": "npm run lint && ./node_modules/.bin/mocha --reporter spec ./test/*.js",
"coverage": "nyc --reporter=lcov --reporter=html npm test && nyc report",
"ts-build": "mkdir -p build && cp -r ../*.js ../utils build && babel -d . build/{,utils/}*.js",
"ts-clean": "rm -fr build"
},

@@ -58,5 +59,14 @@ "repository": {

"chai-spies": "^0.7.1",
"eslint": "^3.19.0",
"eslint-config-semistandard": "^11.0.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-chai-expect": "^1.1.1",
"eslint-plugin-chai-friendly": "^0.3.6",
"eslint-plugin-import": "^2.3.0",
"eslint-plugin-node": "^5.0.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1",
"mocha": "^3.0.2",
"winston": "2.2.0",
"semistandard": "^9.1.0"
"nyc": "^11.0.3",
"winston": "2.2.0"
},

@@ -63,0 +73,0 @@ "babel": {

@@ -15,4 +15,4 @@ [![NPM](https://nodei.co/npm/actions-on-google-ts.png?downloads=false&stars=false)](https://npmjs.org/package/actions-on-google-ts) [![NPM](https://nodei.co/npm-dl/actions-on-google-ts.png?months=6)](https://npmjs.org/package/actions-on-google-ts)

npm install
npm run build
# npm run clean
npm run ts-build
# npm run ts-clean

@@ -24,2 +24,7 @@ ### Sync with upstream

git checkout master
git merge upstream/master
git checkout ts
git merge upstream/master
### Compare
https://github.com/actions-on-google/actions-on-google-nodejs/compare/<old-commit-hash>...master

@@ -5,9 +5,4 @@ import { Request, Response } from 'express';

import { Carousel, List, RichResponse, SimpleResponse } from './response-builder';
import { DeliveryAddress, TransactionDecision } from './transactions';
import { TransactionDecision } from './transactions';
/**
* This is the class that handles the converstaion API directly from Assistant, providing
* implementation for all the methods available in the API.
*/
// ---------------------------------------------------------------------------

@@ -24,17 +19,20 @@ // Actions SDK support

/**
* Constructor for ActionsSdkApp object. To be used in the Actions SDK
* HTTP endpoint logic.
*
* @example
* const ActionsSdkApp = require('actions-on-google').ActionsSdkApp;
* const app = new ActionsSdkApp({request: request, response: response,
* sessionStarted:sessionStarted});
*
* @param {Object} options JSON configuration.
* @param {Object} options.request Express HTTP request object.
* @param {Object} options.response Express HTTP response object.
* @param {Function=} options.sessionStarted Function callback when session starts.
* @actionssdk
* This is the class that handles the conversation API directly from Assistant,
* providing implementation for all the methods available in the API.
*/
export class ActionsSdkApp extends AssistantApp {
/**
* Constructor for ActionsSdkApp object.
* To be used in the Actions SDK HTTP endpoint logic.
*
* @example
* const ActionsSdkApp = require('actions-on-google').ActionsSdkApp;
* const app = new ActionsSdkApp({request: request, response: response,
* sessionStarted:sessionStarted});
*
* @param {Object} options JSON configuration.
* @param {Object} options.request Express HTTP request object.
* @param {Object} options.response Express HTTP response object.
* @param {Function=} options.sessionStarted Function callback when session starts.
*/
constructor(options: ActionsSdkAppOptions);

@@ -50,3 +48,2 @@

* @return {string} Version value or null if no value.
* @actionssdk
*/

@@ -63,3 +60,2 @@ getApiVersion(): string;

* @return {string} User's raw query or null if no value.
* @actionssdk
*/

@@ -78,3 +74,2 @@ getRawInput(): string;

* user turn or {} if no value.
* @actionssdk
*/

@@ -84,126 +79,2 @@ getDialogState(): object;

/**
* Gets the {@link User} object.
* The user object contains information about the user, including
* a string identifier and personal information (requires requesting permissions,
* see {@link AssistantApp#askForPermissions|askForPermissions}).
*
* @example
* const app = new ActionsSdkApp({request: request, response: response});
* const userId = app.getUser().userId;
*
* @return {User} Null if no value.
* @actionssdk
*/
getUser(): User;
/**
* If granted permission to device's location in previous intent, returns device's
* location (see {@link AssistantApp#askForPermissions|askForPermissoins}).
* If device info is unavailable, returns null.
*
* @example
* const app = new ActionsSdkApp({request: req, response: res});
* app.askForPermission("To get you a ride",
* app.SupportedPermissions.DEVICE_PRECISE_LOCATION);
* // ...
* // In response handler for subsequent intent:
* if (app.isPermissionGranted()) {
* sendCarTo(app.getDeviceLocation().coordinates);
* }
*
* @return {DeviceLocation} Null if location permission is not granted.
* @actionssdk
*/
getDeviceLocation(): DeviceLocation;
/**
* Gets transactability of user. Only use after calling
* askForTransactionRequirements. Null if no result given.
*
* @return {string} One of Transactions.ResultType.
* @actionssdk
*/
getTransactionRequirementsResult(): string;
/**
* Gets transaction decision information. Only use after calling
* askForTransactionDecision.
*
* @return {TransactionDecision} Transaction decision data. Returns object with
* userDecision. userDecision will be one of
* Transactions.ConfirmationDecision. Null if no decision given.
* @actionssdk
*/
getTransactionDecision(): TransactionDecision;
/**
* Gets confirmation decision. Use after askForConfirmation.
*
* @return {boolean} True if the user replied with affirmative response.
* False if user replied with negative response. Null if no user
* confirmation decision given.
* @actionssdk
*/
getUserConfirmation(): boolean;
/**
* Gets user provided date and time. Use after askForDateTime.
*
* @return {DateTime} Date and time given by the user. Null if no user
* date and time given.
* @actionssdk
*/
getDateTime(): DateTime;
/**
* Gets status of user sign in request.
*
* @return {string} Result of user sign in request. One of
* ActionsSdkApp.SignInStatus. Null if no sign in status.
* @actionssdk
*/
getSignInStatus(): string;
/**
* Gets order delivery address. Only use after calling askForDeliveryAddress.
*
* @return {DeliveryAddress} Delivery address information. Null if user
* denies permission, or no address given.
* @actionssdk
*/
getDeliveryAddress(): DeliveryAddress;
/**
* Returns true if the request follows a previous request asking for
* permission from the user and the user granted the permission(s). Otherwise,
* false. Use with {@link AssistantApp#askForPermissions|askForPermissions}.
*
* @example
* const app = new ActionsSdkApp({request: request, response: response});
* app.askForPermissions("To get you a ride", [
* app.SupportedPermissions.NAME,
* app.SupportedPermissions.DEVICE_PRECISE_LOCATION
* ]);
* // ...
* // In response handler for subsequent intent:
* if (app.isPermissionGranted()) {
* // Use the requested permission(s) to get the user a ride
* }
*
* @return {boolean} true if permissions granted.
* @actionssdk
*/
isPermissionGranted(): boolean;
/**
* Returns true if the app is being tested in sandbox mode. Enable sandbox
* mode in the (Actions console)[console.actions.google.com] to test
* transactions.
*
* @return {boolean} True if app is being used in Sandbox mode.
* @actionssdk
*/
isInSandbox(): boolean;
/**
* Gets the "versionLabel" specified inside the Action Package.

@@ -217,3 +88,2 @@ * Used by app to do version control.

* @return {string} The specified version label or null if unspecified.
* @actionssdk
*/

@@ -231,3 +101,2 @@ getActionVersionLabel(): string;

* @return {string} Conversation ID or null if no value.
* @actionssdk
*/

@@ -261,3 +130,2 @@ getConversationId(): string;

* @return {string} Intent id or null if no value.
* @actionssdk
*/

@@ -267,20 +135,2 @@ getIntent(): string;

/**
* Gets surface capabilities of user device.
*
* @return {Array<string>} Supported surface capabilities, as defined in
* ActionsSdkApp.SurfaceCapabilities.
* @actionssdk
*/
getSurfaceCapabilities(): string[];
/**
* Gets type of input used for this request.
*
* @return {number} One of ActionsSdkApp.InputTypes.
* Null if no input type given.
* @actionssdk
*/
getInputType(): number;
/**
* Get the argument value by name from the current intent. If the argument

@@ -295,3 +145,2 @@ * is not a text argument, the entire argument object is returned.

* or null if no matching argument.
* @actionssdk
*/

@@ -329,3 +178,2 @@ getArgument(argName: string): string;

* if current intent is not OPTION intent.
* @actionssdk
*/

@@ -337,2 +185,4 @@ getSelectedOption(): string;

* 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}.
*

@@ -372,3 +222,2 @@ * @example

* @return The response that is sent to Assistant to ask user to provide input.
* @actionssdk
*/

@@ -415,3 +264,2 @@ ask(inputPrompt: object | SimpleResponse | RichResponse, dialogState?: object): object;

* @return The response that is sent to Assistant to ask user to provide input.
* @actionssdk
*/

@@ -450,3 +298,2 @@ askWithList(inputPrompt: object | SimpleResponse | RichResponse, list: List, dialogState?: object): object;

* @return {Object} HTTP response.
* @apiai
*/

@@ -494,3 +341,2 @@ askForDeliveryAddress(reason: string, dialogState?: object): object;

* @return The response that is sent to Assistant to ask user to provide input.
* @actionssdk
*/

@@ -533,3 +379,2 @@ askWithCarousel(inputPrompt: object | SimpleResponse | RichResponse, carousel: Carousel, dialogState?: object): object;

* @return The HTTP response that is sent back to Assistant.
* @actionssdk
*/

@@ -559,3 +404,2 @@ tell(textToSpeech: string | SimpleResponse | RichResponse): object;

* @return {Object} An {@link https://developers.google.com/actions/reference/conversation#InputPrompt|InputPrompt object}.
* @actionssdk
*/

@@ -562,0 +406,0 @@ buildInputPrompt(isSsml: boolean, initialPrompt: string, noInputs: string[]): object;

@@ -5,8 +5,4 @@ import { Request, Response } from 'express';

import { Carousel, List, RichResponse, SimpleResponse } from './response-builder';
import { DeliveryAddress, TransactionDecision } from './transactions';
import { TransactionDecision } from './transactions';
/**
* This is the class that handles the communication with API.ai's backend..
*/
// ---------------------------------------------------------------------------

@@ -36,146 +32,24 @@ // API.AI support

/**
* Constructor for ApiAiApp object. To be used in the API.AI
* fulfillment webhook logic.
*
* @example
* const ApiAiApp = require('actions-on-google').ApiAiApp;
* const app = new ApiAiApp({request: request, response: response,
* sessionStarted:sessionStarted});
*
* @param {Object} options JSON configuration.
* @param {Object} options.request Express HTTP request object.
* @param {Object} options.response Express HTTP response object.
* @param {Function=} options.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 API.AI simulator).
* @apiai
* This is the class that handles the communication with API.AI's fulfillment API.
*/
export class ApiAiApp extends AssistantApp {
constructor(options: ApiAiAppOptions);
/**
* Gets the {@link User} object.
* The user object contains information about the user, including
* a string identifier and personal information (requires requesting permissions,
* see {@link AssistantApp#askForPermissions|askForPermissions}).
* Constructor for ApiAiApp object.
* To be used in the API.AI fulfillment webhook logic.
*
* @example
* const app = new ApiAiApp({request: request, response: response});
* const userId = app.getUser().userId;
* const ApiAiApp = require('actions-on-google').ApiAiApp;
* const app = new ApiAiApp({request: request, response: response,
* sessionStarted:sessionStarted});
*
* @return {User} Null if no value.
* @apiai
* @param {Object} options JSON configuration.
* @param {Object} options.request Express HTTP request object.
* @param {Object} options.response Express HTTP response object.
* @param {Function=} options.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 API.AI simulator).
*/
getUser(): User;
constructor(options: ApiAiAppOptions);
/**
* If granted permission to device's location in previous intent, returns device's
* location (see {@link AssistantApp#askForPermissions|askForPermissions}).
* If device info is unavailable, returns null.
*
* @example
* const app = new ApiAiApp({request: req, response: res});
* app.askForPermission("To get you a ride",
* app.SupportedPermissions.DEVICE_PRECISE_LOCATION);
* // ...
* // In response handler for permissions fallback intent:
* if (app.isPermissionGranted()) {
* sendCarTo(app.getDeviceLocation().coordinates);
* }
*
* @return {DeviceLocation} Null if location permission is not granted.
* @apiai
*/
getDeviceLocation(): DeviceLocation;
/**
* Gets transactability of user. Only use after calling
* askForTransactionRequirements. Null if no result given.
*
* @return {string} One of Transactions.ResultType.
* @apiai
*/
getTransactionRequirementsResult(): string;
/**
* Gets order delivery address. Only use after calling askForDeliveryAddress.
*
* @return {DeliveryAddress} Delivery address information. Null if user
* denies permission, or no address given.
* @apiai
*/
getDeliveryAddress(): DeliveryAddress;
/**
* Gets transaction decision information. Only use after calling
* askForTransactionDecision.
*
* @return {TransactionDecision} Transaction decision data. Returns object with
* userDecision only if user declines. userDecision will be one of
* Transactions.ConfirmationDecision. Null if no decision given.
* @apiai
*/
getTransactionDecision(): TransactionDecision;
/**
* Gets confirmation decision. Use after askForConfirmation.
*
* @return {boolean} True if the user replied with affirmative response.
* False if user replied with negative response. Null if no user
* confirmation decision given.
* @apiai
*/
getUserConfirmation(): boolean;
/**
* Gets user provided date and time. Use after askForDateTime.
*
* @return {DateTime} Date and time given by the user. Null if no user
* date and time given.
* @apiai
*/
getDateTime(): DateTime;
/**
* Gets status of user sign in request.
*
* @return {string} Result of user sign in request. One of
* ApiAiApp.SignInStatus. Null if no sign in status.
* @apiai
*/
getSignInStatus(): string;
/**
* Returns true if the request follows a previous request asking for
* permission from the user and the user granted the permission(s). Otherwise,
* false. Use with {@link AssistantApp#askForPermissions|askForPermissions}.
*
* @example
* const app = new ApiAiApp({request: request, response: response});
* app.askForPermissions("To get you a ride", [
* app.SupportedPermissions.NAME,
* app.SupportedPermissions.DEVICE_PRECISE_LOCATION
* ]);
* // ...
* // In response handler for permissions fallback intent:
* if (app.isPermissionGranted()) {
* // Use the requested permission(s) to get the user a ride
* }
*
* @return {boolean} True if permissions granted.
* @apiai
*/
isPermissionGranted(): boolean;
/**
* Returns true if the app is being tested in sandbox mode. Enable sandbox
* mode in the (Actions console)[console.actions.google.com] to test
* transactions.
*
* @return {boolean} True if app is being used in Sandbox mode.
* @apiai
*/
isInSandbox(): boolean;
/**
* Verifies whether the request comes from API.AI.

@@ -188,3 +62,2 @@ *

* @return {boolean} True if the request comes from API.AI.
* @apiai
*/

@@ -194,23 +67,6 @@ isRequestFromApiAi(key: string, value: string): boolean;

/**
* Gets surface capabilities of user device.
*
* @return {Array<string>} Supported surface capabilities, as defined in
* AssistantApp.SurfaceCapabilities.
* @apiai
*/
getSurfaceCapabilities(): string[];
/**
* Gets type of input used for this request.
*
* @return {number} One of ApiAiApp.InputTypes.
* Null if no input type given.
* @apiai
*/
getInputType(): number;
/**
* 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 API.ai context translates into the current action.
*

@@ -236,4 +92,3 @@ * @example

*
* @return {string} Intent id or null if no value.
* @apiai
* @return {string} Intent id or null if no value (action name).
*/

@@ -272,3 +127,2 @@ getIntent(): string;

* or null if no matching argument.
* @apiai
*/

@@ -313,3 +167,2 @@ getArgument(argName: string): object;

* property matching context argument. Null if no matching argument.
* @apiai
*/

@@ -344,3 +197,2 @@ getContextArgument(contextName: string, argName: string): object;

* created, an empty RichResponse is returned.
* @apiai
*/

@@ -373,3 +225,2 @@ getIncomingRichResponse(): RichResponse;

* List is returned.
* @apiai
*/

@@ -402,3 +253,2 @@ getIncomingList(): List;

* an empty Carousel is returned.
* @apiai
*/

@@ -436,3 +286,2 @@ getIncomingCarousel(): Carousel;

* if current intent is not OPTION intent.
* @apiai
*/

@@ -443,2 +292,4 @@ 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}.
*

@@ -473,3 +324,2 @@ * NOTE: Due to a bug, if you specify the no-input prompts,

* @return {Object} HTTP response.
* @apiai
*/

@@ -516,3 +366,2 @@ ask(inputPrompt: string | SimpleResponse | RichResponse, noInputs?: string[]): object;

* @return {Object} HTTP response.
* @apiai
*/

@@ -560,3 +409,2 @@ askWithList(inputPrompt: string | RichResponse | SimpleResponse, list: List): object;

* @return {Object} HTTP response.
* @apiai
*/

@@ -593,3 +441,2 @@ askWithCarousel(inputPrompt: string | RichResponse | SimpleResponse, carousel: Carousel): object;

* @return {Object} HTTP response.
* @apiai
*/

@@ -623,3 +470,2 @@ askForDeliveryAddress(reason: string): object;

* @return The response that is sent back to Assistant.
* @apiai
*/

@@ -654,3 +500,2 @@ tell(speechResponse: string | SimpleResponse | RichResponse): object;

* @param {Object=} parameters Context JSON parameters.
* @apiai
*/

@@ -692,3 +537,2 @@ setContext(name: string, lifespan: number, parameters?: object): void;

* @return {Context[]} Empty if no active contexts.
* @apiai
*/

@@ -731,3 +575,2 @@ getContexts(): Context[];

* or null if no matching context.
* @apiai
*/

@@ -744,3 +587,2 @@ getContext(name: string): object;

* @return {string} User's raw query or null if no value.
* @apiai
*/

@@ -747,0 +589,0 @@ getRawInput(): string;

@@ -5,13 +5,5 @@ import { Request, Response } from 'express';

import { ActionPaymentTransactionConfig, Cart, GooglePaymentTransactionConfig,
LineItem, Order, OrderUpdate, TransactionValues } from './transactions';
LineItem, Order, OrderUpdate, TransactionDecision, TransactionValues } from './transactions';
/**
* The Actions on Google client library AssistantApp base class.
*
* This class contains the methods that are shared between platforms to support the conversation API
* protocol from Assistant. It also exports the 'State' class as a helper to represent states by
* name.
*/
/**
* User provided date/time info.

@@ -237,4 +229,13 @@ * @typedef {Object} DateTime

export type AssistantAppRequestData = () => any;
export type RequestHandler = (app: AssistantApp) => any;
/**
* The Actions on Google client library AssistantApp base class.
*
* This class contains the methods that are shared between platforms to support the conversation API
* protocol from Assistant. It also exports the 'State' class as a helper to represent states by
* name.
*/
export class AssistantApp {

@@ -254,4 +255,2 @@ /**

* @enum {string}
* @actionssdk
* @apiai
*/

@@ -284,4 +283,2 @@ readonly StandardIntents: {

* @enum {string}
* @actionssdk
* @apiai
*/

@@ -309,4 +306,2 @@ readonly SupportedPermissions: {

* @enum {string}
* @actionssdk
* @apiai
*/

@@ -336,4 +331,2 @@ readonly BuiltInArgNames: {

* @enum {number}
* @actionssdk
* @apiai
*/

@@ -358,4 +351,2 @@ readonly ConversationStages: {

* @enum {string}
* @actionssdk
* @apiai
*/

@@ -376,4 +367,2 @@ readonly SurfaceCapabilities: {

* @enum {number}
* @actionssdk
* @apiai
*/

@@ -402,4 +391,2 @@ readonly InputTypes: {

* @enum {string}
* @actionssdk
* @apiai
*/

@@ -423,5 +410,8 @@ readonly SignInStatus: {

readonly requestData: AssistantAppRequestData;
/**
* Constructor for AssistantApp object.
* Should not be instantiated; rather instantiate one of the subclasses
*
* {@link ActionsSdkApp} or {@link ApiAiApp}.

@@ -433,4 +423,6 @@ *

* @param {Function=} options.sessionStarted Function callback when session starts.
* @param {function(): *} requestData Function that returns the
* request data object to be processed.
*/
constructor(options: AssistantAppOptions);
constructor(options: AssistantAppOptions, requestData: AssistantAppRequestData);

@@ -493,4 +485,2 @@ // ---------------------------------------------------------------------------

* @param {(Function|Map)} handler The handler (or Map of handlers) for the request.
* @actionssdk
* @apiai
*/

@@ -550,4 +540,2 @@ handleRequest(handler?: RequestHandler | Map<string, RequestHandler>): void;

* invalid input, we return null.
* @actionssdk
* @apiai
*/

@@ -593,4 +581,2 @@ askForPermissions(context: string, permissions: string[], dialogState?: object): object;

* @return {Object} HTTP response.
* @actionssdk
* @apiai
*/

@@ -635,3 +621,2 @@ askForTransactionRequirements(transactionConfig?: ActionPaymentTransactionConfig | GooglePaymentTransactionConfig, dialogState?: object): object;

* will be circulated back by Assistant. Used in {@link ActionsSdkAssistant}.
* @apiai
*/

@@ -655,4 +640,4 @@ askForTransactionDecision(order: object, transactionConfig?: ActionPaymentTransactionConfig | GooglePaymentTransactionConfig, dialogState?: object): object;

* * {@link https://developers.google.com/actions/reference/conversation#ExpectedIntent|Supported Permissions}
* * Check if the permission has been granted with {@link ActionsSdkApp#isPermissionGranted|isPermissionsGranted}
* * {@link ActionsSdkApp#getDeviceLocation|getDeviceLocation}
* * Check if the permission has been granted with {@link AssistantApp#isPermissionGranted|isPermissionsGranted}
* * {@link AssistantApp#getDeviceLocation|getDeviceLocation}
* * {@link AssistantApp#getUserName|getUserName}

@@ -692,4 +677,2 @@ *

* for any invalid input, we return null.
* @actionssdk
* @apiai
*/

@@ -699,2 +682,25 @@ askForPermission(context: string, permission: string, dialogState?: object): object;

/**
* Returns true if the request follows a previous request asking for
* permission from the user and the user granted the permission(s). Otherwise,
* false. Use with {@link AssistantApp#askForPermissions|askForPermissions}.
*
* @example
* const app = new ActionsSdkApp({request: request, response: response});
* // or
* const app = new ApiAiApp({request: request, response: response});
* app.askForPermissions("To get you a ride", [
* app.SupportedPermissions.NAME,
* app.SupportedPermissions.DEVICE_PRECISE_LOCATION
* ]);
* // ...
* // In response handler for subsequent intent:
* if (app.isPermissionGranted()) {
* // Use the requested permission(s) to get the user a ride
* }
*
* @return {boolean} true if permissions granted.
*/
isPermissionGranted(): boolean;
/**
* Asks user for a confirmation.

@@ -729,4 +735,2 @@ *

* will be circulated back by Assistant. Used in {@link ActionsSdkAssistant}.
* @actionssdk
* @apiai
*/

@@ -774,4 +778,2 @@ askForConfirmation(prompt?: string, dialogState?: object): object;

* will be circulated back by Assistant. Used in {@link ActionsSdkAssistant}.
* @actionssdk
* @apiai
*/

@@ -781,4 +783,12 @@ askForDateTime(initialPrompt?: string, datePrompt?: string, timePrompt?: string, dialogState?: object): object;

/**
* Asks user for a timezone-agnostic date and time.
* Hands the user off to a web sign in flow. App sign in and OAuth credentials
* are set in the {@link https://console.actions.google.com|Actions Console}.
* Retrieve the access token in subsequent intents using
* app.getUser().accessToken.
*
* Note: Currently this API requires enabling the app for Transactions APIs.
* To do this, fill out the App Info section of the Actions Console project
* and check the box indicating the use of Transactions under "Privacy and
* consent".
*
* @example

@@ -809,4 +819,2 @@ * const app = new ApiAiApp({ request, response });

* will be circulated back by Assistant. Used in {@link ActionsSdkAssistant}.
* @actionssdk
* @apiai
*/

@@ -816,2 +824,18 @@ askForSignIn(dialogState?: object): object;

/**
* Gets the {@link User} object.
* The user object contains information about the user, including
* a string identifier and personal information (requires requesting permissions,
* see {@link AssistantApp#askForPermissions|askForPermissions}).
*
* @example
* const app = new ApiAiApp({request: request, response: response});
* // or
* const app = new ActionsSdkApp({request: request, response: response});
* const userId = app.getUser().userId;
*
* @return {User} Null if no value.
*/
getUser(): User;
/**
* If granted permission to user's name in previous intent, returns user's

@@ -844,8 +868,132 @@ * display name, family name, and given name. If name info is unavailable,

* @return {UserName} Null if name permission is not granted.
* @actionssdk
* @apiai
*/
getUserName(): string;
getUserName(): UserName;
/**
* Gets the user locale. Returned string represents the regional language
* information of the user set in their Assistant settings.
* For example, 'en-US' represents US English.
*
* @example
* const app = new ApiAiApp({request, response});
* const locale = app.getUserLocale();
*
* @return {string} User's locale, e.g. 'en-US'. Null if no locale given.
*/
getUserLocale(): string;
/**
* If granted permission to device's location in previous intent, returns device's
* location (see {@link AssistantApp#askForPermissions|askForPermissions}).
* If device info is unavailable, returns null.
*
* @example
* const app = new ApiAiApp({request: req, response: res});
* // or
* const app = new ActionsSdkApp({request: req, response: res});
* app.askForPermission("To get you a ride",
* app.SupportedPermissions.DEVICE_PRECISE_LOCATION);
* // ...
* // In response handler for permissions fallback intent:
* if (app.isPermissionGranted()) {
* sendCarTo(app.getDeviceLocation().coordinates);
* }
*
* @return {DeviceLocation} Null if location permission is not granted.
*/
getDeviceLocation(): DeviceLocation;
/**
* Gets type of input used for this request.
*
* @return {number} One of AssistantApp.InputTypes.
* Null if no input type given.
*/
getInputType(): number;
/**
* 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 ApiAiApp({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.
*/
getArgumentCommon(argName): object;
/**
* Gets transactability of user. Only use after calling
* askForTransactionRequirements. Null if no result given.
*
* @return {string} One of Transactions.ResultType.
*/
getTransactionRequirementsResult(): string;
/**
* Gets order delivery address. Only use after calling askForDeliveryAddress.
*
* @return {DeliveryAddress} Delivery address information. Null if user
* denies permission, or no address given.
*/
getDeliveryAddress(): Location;
/**
* Gets transaction decision information. Only use after calling
* askForTransactionDecision.
*
* @return {TransactionDecision} Transaction decision data. Returns object with
* userDecision only if user declines. userDecision will be one of
* Transactions.ConfirmationDecision. Null if no decision given.
*/
getTransactionDecision(): TransactionDecision;
/**
* Gets confirmation decision. Use after askForConfirmation.
*
* False if user replied with negative response. Null if no user
* confirmation decision given.
*/
getUserConfirmation(): boolean;
/**
* Gets user provided date and time. Use after askForDateTime.
*
* @return {DateTime} Date and time given by the user. Null if no user
* date and time given.
*/
getDateTime(): Date;
/**
* Gets status of user sign in request.
*
* @return {string} Result of user sign in request. One of
* ApiAiApp.SignInStatus or ActionsSdkApp.SignInStatus
* Null if no sign in status.
*/
getSignInStatus(): string;
/**
* Returns true if user device has a given surface capability.

@@ -870,5 +1018,2 @@ *

* app.handleRequest(actionMap);
*
* @apiai
* @actionssdk
*/

@@ -880,9 +1025,16 @@ hasSurfaceCapability(requestedCapability: string): boolean;

*
* Implemented in subclasses for Actions SDK and API.AI.
* @return {Object} HTTP response.
* @apiai
* @actionssdk
* @return {Array<string>} Supported surface capabilities, as defined in
* AssistantApp.SurfaceCapabilities.
*/
getSurfaceCapabilities(): object;
getSurfaceCapabilities(): string[];
/**
* Returns true if the app is being tested in sandbox mode. Enable sandbox
* mode in the (Actions console)[console.actions.google.com] to test
* transactions.
*
* @return {boolean} True if app is being used in Sandbox mode.
*/
isInSandbox(): boolean;
// ---------------------------------------------------------------------------

@@ -889,0 +1041,0 @@ // Response Builders

@@ -125,2 +125,8 @@ /**

/**
* 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.
*/
isValidSuggestionText(suggestionText: string): boolean;
/**
* Sets the suggestion link for this rich response.

@@ -127,0 +133,0 @@ *

@@ -96,2 +96,3 @@ /**

displayName: string;
customerInfoOptions?: CustomerInfoOptions;
}

@@ -112,11 +113,19 @@

prepaidCardDisallowed: boolean;
customerInfoOptions?: CustomerInfoOptions;
}
/**
* Delivery address returned when calling getDeliveryAddress().
* Customer information requested as part of the transaction
*/
export interface DeliveryAddress {
export interface CustomerInfoOptions {
// one of Transactions.CustomerInfoProperties
customerInfoProperties: string[];
}
/**
* Generic Location type.
*/
export interface Location {
// Either Transactions.ConfirmationDecision.ACCEPTED
// or Transactions.ConfirmationDecision.REJECTED.
userDecision: ConfirmationDecision;
postalAddress: {

@@ -128,3 +137,3 @@ regionCode: string;

locality: string;
addressLines: string;
addressLines: string[];
recipients: string;

@@ -178,3 +187,3 @@ };

// Will appear if userDecision is Transactions.DELIVERY_ADDRESS_UPDATED.
deliveryAddress: DeliveryAddress;
deliveryAddress: Location;
}

@@ -298,2 +307,7 @@

/**
* List of customer information properties that can be requested.
*/
export type CustomerInfoProperties = 'EMAIL';
/**
* List of possible order confirmation user decisions

@@ -327,6 +341,2 @@ * @enum {string}

/**
* Order was confirmed by user.
*/
'CREATED' |
/**
* Order was rejected.

@@ -467,3 +477,3 @@ */

*/
'ASSISTANT_SURFACE_NOT_SUPPORTED';
'REGION_NOT_SUPPORTED';

@@ -489,2 +499,51 @@ /**

/**
* List of possible order location types.
* @enum {string}
*/
export type LocationType =
/**
* Unknown.
*/
'UNKNOWN' |
/**
* Delivery location for an order.
*/
'DELIVERY' |
/**
* Business location of order provider.
*/
'BUSINESS' |
/**
* Origin of the order.
*/
'ORIGIN' |
/**
* Destination of the order.
*/
'DESTINATION';
/**
* List of possible order time types.
* @enum {string}
*/
export type TimeType =
/**
* Unknown.
*/
'UNKNOWN' |
/**
* Date of delivery for the order.
*/
'DELIVERY_DATE' |
/**
* Estimated Time of Arrival for order.
*/
'ETA' |
/**
* Reservation time.
*/
'RESERVATION_SLOT';
/**
* Values related to supporting transactions.

@@ -494,2 +553,3 @@ * @type {Object}

export const TransactionValues: {
/**

@@ -525,2 +585,3 @@ * List of transaction card networks available when paying with Google.

},
/**

@@ -564,2 +625,3 @@ * List of possible item types.

},
/**

@@ -583,2 +645,3 @@ * List of price types.

},
/**

@@ -614,2 +677,3 @@ * List of possible item types.

},
/**

@@ -619,2 +683,10 @@ * List of possible order confirmation user decisions

*/
readonly CustomerInfoProperties: {
EMAIL: CustomerInfoProperties,
},
/**
* List of possible order confirmation user decisions
* @enum {string}
*/
readonly ConfirmationDecision: {

@@ -639,2 +711,3 @@ /**

},
/**

@@ -646,6 +719,2 @@ * List of possible order states.

/**
* Order was confirmed by user.
*/
CREATED: OrderState,
/**
* Order was rejected.

@@ -675,2 +744,3 @@ */

},
/**

@@ -718,2 +788,3 @@ * List of possible actions to take on the order.

},
/**

@@ -733,2 +804,3 @@ * List of possible types of order rejection.

},
/**

@@ -764,2 +836,3 @@ * List of possible order state objects.

},
/**

@@ -792,2 +865,3 @@ * List of possible order transaction requirements check result types.

},
/**

@@ -811,2 +885,53 @@ * List of possible user decisions to give delivery address.

},
/**
* List of possible user decisions to give delivery address.
* @enum {string}
*/
readonly LocationType: {
/**
* Unknown.
*/
UNKNOWN: LocationType,
/**
* Delivery location for an order.
*/
DELIVERY: LocationType,
/**
* Business location of order provider.
*/
BUSINESS: LocationType,
/**
* Origin of the order.
*/
ORIGIN: LocationType,
/**
* Destination of the order.
*/
DESTINATION: LocationType,
},
/**
* List of possible user decisions to give delivery address.
* @enum {string}
*/
readonly TimeType: {
/**
* Unknown.
*/
UNKNOWN: TimeType,
/**
* Date of delivery for the order.
*/
DELIVERY_DATE: TimeType,
/**
* Estimated Time of Arrival for order.
*/
ETA: TimeType,
/**
* Reservation time.
*/
RESERVATION_SLOT: TimeType,
},
}

@@ -902,2 +1027,21 @@

setTotalPrice(priceType: PriceType, 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;
}

@@ -1150,2 +1294,9 @@

/**
* Extensions for this order. Used for vertical-specific order attributes,
* like times and locations.
* @type {Object}
*/
readonly extension: object;
/**
* Constructor for OrderUpdate.

@@ -1152,0 +1303,0 @@ *

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc