botium-actions-on-google-testing
Version:
This is an end-to-end testing library for developers building actions
286 lines (285 loc) • 8.19 kB
TypeScript
/**
* Copyright 2018 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
*
* https://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
*
*/
/// <reference types="node" />
import * as i18n from 'i18n';
interface AogOptionInfo {
key: string;
synonyms: string[];
}
export declare const AUDIO_OUT_ENCODINGS: {
LINEAR16: number;
MP3: number;
OPUS_IN_OGG: number;
};
export interface UserCredentials {
client_id: string;
client_secret: string;
refresh_token: string;
type: 'authorized_user';
}
export interface AssistResponseButton {
title: string;
url: string;
}
export interface AssistResponseCard {
title?: string;
subtitle?: string;
text?: string;
imageUrl?: string;
imageAltText?: string;
buttons: AssistResponseButton[];
}
export interface AssistResponseList {
title?: string;
items: {
title?: string;
description?: string;
imageUrl?: string;
imageAltText?: string;
optionInfo?: AogOptionInfo;
}[];
}
export interface AssistResponseTableRow {
cells: string[];
divider: boolean;
}
export interface AssistResponse {
micOpen: boolean;
textToSpeech: string[];
displayText: string[];
ssml: string[];
cards?: AssistResponseCard[];
carousel?: {
title?: string;
description?: string;
imageUrl?: string;
imageAltText?: string;
footer?: string;
url?: string;
optionInfo?: AogOptionInfo;
}[];
list?: AssistResponseList;
mediaResponse?: {
type: string;
name: string;
description: string;
sourceUrl: string;
icon?: string;
largeImage?: string;
};
suggestions: string[];
linkOutSuggestion?: {
url: string;
name: string;
};
table?: {
headers: string[];
rows: AssistResponseTableRow[];
};
newSurface?: {
capabilities: string[];
context: string;
notificationTitle: string;
};
deviceAction?: string;
signInIntent?: boolean;
audioOut?: Buffer;
screenOutHtml?: string;
}
/**
* A class to handle requests to the Google Assistant for an Action.
*/
export declare class ActionsOnGoogle {
/** @hidden */
_client: any;
/** @hidden reference to ava test to allow logging */
_t: any;
/** @hidden */
_conversationState: Uint8Array;
/** @hidden */
_endpoint: string;
/** @hidden */
_isNewConversation: boolean;
/** @hidden */
_locale: string;
/** @hidden */
_micHasClosed: boolean;
/**
* A representation of coordinates, longitude and latitude
*
* @example
* ```javascript
* action.location = [37.39, -122.08] // Mountain View, California
* ```
*
* @public
*/
location: number[];
/** @public */
deviceModelId: string;
/** @public */
deviceInstanceId: string;
/**
* Flags to include/exclude certain response data
* audioOut - include/exclude response audio buffer (if available)
* screenOut - include/exclude response screen output (HTML) (if available)
*
* @example
* ```javascript
* const action = new ActionsOnGoogleAva(CREDENTIALS);
* action.include.audioOut = true;
* action.include.screenOut = true;
* action.include = { audioOut: true, screenOut = false };
* ```
*
* @public
*/
include: {
audioOut: boolean;
screenOut: boolean;
};
/**
* Audio encoding of response audio buffer (only used if include.audioOut is enabled)
* @public
*/
audioOutEncoding: number;
/**
* Constructs a new ActionsOnGoogle object and initializes a gRPC client
*
* @param credentials Credentials for a given user to make authorized requests
* @public
*/
constructor(credentials?: UserCredentials);
/** @hidden */
_createClient(credentials?: UserCredentials): any;
/**
* @deprecated This will be removed in future releases. Use `action.locale` instead.
* @hidden
*/
setLocale(l: string): void;
/**
* The locale of user-initiated requests
*
* @param l The locale to use in requests
*
* @example
* ```javascript
* const action = new ActionsOnGoogleAva(CREDENTIALS);
* action.locale = 'fr-FR'
* ```
*
* @public
*/
locale: string;
/** @hidden */
i18n_(name: string, params?: i18n.Replacements): string;
/**
* @deprecated This will be removed at releasing a version 1.
* @hidden
*/
startConversation(prompt?: string): Promise<AssistResponse>;
/**
* Starts a conversation with "my test app"
*
* @param prompt An optional starting prompt to send to the Action as it is invoked
* @return A Promise with the response from the Action
*
* @example
* ```javascript
* // Pass in optional user credentials or default to environment variables
* const action = new ActionsOnGoogleAva(CREDENTIALS);
* action.start() // "talk to my test app"
* then(res => {
* expect(res.textToSpeech[0]).to.be.equal('Welcome to my test app')
* })
* ```
*
* @public
*/
start(prompt?: string): Promise<AssistResponse>;
/**
* @deprecated This will be removed at releasing a version 1.
* @hidden
*/
startConversationWith(action: string, prompt?: string): Promise<AssistResponse>;
/**
* Starts a conversation with the provided Action
*
* @param action The name of the Action to invoke
* @param prompt An optional starting prompt to send to the Action as it is invoked
* @return A Promise with the response from the Action
*
* @example
* ```javascript
* // Pass in optional user credentials or default to environment variables
* const action = new ActionsOnGoogleAva(CREDENTIALS);
* action.startWith('number genie') // "talk to number genie"
* .then(res => {
* expect(res.textToSpeech[0]).to.be.equal('I am thinking of a number')
* })
* ```
*
* @public
*/
startWith(action: string, prompt?: string): Promise<AssistResponse>;
/**
* @deprecated This will be removed at releasing a version 1.
* @hidden
*/
endConversation(): Promise<AssistResponse>;
/**
* Sends a cancel command to the Action, to end the conversation immediately
*
* @return A Promise with the response from the Action
*
* @example
* ```javascript
* // Pass in optional user credentials or default to environment variables
* const action = new ActionsOnGoogleAva(CREDENTIALS);
* action.startWith('number genie') // "talk to number genie"
* .then(res => {
* return action.cancel()
* }).then(res => {
* expect(res.textToSpeech[0]).to.be.equal('See you later')
* })
* ```
*
* @public
*/
cancel(): Promise<AssistResponse>;
/**
* Sends a text query to the Action
*
* @param input The user-provided query as text
* @return A Promise with the response from the Action
*
* @example
* ```javascript
* // Pass in optional user credentials or default to environment variables
* const action = new ActionsOnGoogleAva(CREDENTIALS);
* action.startWith('number genie', 'about 50') // "talk to number genie about 50"
* .then(res => {
* return action.send('what about 49?')
* }).then(res => {
* expect(res.textToSpeech[0]).to.be.equal('You are very close')
* })
* ```
*
* @public
*/
send(input: string): Promise<AssistResponse>;
}
export {};