crisp-im / node-crisp-api

:zap: Crisp API Node Wrapper
https://docs.crisp.chat/guides/rest-api/
MIT License
99 stars 39 forks source link

rebindSocket function not available #58

Closed jryebread closed 1 year ago

jryebread commented 1 year ago

https://github.com/crisp-im/node-crisp-api/issues/57#issuecomment-1714372311

Please see above thread,

It is not clear how to call rebindSocket for when new users subscribe to the plugin (to refresh the "on" listeners) I got a function not found error when I tried to call rebindSocket? Why is that?

I couldn't find rebindSocket documented anywhere in the API docs.

This is my code for when a new user subscribes to the plugin:

  async updatePluginForWebsite(websiteId, token, botName, botId, live) {

    console.log("UPDATING VALUE")

    if (!live) {
      console.log('unsubbing!')
      await this.crispClient.plugin.updateSubscriptionSettings(
        websiteId,
        this.pluginId,
        { botId: botId, botName: botName, live: live}
      );
      this.reinitializeClient();
      console.log(
        `Successfully unlived plugin config for website ID: ${websiteId}`
      );

      return;
    }

    //subscribe
    try {
      await this.crispClient.plugin.updateSubscriptionSettings(
        websiteId,
        this.pluginId,
        { botId: botId, botName: botName, live: live}
      );
      console.log(
        `Successfully updated plugin config for website ID: ${websiteId}`
      );
      this.reinitializeClient();

    } catch (error) {
      console.error(`Failed to update plugin config for website ID: ${websiteId}. Error: ${error.message}`);
      throw error;
    }
  }

  _initPlugin() {
    this.crispClient.authenticateTier(
      "plugin", this._apiIdentifier, this._apiKey
    );
    this._events();
  }

  reinitializeClient() {
    // Reinitialize the Crisp client

    this.crispClient.rebindSocket(); --- function not found error
   }

Thanks In advance

valeriansaliou commented 1 year ago

Thanks, will try to replicate today.

valeriansaliou commented 1 year ago

Fixed in v8.1.0.