import { Component } from '@angular/core';
import { ToastController } from '@ionic/angular';
import { Kommunicate } from '@ionic-native/kommunicate/ngx';
@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {
  kmUser = {
    'userId' : '**LOGGED IN EMAIL ID**',   // Replace it with the Email Id of the logged in user in you application
    'password' : '**PASSWORD**',  // Put password that matchs the above Email ID
  };
  conversationObject = {
    'appId' : '**Your APP_ID**',
    'kmUser' : JSON.stringify(this.kmUser)
  };
  clientKey: any;
  constructor(private toastCtrl: ToastController,
              private kommunicate: Kommunicate){}
  // Function to be called when you want to launch the chat window
  initateBot() {
    this.kommunicate.conversationBuilder(this.conversationObject)
    .then((clientChannelKey: any) => {
    this.clientKey = clientChannelKey; // Save this ClientKey to the database to start the start the coversation again
    this.checkLoginUser();
    }).catch((error: any) => console.error("Error creating conversation." + error));
  }
  checkLoginUser() {
    this.kommunicate.login(this.kmUser).then((response : any) => {
       console.log('success login', response);
    })
    .catch((error1 : any) => {
       console.log('login error', error1);
    })
 }
}