UNPKG

2.79 kBJavaScriptView Raw
1"use strict";
2/**
3 * Copyright 2018 Google Inc. All Rights Reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.SignIn = void 0;
19const helper_1 = require("./helper");
20/**
21 * Hands the user off to a web sign in flow. App sign in and OAuth credentials
22 * are set in the {@link https://console.actions.google.com|Actions Console}.
23 * Retrieve the access token in subsequent intents using
24 * {@link Access#token|conv.user.access.token}.
25 *
26 * @example
27 * ```javascript
28 *
29 * // Actions SDK
30 * const app = actionssdk()
31 *
32 * app.intent('actions.intent.MAIN', conv => {
33 * conv.ask(new SignIn())
34 * })
35 *
36 * app.intent('actions.intent.SIGN_IN', (conv, input, signin) => {
37 * if (signin.status === 'OK') {
38 * const access = conv.user.access.token // possibly do something with access token
39 * conv.ask('Great, thanks for signing in! What do you want to do next?')
40 * } else {
41 * conv.ask(`I won't be able to save your data, but what do you want to do next?`)
42 * }
43 * })
44 *
45 * // Dialogflow
46 * const app = dialogflow()
47 *
48 * app.intent('actions.intent.MAIN', conv => {
49 * conv.ask(new SignIn())
50 * })
51 *
52 * // Create a Dialogflow intent with the `actions_intent_SIGN_IN` event
53 * app.intent('Get Signin', (conv, params, signin) => {
54 * if (signin.status === 'OK') {
55 * const access = conv.user.access.token // possibly do something with access token
56 * conv.ask('Great, thanks for signing in! What do you want to do next?')
57 * } else {
58 * conv.ask(`I won't be able to save your data, but what do you want to do next?`)
59 * }
60 * })
61 * ```
62 *
63 * @public
64 */
65class SignIn extends helper_1.SoloHelper {
66 /**
67 * @param context The optional context why the app needs to ask the user to sign in, as a
68 * prefix of a prompt for user consent, e.g. "To track your exercise", or
69 * "To check your account balance".
70 * @public
71 */
72 constructor(context) {
73 super({
74 intent: 'actions.intent.SIGN_IN',
75 type: 'type.googleapis.com/google.actions.v2.SignInValueSpec',
76 data: {
77 optContext: context,
78 },
79 });
80 }
81}
82exports.SignIn = SignIn;
83//# sourceMappingURL=signin.js.map
\No newline at end of file