2018-10-25 00:49:29 -04:00
|
|
|
import { Injectable } from "@angular/core";
|
|
|
|
import { AuthedApi } from "../authed-api";
|
|
|
|
import { FE_SlackChannel, FE_SlackLink, FE_SlackTeam } from "../../models/slack";
|
2019-06-29 02:21:56 -04:00
|
|
|
import { HttpClient } from "@angular/common/http";
|
2018-10-25 00:49:29 -04:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class SlackApiService extends AuthedApi {
|
2019-06-29 02:21:56 -04:00
|
|
|
constructor(http: HttpClient) {
|
2018-10-25 00:49:29 -04:00
|
|
|
super(http);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bridgeRoom(roomId: string, teamId: string, channelId: string): Promise<FE_SlackLink> {
|
2019-06-29 02:21:56 -04:00
|
|
|
return this.authedPost<FE_SlackLink>("/api/v1/dimension/slack/room/" + roomId + "/link", {
|
|
|
|
teamId,
|
|
|
|
channelId
|
|
|
|
}).toPromise();
|
2018-10-25 00:49:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public unbridgeRoom(roomId: string): Promise<any> {
|
2019-06-29 02:21:56 -04:00
|
|
|
return this.authedDelete("/api/v1/dimension/slack/room/" + roomId + "/link").toPromise();
|
2018-10-25 00:49:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public getLink(roomId: string): Promise<FE_SlackLink> {
|
2019-06-29 02:21:56 -04:00
|
|
|
return this.authedGet<FE_SlackLink>("/api/v1/dimension/slack/room/" + roomId + "/link").toPromise();
|
2018-10-25 00:49:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public getTeams(): Promise<FE_SlackTeam[]> {
|
2019-06-29 02:21:56 -04:00
|
|
|
return this.authedGet<FE_SlackTeam[]>("/api/v1/dimension/slack/teams").toPromise();
|
2018-10-25 00:49:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public getChannels(teamId: string): Promise<FE_SlackChannel[]> {
|
2019-06-29 02:21:56 -04:00
|
|
|
return this.authedGet<FE_SlackChannel[]>("/api/v1/dimension/slack/teams/" + teamId + "/channels").toPromise();
|
2018-10-25 00:49:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public getAuthUrl(): Promise<string> {
|
2019-06-29 02:21:56 -04:00
|
|
|
return this.authedGet("/api/v1/dimension/slack/auth").toPromise()
|
2019-04-13 16:37:56 -04:00
|
|
|
.then(r => r["authUrl"]);
|
2018-10-25 00:49:29 -04:00
|
|
|
}
|
|
|
|
}
|