Skip to content

Commit 54b015a

Browse files
authored
Merge pull request #3 from tawk/TAWK-860rywc83-new-api-for-connections
Tawk-860rywc83-new-api-for-connections
2 parents 8fe8547 + d0d55c0 commit 54b015a

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

addon/components/tawk-messenger.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export default class TawkMessengerComponent extends Component {
4747
widgetId : this.args.widgetId,
4848
embedId : this.args.embedId,
4949
basePath : this.args.basePath,
50+
autoStart : this.args.autoStart
5051
});
5152

5253
/**

addon/services/tawk-messenger.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ export default class TawkMessenger extends Service {
1313
/**
1414
* API for calling an action on the widget
1515
*/
16+
start() {
17+
return window.Tawk_API.start();
18+
}
19+
20+
shutdown() {
21+
return window.Tawk_API.shutdown();
22+
}
23+
1624
maximize() {
1725
return window.Tawk_API.maximize();
1826
}

addon/utils/widget.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function loadScript({propertyId = '', widgetId = '', embedId = '', basePath = 'tawk.to'}) {
1+
function loadScript({propertyId = '', widgetId = '', embedId = '', basePath = 'tawk.to', autoStart = true}) {
22
if (embedId.length) {
33
/**
44
* If the element with embedId as id we will create a new clement
@@ -13,6 +13,10 @@ function loadScript({propertyId = '', widgetId = '', embedId = '', basePath = 't
1313
window.Tawk_API.embedded = embedId;
1414
}
1515

16+
if (!autoStart) {
17+
window.Tawk_API.autoStart = autoStart;
18+
}
19+
1620
const script = document.createElement('script');
1721
script.async = true;
1822
script.src = `https://embed.${basePath}/${propertyId}/${widgetId}`;

docs/api-reference.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ Use the JavaScript API to manipulate the chat widget displayed on your website.
3131
- [onTagsUpdated](#ontagsupdated)
3232
- [onUnreadCountChanged](#onunreadcountchanged)
3333
- [visitor](#visitor)
34+
- [autoStart](#autostart)
35+
- [start](#start)
36+
- [shutdown](#shutdown)
3437
- [maximize](#maximize)
3538
- [minimize](#minimize)
3639
- [toggle](#toggle)
@@ -458,6 +461,52 @@ this.tawkMessenger.visitor({
458461

459462
<br/>
460463

464+
## autoStart
465+
If set to true, it will auto-start the Tawk socket connection for chat services. If set to false,
466+
you will need to manually call the start API. It will not register and connect to the dashboard
467+
if this is set to false.
468+
469+
```hbs
470+
<TawkMessenger
471+
@propertyId={{'property_id'}}
472+
@widgetId={{'widget_id'}}
473+
@autoStart={{false}}/>
474+
```
475+
476+
<br/>
477+
478+
## start
479+
Start the tawk socket connection.
480+
481+
```js
482+
this.tawkMessenger.start();
483+
484+
// Example
485+
486+
@action
487+
handleOnLoad() {
488+
this.tawkMessenger.start();
489+
}
490+
```
491+
492+
<br/>
493+
494+
## shutdown
495+
End the tawk socket connection.
496+
497+
```js
498+
this.tawkMessenger.shutdown();
499+
500+
// Example
501+
502+
@action
503+
handleOnLoad() {
504+
this.tawkMessenger.shutdown();
505+
}
506+
```
507+
508+
<br/>
509+
461510
## maximize
462511
Maximizes the chat widget.
463512

0 commit comments

Comments
 (0)