From 5123fe15962097060fee69fb7ad360d370b5da04 Mon Sep 17 00:00:00 2001 From: Jerald Austero Date: Fri, 10 Nov 2023 00:35:11 +0800 Subject: [PATCH 1/7] Add new API start, shutdown, autoStart --- addon/services/tawk-messenger.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addon/services/tawk-messenger.js b/addon/services/tawk-messenger.js index cd2be3f..719f4b1 100644 --- a/addon/services/tawk-messenger.js +++ b/addon/services/tawk-messenger.js @@ -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(); } From 051b4da3c69f56e3c28d57d5ff6a294c450a30a9 Mon Sep 17 00:00:00 2001 From: Jerald Austero Date: Fri, 10 Nov 2023 00:35:17 +0800 Subject: [PATCH 2/7] Update API Docs --- docs/api-reference.md | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/docs/api-reference.md b/docs/api-reference.md index 30dcbf0..5387378 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -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) @@ -457,6 +460,57 @@ this.tawkMessenger.visitor({
+## 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. + +```js +module.exports = function (environment) { + let ENV = { + ... + tawkMessenger : { + autoStart : false + } + ... + } +}; +``` + +
+ +## start +Start the tawk socket connection. + +```js +this.tawkMessenger.start(); + +// Example + +@action +handleOnLoad() { + this.tawkMessenger.start(); +} +``` + +
+ +## shutdown +End the tawk socket connection. + +```js +this.tawkMessenger.shutdown(); + +// Example + +@action +handleOnLoad() { + this.tawkMessenger.shutdown(); +} +``` + +
+ ## maximize Maximizes the chat widget. From 33d7b5000129e33362146681b1c2d8757a251865 Mon Sep 17 00:00:00 2001 From: Jerald Austero Date: Fri, 10 Nov 2023 00:36:50 +0800 Subject: [PATCH 3/7] Update autoStart --- addon/services/tawk-messenger.js | 4 ++++ docs/api-reference.md | 10 +--------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/addon/services/tawk-messenger.js b/addon/services/tawk-messenger.js index 719f4b1..4206291 100644 --- a/addon/services/tawk-messenger.js +++ b/addon/services/tawk-messenger.js @@ -99,6 +99,10 @@ export default class TawkMessenger extends Service { /** * API for setting a data on the widget */ + autoStart(enable) { + window.Tawk_API.autoStart = enable; + } + visitor(data) { window.Tawk_API.visitor = data; } diff --git a/docs/api-reference.md b/docs/api-reference.md index 5387378..6979447 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -466,15 +466,7 @@ you will need to manually call the start API. It will not register and connect t if this is set to false. ```js -module.exports = function (environment) { - let ENV = { - ... - tawkMessenger : { - autoStart : false - } - ... - } -}; +this.tawkMessenger.autoStart(false); ```
From a3b4b8835a5796111b83d420b3cc3e21f392bed7 Mon Sep 17 00:00:00 2001 From: Jerald Austero Date: Fri, 10 Nov 2023 08:43:34 +0800 Subject: [PATCH 4/7] Update autoStart --- addon/utils/widget.js | 6 +++++- docs/api-reference.md | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/addon/utils/widget.js b/addon/utils/widget.js index 04f99a3..6cda008 100644 --- a/addon/utils/widget.js +++ b/addon/utils/widget.js @@ -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 @@ -21,6 +21,10 @@ function loadScript({propertyId = '', widgetId = '', embedId = '', basePath = 't const firstScript = document.getElementsByTagName('script')[0]; firstScript.parentNode.insertBefore(script, firstScript); + + if (autoStart) { + window.Tawk_API.autoStart = autoStart; + } } export { diff --git a/docs/api-reference.md b/docs/api-reference.md index 6979447..922b738 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -465,8 +465,11 @@ If set to true, it will auto-start the Tawk socket connection for chat services. you will need to manually call the start API. It will not register and connect to the dashboard if this is set to false. -```js -this.tawkMessenger.autoStart(false); +```hbs + ```
From a9258732a060d2982a0fc38f805e6e4f9457a70e Mon Sep 17 00:00:00 2001 From: Jerald Austero Date: Fri, 10 Nov 2023 08:47:23 +0800 Subject: [PATCH 5/7] Update autoStart --- addon/components/tawk-messenger.js | 1 + 1 file changed, 1 insertion(+) diff --git a/addon/components/tawk-messenger.js b/addon/components/tawk-messenger.js index 6dda557..3b19810 100644 --- a/addon/components/tawk-messenger.js +++ b/addon/components/tawk-messenger.js @@ -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 }); /** From b7b97c5164478e4fd9d18e64843d7b6e8cdd9dc8 Mon Sep 17 00:00:00 2001 From: Jerald Austero Date: Fri, 10 Nov 2023 08:54:42 +0800 Subject: [PATCH 6/7] Update autoStart --- addon/services/tawk-messenger.js | 4 ---- addon/utils/widget.js | 8 ++++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/addon/services/tawk-messenger.js b/addon/services/tawk-messenger.js index 4206291..719f4b1 100644 --- a/addon/services/tawk-messenger.js +++ b/addon/services/tawk-messenger.js @@ -99,10 +99,6 @@ export default class TawkMessenger extends Service { /** * API for setting a data on the widget */ - autoStart(enable) { - window.Tawk_API.autoStart = enable; - } - visitor(data) { window.Tawk_API.visitor = data; } diff --git a/addon/utils/widget.js b/addon/utils/widget.js index 6cda008..8843dc2 100644 --- a/addon/utils/widget.js +++ b/addon/utils/widget.js @@ -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}`; @@ -21,10 +25,6 @@ function loadScript({propertyId = '', widgetId = '', embedId = '', basePath = 't const firstScript = document.getElementsByTagName('script')[0]; firstScript.parentNode.insertBefore(script, firstScript); - - if (autoStart) { - window.Tawk_API.autoStart = autoStart; - } } export { From d0d55c0e440f3c271789df19d5fcea3acb102f8a Mon Sep 17 00:00:00 2001 From: Jerald Austero Date: Mon, 13 Nov 2023 17:50:41 +0800 Subject: [PATCH 7/7] Add only autoStart when disabled --- addon/utils/widget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/utils/widget.js b/addon/utils/widget.js index 8843dc2..103831e 100644 --- a/addon/utils/widget.js +++ b/addon/utils/widget.js @@ -13,7 +13,7 @@ function loadScript({propertyId = '', widgetId = '', embedId = '', basePath = 't window.Tawk_API.embedded = embedId; } - if (autoStart) { + if (!autoStart) { window.Tawk_API.autoStart = autoStart; }