Skip to content
Merged
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
79 changes: 77 additions & 2 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Use the JavaScript API to manipulate the chat widget displayed on your website.
<br/>

## Table of contents
<<<<<<< HEAD
- [API Reference](#api-reference)
- [Table of contents](#table-of-contents)
- [onLoad](#onload)
Expand All @@ -36,6 +35,9 @@ Use the JavaScript API to manipulate the chat widget displayed on your website.
- [onBeforeLoaded](#onbeforeloaded)
- [widgetPosition](#widgetposition)
- [visitor](#visitor)
- [autoStart](#autostart)
- [start](#start)
- [shutdown](#shutdown)
- [maximize](#maximize)
- [minimize](#minimize)
- [toggle](#toggle)
Expand All @@ -60,7 +62,6 @@ Use the JavaScript API to manipulate the chat widget displayed on your website.
- [customstyle](#customstyle)
- [zIndex](#zindex)
- [Visibility](#visibility)
>>>>>>> main

<br/>

Expand Down Expand Up @@ -611,6 +612,80 @@ function App() {

<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.

```js
import TawkMessengerReact from '@tawk.to/tawk-messenger-react';

function App() {
return (
<div className="App">
<TawkMessengerReact
propertyId="property_id"
widgetId="default"
autoStart={false}/>
</div>
);
}
```

<br/>

## start
Start the tawk socket connection.

```js
tawkMessengerRef.current.start();

// Example

function App() {
const tawkMessengerRef = useRef();

const startTawk = () => {
tawkMessengerRef.current.start();
};

return (
<div>
<TawkMessengerReact
ref={tawkMessengerRef}/>
</div>
);
}
```

<br/>

## shutdown
End the tawk socket connection.

```js
tawkMessengerRef.current.shutdown();

// Example

function App() {
const tawkMessengerRef = useRef();

const shutdownTawk = () => {
tawkMessengerRef.current.shutdown();
};

return (
<div>
<TawkMessengerReact
ref={tawkMessengerRef}/>
</div>
);
}
```

<br/>

## maximize
Maximizes the chat widget.

Expand Down
11 changes: 10 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const TawkMessenger = forwardRef((props, ref) => {
propertyId : props.propertyId,
widgetId : props.widgetId,
embedId : props.embedId,
basePath : props.basePath
basePath : props.basePath,
autoStart : props.autoStart
});

/**
Expand All @@ -62,6 +63,14 @@ const TawkMessenger = forwardRef((props, ref) => {
/**
* 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 src/utils/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/**
* @param {Object} - Tawk widget required properties

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param {Object} - Tawk widget required properties
* @param {Object} - Tawk widget required properties https://tawk.to/chat/61c89ef380b2296cfdd3dbee/1ig5ooitr

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param {Object} - Tawk widget required properties
* @param {Object} - Tawk widget required properties https://tawk.to/chat/61c89ef380b2296cfdd3dbee/1ig5ooitr

*/
const loadScript = ({propertyId = '', widgetId = '', embedId = '', basePath = 'tawk.to'}) => {
const 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 @@ -19,6 +19,10 @@ const 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