@tugitark/react-widget 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Widget.tsx +38 -0
- package/index.js +7 -0
- package/index.md +148 -0
- package/package.json +28 -0
package/Widget.tsx
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Copyright (c) 2026, TugiTark. All rights reserved.
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
|
|
6
|
+
import render, { Props } from '@tugitark/declarative-widget';
|
|
7
|
+
|
|
8
|
+
function Widget(props: Props) {
|
|
9
|
+
// Is this the first time this component has been rendered ever?
|
|
10
|
+
const [firstTime, setFirstTime] = useState(true);
|
|
11
|
+
|
|
12
|
+
function onNotification(hasNotification: boolean) {
|
|
13
|
+
if (props.jwtFn == null && props.user == null) {
|
|
14
|
+
if (firstTime) {
|
|
15
|
+
// Replicate FAQ internal behaviour at a per-component level.
|
|
16
|
+
props.onNotification?.(hasNotification);
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
props.onNotification?.(hasNotification);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function onReady() {
|
|
24
|
+
if (firstTime) {
|
|
25
|
+
setFirstTime(false);
|
|
26
|
+
props.onReady?.();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
render({ ...props, onReady, onNotification });
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<></>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default Widget;
|
|
38
|
+
|
package/index.js
ADDED
package/index.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
Tugi Tark React Widget Component
|
|
2
|
+
==================================
|
|
3
|
+
|
|
4
|
+
This library wraps the Tugi Tark chat widget in a standardised react component. The component internally handles loading the latest version of the widget script from our CDN and translates between the imperative API controlling the widget and the react data flow model to configure things based purely on properties and callbacks.
|
|
5
|
+
|
|
6
|
+
Minimal Example
|
|
7
|
+
-----------------
|
|
8
|
+
|
|
9
|
+
This is the smallest number of properties that you can pass to `<TugiWidget>` and have it still operate correctly.
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
import TugiWidget from '@tugitark/react-widget';
|
|
13
|
+
|
|
14
|
+
function Component(props) {
|
|
15
|
+
return (
|
|
16
|
+
<TugiWidget
|
|
17
|
+
user={props.userId}
|
|
18
|
+
brandId="a040050697fc4b2db16acfbbad1d0da4"
|
|
19
|
+
brandName="Super Casino"
|
|
20
|
+
tenantId="gb-casinos-ltd"
|
|
21
|
+
/>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
If your server has the standard `/.tugi` endpoints (as provided by our back-end libraries and documented in our [developer documentation](https://gitlab.com/tugitark/integration/docs)) this is enough to get started with the Tugi Widget. The `brandId`, `brandName`, and `tenantId` will be provided by us based on details provided by you when signing up with our system. They are not secret, so can safely appear in client-side code, but are case-sensitive so must remain exactly as specified by us.
|
|
27
|
+
|
|
28
|
+
`user` is the ID within your system of the current player. How you determine the current player's unique ID depends entirely on your system and is left as a provided parameter here. This is the ID that the widget will internally pass to the `/.tugi/jwt/issue` endpoint to retrieve the player's profile, and so must in some way identify an end-user on your server.
|
|
29
|
+
|
|
30
|
+
Custom Example
|
|
31
|
+
----------------
|
|
32
|
+
|
|
33
|
+
This is a more extensive widget example, with colour-scheme customisation and an explicit JWT lookup function. The HTTP and websocket addresses are also specified, though match the defaults.
|
|
34
|
+
|
|
35
|
+
```javascript
|
|
36
|
+
import TugiWidget from '@tugitark/react-widget';
|
|
37
|
+
|
|
38
|
+
interface Props {
|
|
39
|
+
getUserId: () => string;
|
|
40
|
+
isLoggedIn: () => boolean;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function Component(props: Props) {
|
|
44
|
+
async function jwtFn() {
|
|
45
|
+
if (!props.isLoggedIn()) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const jwt = await fetch('/get-jwt-for-player/' + props.getUserId());
|
|
49
|
+
return jwt;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<TugiWidget
|
|
54
|
+
jwtFn={jwtFn}
|
|
55
|
+
brandId="a040050697fc4b2db16acfbbad1d0da4"
|
|
56
|
+
brandName="Super Casino"
|
|
57
|
+
tenantId="gb-casinos-ltd"
|
|
58
|
+
httpUrl="https://app.tugi.ai/tugi.widget"
|
|
59
|
+
wsUrl="wss://ws.tugi.ai"
|
|
60
|
+
customize={{
|
|
61
|
+
title: 'Tugi Casino Help',
|
|
62
|
+
showTitle: true,
|
|
63
|
+
fontColor: '#2c3e50',
|
|
64
|
+
primaryColor: '#2c3e50',
|
|
65
|
+
secondaryColor: 'hsla(36, 100%, 50%, 1)',
|
|
66
|
+
homePageBackgroundColor: 'hsla(36, 100%, 37%, 0.2)',
|
|
67
|
+
homePageTextColor: '#2c3e50',
|
|
68
|
+
}}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
All Full Version Properties
|
|
75
|
+
-----------------------------
|
|
76
|
+
|
|
77
|
+
The full list of properties that can be passed to the `<TugiWidget>` component are:
|
|
78
|
+
|
|
79
|
+
* `user` Optional. When given will be used to look up a player's data from the server. You can disable this automatic lookup by passing a custom `jwtFn` or by not passing the `user` parameter. However, if you specify neither `user` nor `jwtFn` then the player will not be able to send any messages to Tugi Tark and you will get the free version of the widget instead (see below).
|
|
80
|
+
* `jwtFn` Optional. A function to override the default method for retrieving a player's data (via JWT). While this and `user` are both optional, one of them must be specified.
|
|
81
|
+
* `brandId` Required. The ID of your brand, as provided by Tugi Tark.
|
|
82
|
+
* `brandName` Required. The name of your brand, as provided by you initially.
|
|
83
|
+
* `tenantId` Required. The ID of your company, as provided by Tugi Tark.
|
|
84
|
+
* `language` Optional. The player's language, for messages to be translated.
|
|
85
|
+
* `httpUrl` Optional. The address of the Tugi Tark backend to connect to.
|
|
86
|
+
* `wsUrl` Optional. The address of the Tugi Tark websocket to connect to.
|
|
87
|
+
* `customize` Optional. An object of CSS options for tweaking the visual appearance of the widget. The complete set of configuration values in this object are documented elsewhere.
|
|
88
|
+
* `onNotification` Optional. An event callback triggered when a player recieves a new message.
|
|
89
|
+
* `onReady` Optional. An event callback triggered when the widget is fully initialised.
|
|
90
|
+
* `onOpened` Optional. An event callback triggered when the widget is opened up.
|
|
91
|
+
* `onClosed` Optional. An event callback triggered when the widget is hidden again.
|
|
92
|
+
* `onError` Optional. An event callback triggered when an error occurs. If this is not given all errors are printed to the console.
|
|
93
|
+
* `open` Optional. When `true` the widget is forced to be open. When `false` it is forced to be closed. When not specified normal user control resumes.
|
|
94
|
+
* `visible` Optional. When `false` the widget can't be seen.
|
|
95
|
+
|
|
96
|
+
The following two properties should all be specified together. If either of them is missing then nothing will happen:
|
|
97
|
+
|
|
98
|
+
* `proactiveMessage` Optional. When specified will open a new ticket with this as the first message. Requires `proactiveContext`.
|
|
99
|
+
* `proactiveContext` Optional. When specified will open a new ticket and pass this information to the backend as to why the ticket was created. Requires `proactiveMessage`.
|
|
100
|
+
* `ticketLanguageCode` Optional. Can specify that the newly created ticket uses a different language to the widget language from `langauge`.
|
|
101
|
+
|
|
102
|
+
A "proactive" message can be used to detect that a player has a problem and offer help without them needing to open a support ticket themselves. `proactiveMessage` would contain a pleasant greeting for the player such as "Hi, we've noticed you're having some touble with your deposit, would you like to speak to one of our agents?", while `proactiveContext` actually contains the details of the detected error that needs solving, such as "£100 deposit from card **********3429 was rejected twice, at 18:43 and 19:11. Error: Insufficient funds."
|
|
103
|
+
|
|
104
|
+
Free Version
|
|
105
|
+
--------------
|
|
106
|
+
|
|
107
|
+
If both `tugiFn` and `user` are missing from the `<TugiWidget>` properties then the widget goes in to the special free mode (more accurately, both must be `null` or `undefined` - if you want a user who isn't logged in pass a `user` of `''`). In this mode the user cannot send or receive any messages, they can only view a few pre-defined FAQ-style help topics:
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
import TugiWidget from '@tugitark/react-widget';
|
|
111
|
+
|
|
112
|
+
function Component(props) {
|
|
113
|
+
return (
|
|
114
|
+
<TugiWidget
|
|
115
|
+
chatDisabledReason="You are not signed in."
|
|
116
|
+
title="FAQ"
|
|
117
|
+
body="Let us help you get started."
|
|
118
|
+
sections={[
|
|
119
|
+
{ title: 'Who are we?', content: 'We are Tugi Tark.' },
|
|
120
|
+
{ title: 'What do we do?', content: 'Make awesome customer support solutions.' },
|
|
121
|
+
{ title: 'How?', content: 'Smart AI agents who know all about your customers and services.' },
|
|
122
|
+
{ title: 'How do I join?', content: 'Click the sign-up botton at the top-right of the page.' },
|
|
123
|
+
]}
|
|
124
|
+
/>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
All Free Version Properties
|
|
130
|
+
-----------------------------
|
|
131
|
+
|
|
132
|
+
* `chatDisabledReason` Required. Why is this user not allowed to see the full chat widget, only this reduced version?
|
|
133
|
+
* `title` Required. What to put in the top bar of the widget.
|
|
134
|
+
* `body` Required. The main text to put in the widget.
|
|
135
|
+
* `sections` Required. An array of questions and answers (or other grouped data). `title` is the "question", `content` is the "answer".
|
|
136
|
+
|
|
137
|
+
The following optional properties are shared with the full version:
|
|
138
|
+
|
|
139
|
+
* `customize`
|
|
140
|
+
* `onNotification`
|
|
141
|
+
* `onReady`
|
|
142
|
+
* `onOpened`
|
|
143
|
+
* `onClosed`
|
|
144
|
+
* `onError`
|
|
145
|
+
* `open`
|
|
146
|
+
* `visible`
|
|
147
|
+
|
|
148
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tugitark/react-widget",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Wraps the tugitark widget in a React component.",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"release": "npm publish --access public"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"Widget.tsx",
|
|
10
|
+
"index.js",
|
|
11
|
+
"index.md"
|
|
12
|
+
],
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@tugitark/declarative-widget": "^1.0.0",
|
|
15
|
+
"react": ">=16.3.0"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"Typescript",
|
|
19
|
+
"React",
|
|
20
|
+
"Tugitark",
|
|
21
|
+
"Casino",
|
|
22
|
+
"Integration",
|
|
23
|
+
"JWT",
|
|
24
|
+
"Library"
|
|
25
|
+
],
|
|
26
|
+
"author": "alex.cole@tugitark.com",
|
|
27
|
+
"license": "(c) 2026 Tugi Tark OÜ"
|
|
28
|
+
}
|