File

src/app/core/voice/nlp.service.ts

Index

Properties
Methods

Constructor

constructor(accessToken: )
Parameters :
Name Optional
accessToken no

Methods

process
process(message: string)
Parameters :
Name Type Optional
message string no
Returns : {}

Properties

client
client: ApiAiClient
Type : ApiAiClient
import { ApiAiClient, IServerResponse } from 'api-ai-javascript/index.js';
import { Injectable, Inject, InjectionToken } from '@angular/core';
import { DIALOGFLOW_TOKEN } from './inject-tokens';

@Injectable({
  providedIn: 'root'
})
export class NlpService {
  client: ApiAiClient;

  constructor(@Inject(DIALOGFLOW_TOKEN) private accessToken) {
    this.client = new ApiAiClient({ accessToken });
  }

  async process(message: string) {
    try {
      const response = (await this.client.textRequest(message)) as any;
      const url = response.result.contexts && response.result.contexts[0] && response.result.contexts[0].parameters.url;
      const speech = response.result.fulfillment.speech;
      return {
        speech: speech.replace(/<<(.*)>>/gi, ''),
        link: (speech.match(/<<(.*)>>/) || [null, null])[1]
      };
    } catch (error) {
      console.error(error);
    }
  }
}

results matching ""

    No results matching ""