freshworks / hotline-phonegap

Hotline Phonegap Plugin
https://hotline.io
Other
6 stars 11 forks source link

How to integrate Hotline with ionic 2 / ionic 3 / cordova / phonegap #33

Closed mj6uc closed 7 years ago

mj6uc commented 7 years ago

I read the phonegap doc - installed the plugin.

Tried init-ing like: (window).Hotline.init({ appId : "93xxxxxxxx9", appKey : "9xxxxxxxxxx1", agentAvatarEnabled : true, cameraCaptureEnabled : false, voiceMessagingEnabled : true, pictureMessagingEnabled : true }, function(success){ console.log("HOTLINE=====> This is called form the init callback"); });

The Hotline object always returns undefined. What is the correct way to use this in an cordova app / ionic 2 (or 3)

Yashika-Chaudhary commented 7 years ago

Facing similar problem. in ionic 2 / ionic 3

jasontrask commented 7 years ago

I've just been able to install this into my Ionic 3 application without any issues... (v3.4.0). I'll share my steps in case it helps!

At the CLI I installed with ionic cordova plugin add hotline. This added to config.xml:

<plugin name="cordova-plugin-hotline" spec="~1.2.1" />

...and to package.json:

"dependencies" : {
    ...
    "hotline": "^1.2.1"
    ...
}

It could have done other stuff as well, but no other installation steps needed than the single command. I then initialised the plugin in the app.component.ts file, within the platform ready method:

this.platform.ready().then(() => {
   (window as any).Hotline.init({
       appId: "APP_ID_HERE",
       appKey: "APP_KEY_HERE"
   }, function(success){
       console.log("Hotline init'd.", success);
   });
}

Then later in the app I'm calling the UI with this:

(window as any).Hotline.showFAQs();
mj6uc commented 7 years ago

The above works well. The only issue (somewhat obvious - but not so) is that on the browser this gives an error - that misleads to thinking that it does not work.

Here is the working version for me:

 this.platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      this.statusBar.styleDefault();
      this.splashScreen.hide();
      if (this.platform.is('core')){
        console.log("Skipping hotline init on browser...")
      }else{
        (<any>window).Hotline.init({
            appId       : "XXXX",
            appKey      : "YYYY",
            agentAvatarEnabled      : true,
            cameraCaptureEnabled    : true,
            voiceMessagingEnabled   : true,
            pictureMessagingEnabled : true
        }, function(success){
            console.log("HOTLINE=====> This is called form the init callback");
            //(<any>window).Hotline.showConversations();

        });
      } 
    });
mj6uc commented 7 years ago

Closing -- as this works now.