-
Notifications
You must be signed in to change notification settings - Fork 1
/
message.service.ts
42 lines (36 loc) · 1.06 KB
/
message.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { Observable } from "rxjs";
import { BehaviorSubject } from "rxjs/BehaviorSubject";
@Injectable({
providedIn: "root",
})
export class MessageService {
public url = "http://localhost:3000/messages";
public boturl = "http://localhost:3000/botresponse";
private storageSub = new BehaviorSubject<String>("");
constructor(private http: HttpClient) {}
sendMessageToBot(message: string): Observable<any> {
return this.http.post(this.url, { message }).pipe((response) => {
return response;
});
}
getBotResponse(): Observable<any> {
return this.http.get(this.boturl).pipe((response) => {
return response;
});
}
watchStorage(): Observable<any> {
console.log("Get");
return this.storageSub.asObservable();
}
setItem(key: string, data: any) {
localStorage.setItem(key, data);
console.log("Set");
this.storageSub.next("changed");
}
testUrlCanLoad(url) {
console.log(url);
return this.http.get(url);
}
}