@defra/flood-webchat 0.0.1-alpha.1 → 0.0.1-alpha.10
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/README.md +81 -15
- package/assets/audio/notification.mp3 +0 -0
- package/babel.config.cjs +3 -0
- package/dist/templates.js +554 -0
- package/docs/assets/create-a-new-release.png +0 -0
- package/docs/assets/example-pre-release.png +0 -0
- package/docs/assets/example-release.png +0 -0
- package/docs/development-guide.md +6 -0
- package/docs/how-to-publish.md +41 -0
- package/main.scss +748 -0
- package/package.json +23 -8
- package/src/client/index.js +14 -0
- package/src/client/lib/availability.js +75 -0
- package/src/client/lib/config.js +17 -0
- package/src/client/lib/keyboard.js +149 -0
- package/src/client/lib/notification.js +59 -0
- package/src/client/lib/nunjucks.js +3 -0
- package/src/client/lib/panel.js +293 -0
- package/src/client/lib/provider.js +11 -0
- package/src/client/lib/skiplink.js +27 -0
- package/src/client/lib/state.js +82 -0
- package/src/client/lib/transcript.js +34 -0
- package/src/client/lib/utils.js +190 -0
- package/src/client/lib/webchat.js +1073 -0
- package/src/server/client.js +72 -0
- package/src/server/index.js +46 -0
- package/src/server/utils.js +19 -0
- package/src/style/_mixins.scss +13 -0
- package/src/browser.mjs +0 -3
- package/src/main.mjs +0 -0
package/README.md
CHANGED
|
@@ -1,25 +1,91 @@
|
|
|
1
1
|
# flood-webchat
|
|
2
2
|
|
|
3
|
-
##
|
|
4
|
-
|
|
3
|
+
## Useful Links
|
|
4
|
+
|
|
5
|
+
- [Development Guide](./docs/development-guide.md)
|
|
6
|
+
- [How to Publish](./docs/how-to-publish.md)
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
### Installation
|
|
11
|
+
|
|
12
|
+
Run:
|
|
5
13
|
|
|
6
14
|
```shell
|
|
7
|
-
npm
|
|
15
|
+
npm i @defra/flood-webchat
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Assets
|
|
19
|
+
|
|
20
|
+
You need to copy `./assets/audio/notification.mp3` to your 'assets' directory. This is the notification sound users will
|
|
21
|
+
hear when they receive a message.
|
|
22
|
+
|
|
23
|
+
### Server Side Javascript
|
|
24
|
+
|
|
25
|
+
You will need to implement an endpoint on your server which checks the availability of webchat. An express example can
|
|
26
|
+
be seen below:
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
|
|
30
|
+
import getAvailability from '@defra/flood-webchat'
|
|
31
|
+
//... the rest of your server setup
|
|
32
|
+
const webchatOptions = {
|
|
33
|
+
clientId: process.env.CXONE_CLIENT_ID,
|
|
34
|
+
clientSecret: process.env.CXONE_CLIENT_SECRET,
|
|
35
|
+
accessKey: process.env.CXONE_ACCESS_KEY,
|
|
36
|
+
accessSecret: process.env.CXONE_ACCESS_SECRET,
|
|
37
|
+
skillEndpoint: process.env.CXONE_SKILL_ENDPOINT,
|
|
38
|
+
hoursEndpoint: process.env.CXONE_HOURS_ENDPOINT,
|
|
39
|
+
maxQueueCount: process.env.CXONE_MAX_QUEUE_COUNT
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
app.get('/webchat-availability', async (req, res, next) => {
|
|
43
|
+
try {
|
|
44
|
+
const response = await getAvailability(webchatOptions)
|
|
45
|
+
return res.status(200).json(response)
|
|
46
|
+
} catch (err) {
|
|
47
|
+
next(err)
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Client Side Javascript
|
|
53
|
+
|
|
54
|
+
You will also need to initialise webchat in your client side code:
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
import * as webchat from '@defra/flood-webchat';
|
|
58
|
+
|
|
59
|
+
if (document.getElementById('wc-availability')) {
|
|
60
|
+
webchat.init('wc-availability', {
|
|
61
|
+
brandId: 'your brand id',
|
|
62
|
+
channelId: 'your channel id',
|
|
63
|
+
environmentName: 'your environment name',
|
|
64
|
+
availabilityEndpoint: '/webchat-availability',
|
|
65
|
+
audioUrl: 'path/to/notification.mp3'
|
|
66
|
+
})
|
|
67
|
+
}
|
|
8
68
|
```
|
|
9
69
|
|
|
10
|
-
|
|
70
|
+
### HTML
|
|
71
|
+
|
|
72
|
+
In your html, will need to add the "Start Chat" link with some placeholder text for if webchat is not supported in the
|
|
73
|
+
user's browser.
|
|
11
74
|
|
|
12
|
-
|
|
75
|
+
```html
|
|
76
|
+
|
|
77
|
+
<div id="wc-availability">
|
|
78
|
+
<p>Webchat is not supported with your browser</p>
|
|
79
|
+
</div>
|
|
80
|
+
```
|
|
13
81
|
|
|
14
|
-
|
|
15
|
-
version with an added pre-release identifier, and check the pre-release identifier.
|
|
16
|
-
For example if the latest published version was `v1.2.3` and you wish to publish a pre-release from your "cool-update"
|
|
17
|
-
branch, name the release: `v1.2.4-cool-update.1`
|
|
82
|
+
And finally a script tag, to prevent the webchat widget "flashing" on page load/reload.
|
|
18
83
|
|
|
19
|
-
|
|
84
|
+
```html
|
|
20
85
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
86
|
+
<script>
|
|
87
|
+
if (window.location.hash === '#webchat' && window.matchMedia('(max-width: 640px)').matches) {
|
|
88
|
+
document.body.classList.add('wc-hidden')
|
|
89
|
+
}
|
|
90
|
+
</script>
|
|
91
|
+
```
|
|
Binary file
|
package/babel.config.cjs
ADDED