import { Injectable } from '@angular/core' ; import { HttpClient , HttpHeaders } from '@angular/common/http' ; import { Observable } from 'rxjs' ; import { environment } from '@env/environment' ; import { Dialogflow } from './dialogflow' ; @ Injectable ( { providedIn : 'root' , } ) export class DialogflowService { private baseURL = environment . dialogFlow . baseUrl ; private token : string = environment . dialogFlow . apiToken ; private sessionId = '_' + Math . random ( ) . toString ( 36 ) . substr ( 2 , 9 ) ; constructor ( private http ) { } public getResponse ( query ) { const data = { query , lang : 'en' , sessionId : this . sessionId , } ; return this . http . post < Dialogflow > ( `${ this . baseURL }` , data , { headers : new HttpHeaders ( { Authorization : `Bearer ${ this . token }` , } ) , } ) ; } }