Add conversation ID to voice dialog (#4189)

This commit is contained in:
Paulus Schoutsen 2019-11-07 12:21:37 -08:00 committed by GitHub
parent 5ca82fd39c
commit ab476d2f1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -9,6 +9,8 @@ interface ProcessResults {
export const processText = (
hass: HomeAssistant,
text: string
text: string,
// tslint:disable-next-line: variable-name
conversation_id: string
): Promise<ProcessResults> =>
hass.callApi("POST", "conversation/process", { text });
hass.callApi("POST", "conversation/process", { text, conversation_id });

View File

@ -22,6 +22,7 @@ import { PaperInputElement } from "@polymer/paper-input/paper-input";
import { haStyleDialog } from "../../resources/styles";
// tslint:disable-next-line
import { PaperDialogScrollableElement } from "@polymer/paper-dialog-scrollable/paper-dialog-scrollable";
import { uid } from "../../common/util/uid";
interface Message {
who: string;
@ -62,6 +63,7 @@ export class HaVoiceCommandDialog extends LitElement {
@property() private _opened = false;
@query("#messages") private messages!: PaperDialogScrollableElement;
private recognition?: SpeechRecognition;
private _conversationId?: string;
public async showDialog(): Promise<void> {
this._opened = true;
@ -166,6 +168,7 @@ export class HaVoiceCommandDialog extends LitElement {
protected firstUpdated(changedProps: PropertyValues) {
super.updated(changedProps);
this._conversationId = uid();
this._conversation = [
{
who: "hass",
@ -258,7 +261,11 @@ export class HaVoiceCommandDialog extends LitElement {
// To make sure the answer is placed at the right user text, we add it before we process it
this._addMessage(message);
try {
const response = await processText(this.hass, text);
const response = await processText(
this.hass,
text,
this._conversationId!
);
const plain = response.speech.plain;
message.text = plain.speech;