@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 CHANGED
@@ -1,25 +1,91 @@
1
1
  # flood-webchat
2
2
 
3
- ## Development
4
- A demo server with hot module reloading can be started at http://localhost:9000 by running:
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 run dev
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
- ## How to Publish
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
- ### A Pre-Release
75
+ ```html
76
+
77
+ <div id="wc-availability">
78
+ <p>Webchat is not supported with your browser</p>
79
+ </div>
80
+ ```
13
81
 
14
- Via the GitHub GUI, create a release off your branch with a name matching a semver version pattern for the appropriate
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
- ### A Release
84
+ ```html
20
85
 
21
- Via the GitHub GUI, create a release off the main branch with a name matching a semver version pattern with the
22
- appropriate version bump. For example if the latest published version was `v1.2.3` and you wish to release:
23
- - a patch update, the new release should be called `v1.2.4`
24
- - a minor update, the new release should be called `v1.3.0`
25
- - a major update, the new release should be called `v2.0.0`
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
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ presets: [['@babel/preset-env', { targets: { node: 'current' } }]]
3
+ }