Initialize programmatically and SPAs

Huggy Chat works with frameworks like Vue, React, Angular, Svelte and other. However, it is possible that will need made some changes. The default installation of Huggy Chat that you copy the code available in channel's settings need that you put the code in HTML file where the frameworks builds (normally in public/index.html or static/index.html).

If you don't have access to this file or simply you want init Huggy Chat by API, is necessary use Huggy.init.

Huggy.init(HuggyChatInit?)

Allows launch Huggy Chat programmatically. This method is made available by the API only when the configuration object $_Huggy is not provided or Huggy.logout is called and Huggy Chat does not reload. The parameter { HuggyChatInit } is optional. The use cases are:

  1. At initialize Huggy Chat without the configuration object $_Huggy
  2. At execute the Huggy.logout(false) method. Read more about Huggy.logout

The 1st case is useful in SPAs or when you want initialize Huggy Chat in another moment. Instead of you put the installation code and it starts automatically, you will add only the Huggy Chat's script.

<script src="https://js.huggy.chat/widget.min.js"></script>
1

When Huggy Chat is initialized without the configuration object $_Huggy in window, the method Huggy.init becomes availablein the API.

In this case, Huggy.init is the unique method available

Using

There 2 ways to initialize programatically. You can declare the configuration object of Huggy Chat window.$_Huggy=HuggyChatInit and call Huggy.init without params. The function will look the object configuration declared previously.

The object of configuration in this case is specifically to start programatically: HuggyChatInit

The other way to initialize Huggy.init(HuggyChatInit) passing the specific configuration.

Both of cases, after execution of Huggy.init, Huggy Chat will load and the method will became unavailable.

HuggyChatInit

PropertyTypeDescriptionDefault
contextIDstringRepresents the context ID. You can find it in the initialization script present in the installation code of your Huggy Chat, provided by our platform during channel configuration.
...HuggyChatConfigAll properties present in HuggyChatConfig are inherited by HuggyChatInit.
<a href="#contextid">contextID</a>
string

Represents the context ID. You can find it in the initialization script present in the installation code of your Huggy Chat, provided by our platform during channel configuration.

Default:


...
HuggyChatConfig

All properties present in HuggyChatConfig are inherited by HuggyChatInit.

Default:


contextID

contextID is an unique hash required for Huggy Chat working. If you're utilizing the common code of instalation, putting the installation code available in channel's settings in your Huggy's account, you don't need worry about because hash already is included.

This param is only important for use case with Huggy.init.

This hash could be founded in installation code. Let's use for example the code used in installation









 



<!-- Init code Huggy Chat  //-->
<script>
  var $_Huggy = {
    defaultCountry: '+1',
    widget_id: '0001',
    company: "0001"
  };
  
  (function(i,s,o,g,r,a,m){ i[r]={context:{id:'8551dbde3f168db249381597eea81c71'}};a=o;o=s.createElement(o); o.async=1;o.src=g;m=s.getElementsByTagName(a)[0];m.parentNode.insertBefore(o,m); })(window,document,'script','https://js.huggy.chat/widget.min.js?v=8.0.0','pwz');
</script>
<!-- End code Huggy Chat  //-->
1
2
3
4
5
6
7
8
9
10
11

In the highlited line we can find the hash 8551dbde3f168db249381597eea81c71

In this case, rewriting the default code for use with Huggy.init would be like this:





 


Huggy.init({
  defaultCountry: '+1',
  widget_id: '0001',
  company: "0001",
  contextID: '8551dbde3f168db249381597eea81c71'
})
1
2
3
4
5
6

Huggy.init accepts as parameter an object HuggyChatInit

Types