/** * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { AppHandler } from '../assistant'; import { ConversationV3, ExceptionHandler, ConversationV3Options, ConversationVerification } from './conv'; import { BuiltinFrameworkMetadata } from '../framework'; import { ServiceBaseApp } from '../assistant'; import { OAuth2Client } from 'google-auth-library'; /** * Throw an UnauthorizedError in an intent handler that requires an access token if the token is * invalid. This triggers an access token refresh request for the Action from the Assistant. * * @example * ```javascript * const app = conversation() * * app.handle('My_Handler_Name_That_Requires_An_Access_Token', conv => { * // ... * * // given a function to check if an access token is still valid * const valid = isTokenValid(conv.user.params.bearerToken) * if (!valid) { * throw new UnauthorizedError() * } * }) * * ``` * * @public */ export declare class UnauthorizedError extends Error { } /** @public */ export interface ConversationV3Handler { /** @public */ (conv: TConversation): Promise | any; } /** @hidden */ export interface ConversationV3Handlers { [handler: string]: ConversationV3Handler | undefined; } /** @hidden */ export interface ConversationV3AppHandlers { handles: ConversationV3Handlers; catcher: ExceptionHandler; } /** @public */ export interface ConversationV3Middleware { /** @public */ ( /** @public */ conv: ConversationV3, /** @public */ framework: BuiltinFrameworkMetadata): (ConversationV3 & TConversationPlugin) | void | Promise | Promise; } /** * Represents the app instance which on new requests, * creates a way to interact with the conversation API directly from Assistant, * providing implementation for all the methods available in the API. * * @example * ```javascript * * const app = conversation() * * app.handler('handler name', conv => { * conv.add('How are you?') * }) * ``` * * @public */ export interface ConversationV3App extends ServiceBaseApp { /** * Sets the Handler to be executed when the fulfillment is called * with a given handler name. * * @param name The handler name to match. * When given an array, sets the Handler for any name in the array. * @param handler The Handler to be executed when the handler name is matched. * @public */ handle(name: string | string[], handler: ConversationV3Handler): this; /** @public */ catch(catcher: ExceptionHandler): this; /** @public */ middleware(middleware: ConversationV3Middleware): this; /** @hidden */ _internal: { handlers: ConversationV3AppHandlers; middlewares: ConversationV3Middleware[]; }; /** @public */ verification?: ConversationVerification | string; /** @hidden */ _client?: OAuth2Client; } /** @public */ export interface Conversation { /** @public */ (options?: ConversationV3Options): AppHandler & ConversationV3App; } /** * This is the function that creates the app instance which on new requests, * creates a way to interact with the conversation API directly from Assistant, * providing implementation for all the methods available in the API. * * @example * ```javascript * * const app = conversation() * * app.handler('handler name', conv => { * conv.add('How are you?') * }) * ``` * * @public */ export declare const conversation: Conversation;