1 | /**
|
2 | * Copyright 2018 Google Inc. All Rights Reserved.
|
3 | *
|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | * you may not use this file except in compliance with the License.
|
6 | * You may obtain a copy of the License at
|
7 | *
|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
9 | *
|
10 | * Unless required by applicable law or agreed to in writing, software
|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | * See the License for the specific language governing permissions and
|
14 | * limitations under the License.
|
15 | */
|
16 | import * as Api from '../../../api/v2';
|
17 | import { SoloHelper } from '../helper';
|
18 | /** @public */
|
19 | export declare type PermissionArgument = boolean;
|
20 | /** @public */
|
21 | export interface PermissionOptions {
|
22 | /**
|
23 | * Context why the permission is being asked.
|
24 | * It's the TTS prompt prefix (action phrase) we ask the user.
|
25 | * @public
|
26 | */
|
27 | context?: string;
|
28 | /**
|
29 | * Array or string of permissions App supports,
|
30 | * each of which comes from {@link GoogleActionsV2PermissionValueSpecPermissions}.
|
31 | * @public
|
32 | */
|
33 | permissions: Api.GoogleActionsV2PermissionValueSpecPermissions | Api.GoogleActionsV2PermissionValueSpecPermissions[];
|
34 | /**
|
35 | * Extra properties to be spread into the value.
|
36 | * For advanced usages like used in {@link UpdatePermission}
|
37 | * @public
|
38 | */
|
39 | extra?: Api.GoogleActionsV2PermissionValueSpec;
|
40 | }
|
41 | /**
|
42 | * Asks the Assistant to guide the user to grant a permission. For example,
|
43 | * if you want your app to get access to the user's name, you would invoke
|
44 | * `conv.ask(new Permission)` with the context containing the reason for the request,
|
45 | * and the {@link GoogleActionsV2PermissionValueSpecPermissions} permission.
|
46 | * With this, the Assistant will ask the user, in your agent's voice,
|
47 | * the following: '[Context with reason for the request],
|
48 | * I'll just need to get your name from Google, is that OK?'.
|
49 | *
|
50 | * Once the user accepts or denies the request, the Assistant will fire another intent:
|
51 | * `actions.intent.PERMISSION` with a boolean argument: `PERMISSION`
|
52 | * and, if granted, the information that you requested.
|
53 | *
|
54 | * Notes for multiple permissions:
|
55 | * * The order in which you specify the permission prompts does not matter -
|
56 | * it is controlled by the Assistant to provide a consistent user experience.
|
57 | * * The user will be able to either accept all permissions at once, or none.
|
58 | * If you wish to allow them to selectively accept one or other, make several
|
59 | * dialog turns asking for each permission independently with `conv.ask(new Permission)`.
|
60 | * * Asking for `DEVICE_COARSE_LOCATION` and `DEVICE_PRECISE_LOCATION` at once is
|
61 | * equivalent to just asking for `DEVICE_PRECISE_LOCATION`
|
62 | *
|
63 | * @example
|
64 | * ```javascript
|
65 | *
|
66 | * // Actions SDK
|
67 | * const app = actionssdk()
|
68 | *
|
69 | * app.intent('actions.intent.MAIN', conv => {
|
70 | * conv.ask(new Permission({
|
71 | * context: 'To read your mind',
|
72 | * permissions: 'NAME',
|
73 | * }))
|
74 | * })
|
75 | *
|
76 | * app.intent('actions.intent.PERMISSION', (conv, input, granted) => {
|
77 | * // granted: inferred first (and only) argument value, boolean true if granted, false if not
|
78 | * const explicit = conv.arguments.get('PERMISSION') // also retrievable w/ explicit arguments.get
|
79 | * const name = conv.user.name
|
80 | * })
|
81 | *
|
82 | * // Dialogflow
|
83 | * const app = dialogflow()
|
84 | *
|
85 | * app.intent('Default Welcome Intent', conv => {
|
86 | * conv.ask(new Permission({
|
87 | * context: 'To read your mind',
|
88 | * permissions: 'NAME',
|
89 | * }))
|
90 | * })
|
91 | *
|
92 | * // Create a Dialogflow intent with the `actions_intent_PERMISSION` event
|
93 | * app.intent('Get Permission', (conv, params, granted) => {
|
94 | * // granted: inferred first (and only) argument value, boolean true if granted, false if not
|
95 | * const explicit = conv.arguments.get('PERMISSION') // also retrievable w/ explicit arguments.get
|
96 | * const name = conv.user.name
|
97 | * })
|
98 | * ```
|
99 | *
|
100 | * Read more:
|
101 | * * {@link GoogleActionsV2PermissionValueSpecPermissions|Supported Permissions}
|
102 | * * Check if the permission has been granted with `conv.arguments.get('PERMISSION')`
|
103 | * * {@link Device#location|conv.device.location}
|
104 | * * {@link User#name|conv.user.name}
|
105 | * * {@link Place|conv.ask(new Place)} which also can ask for Location permission to get a place
|
106 | * @public
|
107 | */
|
108 | export declare class Permission extends SoloHelper<'actions.intent.PERMISSION', Api.GoogleActionsV2PermissionValueSpec> {
|
109 | /**
|
110 | * @param options Permission options
|
111 | * @public
|
112 | */
|
113 | constructor(options: PermissionOptions);
|
114 | }
|