Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tawk-860rywc83-new-api-for-connections #3

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addon/components/tawk-messenger.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default class TawkMessengerComponent extends Component {
widgetId : this.args.widgetId,
embedId : this.args.embedId,
basePath : this.args.basePath,
autoStart : this.args.autoStart
});

/**
Expand Down
8 changes: 8 additions & 0 deletions addon/services/tawk-messenger.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ export default class TawkMessenger extends Service {
/**
* API for calling an action on the widget
*/
start() {
return window.Tawk_API.start();
}

shutdown() {
return window.Tawk_API.shutdown();
}

maximize() {
return window.Tawk_API.maximize();
}
Expand Down
6 changes: 5 additions & 1 deletion addon/utils/widget.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function loadScript({propertyId = '', widgetId = '', embedId = '', basePath = 'tawk.to'}) {
function loadScript({propertyId = '', widgetId = '', embedId = '', basePath = 'tawk.to', autoStart = true}) {
if (embedId.length) {
/**
* If the element with embedId as id we will create a new clement
Expand All @@ -13,6 +13,10 @@ function loadScript({propertyId = '', widgetId = '', embedId = '', basePath = 't
window.Tawk_API.embedded = embedId;
}

if (!autoStart) {
window.Tawk_API.autoStart = autoStart;
}

const script = document.createElement('script');
script.async = true;
script.src = `https://embed.${basePath}/${propertyId}/${widgetId}`;
Expand Down
49 changes: 49 additions & 0 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Use the JavaScript API to manipulate the chat widget displayed on your website.
- [onTagsUpdated](#ontagsupdated)
- [onUnreadCountChanged](#onunreadcountchanged)
- [visitor](#visitor)
- [autoStart](#autostart)
- [start](#start)
- [shutdown](#shutdown)
- [maximize](#maximize)
- [minimize](#minimize)
- [toggle](#toggle)
Expand Down Expand Up @@ -457,6 +460,52 @@ this.tawkMessenger.visitor({

<br/>

## autoStart
If set to true, it will auto-start the Tawk socket connection for chat services. If set to false,
you will need to manually call the start API. It will not register and connect to the dashboard
if this is set to false.

```hbs
<TawkMessenger
@propertyId={{'property_id'}}
@widgetId={{'widget_id'}}
@autoStart={{false}}/>
```

<br/>

## start
Start the tawk socket connection.

```js
this.tawkMessenger.start();

// Example

@action
handleOnLoad() {
this.tawkMessenger.start();
}
```

<br/>

## shutdown
End the tawk socket connection.

```js
this.tawkMessenger.shutdown();

// Example

@action
handleOnLoad() {
this.tawkMessenger.shutdown();
}
```

<br/>

## maximize
Maximizes the chat widget.

Expand Down
Loading