import { Injectable } from '@angular/core' ; import { Http , RequestOptionsArgs , Headers } from '@angular/http' ; import { Observable } from 'rxjs' ; import 'rxjs/add/operator/map' ; import * as models from '../models/chatflow.models' ; import { ChatServerConnection , ChatBotProject } from '../models/app.models' ; @ Injectable ( ) export class ChatFlowService { constructor ( private http ) { } private publishChatBotAPI : string = "bot/business" ; private normalizeBaseUrl ( baseUrl ) { baseUrl = baseUrl . replace ( /\\$/ , '' ) ; if ( ! baseUrl . endsWith ( '/' ) ) baseUrl += '/' ; return baseUrl ; } publishProject ( conn , proj , pack ) { let chatNodes = this . normalizeChatNodes ( pack . ChatNodes ) ; return this . http . post ( this . normalizeBaseUrl ( conn . ServerUrl ) + this . publishChatBotAPI , { business_id : proj . Id , flow : chatNodes , business_name : proj . Name } ) . map ( res => res . json ( ) ) ; } chatProjectExists ( conn , proj ) { return this . http . get ( this . normalizeBaseUrl ( conn . ServerUrl ) + this . publishChatBotAPI + "?business_id=" + proj . Id ) . map ( res => res . json ( ) ) ; } normalizeChatNodes ( chatNodes ) { chatNodes . forEach ( x => { x . IsStartNode = x . IsStartNode ? true : false ; } ) ; return chatNodes ; } }