techaffinity / freshchat-phonegap

Freshchat sdk for phonegap
7 stars 36 forks source link

not able to initiallize freshchat in my cordova app #15

Closed wishbooks closed 5 years ago

wishbooks commented 6 years ago

i followed the steps here https://github.com/techaffinity/freshchat-phonegap used this to resolve the issue still same error my code https://codeshare.io/5ovJ9b

screen shot 2018-07-05 at 5 03 26 pm

my cordovaa cersion is 8.0 i tried to create a sample cordova project & load the freshchat plugin

it shows an error occured while trying to load the resource

`function showFreshChat() { console.log("freshchat"); var profile = JSON.parse(localStorage.getItem('profile')); console.log(profile);

if(wGlobal.platform == '') { window.fcWidget.init({

          token      : "",
          host       : "https://wchat.freshchat.com",
          externalId : profile.username,     // user’s id unique to your system
          firstName  : profile.first_name,   // user’s first name
          lastName   : profile.last_name,    // user’s last name
          email      : profile.email,    // user’s email address
          phone      : profile.userprofile.phone_number,  // phone number without country code
          phoneCountryCode: "+91",
          restoreId  : localStorage.getItem('freshchatrestotreId'+profile.username),
          config     : { 
                            headerProperty:
                            {
                              //Set Widget to be left to right.
                              direction: 'ltr'
                            }
                        }
        });

      window.fcWidget.user.get(function(resp)
      {
        var status = resp && resp.status,
            data = resp && resp.data;
        if (status !== 200)
        {
          window.fcWidget.user.setProperties({
            firstName  : profile.first_name,   // user’s first name
            lastName   : profile.last_name,    // user’s last name
            email      : profile.email,    // user’s email address
            phone      : profile.userprofile.phone_number, // phone number without country code
            phoneCountryCode: "+91",
            plan       : "Estate",                 // user's meta property 1
            status     : "Active",               // user's meta property 2
          });
          window.fcWidget.on('user:created', function(resp)
          {
            var status = resp && resp.status,
                data = resp && resp.data;

            if (status === 200) {
              if (data.restoreId)
              {
                localStorage.setItem("freshchatrestotreId"+profile.username, data.restoreId);// Update restoreId in your database
              }
            }
          });
        }
      });

  }// end of freshat initiallization for lite app
  else
  {
    document.addEventListener("deviceready",function(){

    window.Freshchat.init({

         appId                   : "",
         appKey                  : "",
         gallerySelectionEnabled : true,
         cameraCaptureEnabled    : true,
         teamMemberInfoVisible   : true,
         config                  : { 
                                      headerProperty:
                                      {
                                        //Set Widget to be left to right.
                                        direction: 'ltr'
                                      }
                                  }
     }, function(success){
         console.log("This is called form the init callback");
     });

    //After initializing Freshchat in ios
    showSupportChat = function()
    {

      var userInfo = {
                     "name" : profile.first_name + ' ' + profile.last_name,
                     "email" : profile.email,
                     "externalId" : profile.username,
                     "countryCode" : "+91",
                     "phoneNumber" : profile.userprofile.phone_number
                  };

      Freshchat.updateUser(userInfo)
      window.Freshchat.showConversations();

    };
    document.getElementById("launch_conversations").onclick = showSupportChat;

     });

  } // end of initiallization for ios

  console.log('opened fresh chat');

} //end of Freshchat `

when i try to add the plugin from the command specified in steps it showed this error

Jays-MacBook-Pro:hello jay$ sudo cordova plugin add https://github.com/techaffinity/freshchat-phonegap.git (node:6762) UnhandledPromiseRejectionWarning: CordovaError: Failed to fetch plugin https://github.com/techaffinity/freshchat-phonegap.git via registry. Probably this is either a connection problem, or plugin spec is incorrect. Check your connection and plugin name/version/URL. Error: npm: Command failed with exit code 1 Error output: npm ERR! code 1 npm ERR! Command failed: /usr/local/bin/git clone -q https://github.com/techaffinity/freshchat-phonegap.git /Users/jay/.npm/_cacache/tmp/git-clone-045cb2e1 npm ERR! /Users/jay/.npm/_cacache/tmp/git-clone-045cb2e1/.git: Permission denied npm ERR!

npm ERR! A complete log of this run can be found in: npm ERR! /Users/jay/.npm/_logs/2018-07-06T07_07_33_337Z-debug.log at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/fetch.js:173:37 at _rejected (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:864:24) at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:890:30 at Promise.when (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:1142:31) at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:808:41) at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:624:44 at runSingle (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:137:13) at flush (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:125:13) at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickCallback (internal/process/next_tick.js:180:9) (node:6762) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:6762) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

so i added the plugin locally

techaffinity commented 5 years ago

Hi Wishbooks,

We can install the plugin through command line itself. As we just checked with our plugin in a new Cordova app we are able to install the plugin without any connection issues that you mentioned here. So we would suggest you to again try installing it only through command line instead of doing it locally. Please given an update if you still have the issue. Thanks