mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Add conversation ID to voice dialog (#4189)
This commit is contained in:
parent
5ca82fd39c
commit
ab476d2f1b
@ -9,6 +9,8 @@ interface ProcessResults {
|
|||||||
|
|
||||||
export const processText = (
|
export const processText = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
text: string
|
text: string,
|
||||||
|
// tslint:disable-next-line: variable-name
|
||||||
|
conversation_id: string
|
||||||
): Promise<ProcessResults> =>
|
): Promise<ProcessResults> =>
|
||||||
hass.callApi("POST", "conversation/process", { text });
|
hass.callApi("POST", "conversation/process", { text, conversation_id });
|
||||||
|
@ -22,6 +22,7 @@ import { PaperInputElement } from "@polymer/paper-input/paper-input";
|
|||||||
import { haStyleDialog } from "../../resources/styles";
|
import { haStyleDialog } from "../../resources/styles";
|
||||||
// tslint:disable-next-line
|
// tslint:disable-next-line
|
||||||
import { PaperDialogScrollableElement } from "@polymer/paper-dialog-scrollable/paper-dialog-scrollable";
|
import { PaperDialogScrollableElement } from "@polymer/paper-dialog-scrollable/paper-dialog-scrollable";
|
||||||
|
import { uid } from "../../common/util/uid";
|
||||||
|
|
||||||
interface Message {
|
interface Message {
|
||||||
who: string;
|
who: string;
|
||||||
@ -62,6 +63,7 @@ export class HaVoiceCommandDialog extends LitElement {
|
|||||||
@property() private _opened = false;
|
@property() private _opened = false;
|
||||||
@query("#messages") private messages!: PaperDialogScrollableElement;
|
@query("#messages") private messages!: PaperDialogScrollableElement;
|
||||||
private recognition?: SpeechRecognition;
|
private recognition?: SpeechRecognition;
|
||||||
|
private _conversationId?: string;
|
||||||
|
|
||||||
public async showDialog(): Promise<void> {
|
public async showDialog(): Promise<void> {
|
||||||
this._opened = true;
|
this._opened = true;
|
||||||
@ -166,6 +168,7 @@ export class HaVoiceCommandDialog extends LitElement {
|
|||||||
|
|
||||||
protected firstUpdated(changedProps: PropertyValues) {
|
protected firstUpdated(changedProps: PropertyValues) {
|
||||||
super.updated(changedProps);
|
super.updated(changedProps);
|
||||||
|
this._conversationId = uid();
|
||||||
this._conversation = [
|
this._conversation = [
|
||||||
{
|
{
|
||||||
who: "hass",
|
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
|
// To make sure the answer is placed at the right user text, we add it before we process it
|
||||||
this._addMessage(message);
|
this._addMessage(message);
|
||||||
try {
|
try {
|
||||||
const response = await processText(this.hass, text);
|
const response = await processText(
|
||||||
|
this.hass,
|
||||||
|
text,
|
||||||
|
this._conversationId!
|
||||||
|
);
|
||||||
const plain = response.speech.plain;
|
const plain = response.speech.plain;
|
||||||
message.text = plain.speech;
|
message.text = plain.speech;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user