beyondsanity / ngx-freshchat

FreshChat library for Angular
8 stars 5 forks source link

How to get restoreId #2

Closed alexandrkrucheniuk closed 5 years ago

alexandrkrucheniuk commented 5 years ago

@beyondsanity Hey Can you please advice is there any ability to get restoreId when_ user is created?

In Freshchat WebMessenger API they have:

window.fcWidget.on("user:created", function(resp) { console.log('User has been created'); //Function to do some task });

AFAIK there is only one way how to get the restoreId.

beyondsanity commented 5 years ago

Hello @alexandrkrucheniuk,

I'm not using this feature, but I think you could translate the code from the freshchat docs like this:

    const restoreId = RESTOREID // Which need to be fetched from your DB

    this.chat.init({
      token: MY_FRESHCHAT_TOKEN,
      host: MY_FRESHCHAT_URL,
      restoreId: restoreId ? restoreId : null
    })
    .pipe(
      flatMap(
        () => this.chat.getUserProperties()
      ),
      catchError(
        () => this.chat.setUserProperties(MY_USER_DATA)
      )
    )
    .subscribe(
      data => {
        if (data.restoreId) {
          // Update restoreId in your database
        }
      },
      err => console.log(err)
    );
beyondsanity commented 5 years ago

fixed in 0.1.0