@hellotext/hellotext 1.8.7 → 2.0.1
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 +27 -2
- package/dist/hellotext.js +1 -1
- package/index.d.ts +61 -0
- package/lib/api/businesses.cjs +37 -0
- package/lib/api/businesses.js +3 -9
- package/lib/api/events.cjs +45 -0
- package/lib/api/events.js +8 -14
- package/lib/api/forms.cjs +51 -0
- package/lib/api/forms.js +10 -17
- package/lib/api/index.cjs +51 -0
- package/lib/api/index.js +10 -23
- package/lib/api/response.cjs +76 -0
- package/lib/api/response.js +1 -7
- package/lib/api/submissions.cjs +47 -0
- package/lib/api/submissions.js +9 -17
- package/lib/api/webchat/messages.cjs +70 -0
- package/lib/api/webchat/messages.js +10 -18
- package/lib/api/webchats.cjs +44 -0
- package/lib/api/webchats.js +8 -16
- package/lib/builders/input_builder.cjs +61 -0
- package/lib/builders/input_builder.js +4 -11
- package/lib/builders/logo_builder.cjs +50 -0
- package/lib/builders/logo_builder.js +5 -12
- package/lib/channels/application_channel.cjs +67 -0
- package/lib/channels/application_channel.js +1 -8
- package/lib/channels/{web_chat_channel.js → webchat_channel.cjs} +35 -20
- package/lib/channels/webchat_channel.js +3 -11
- package/lib/controllers/form_controller.cjs +141 -0
- package/lib/controllers/form_controller.js +15 -22
- package/lib/controllers/mixins/usePopover.cjs +59 -0
- package/lib/controllers/mixins/usePopover.js +6 -14
- package/lib/controllers/{web_chat/pagination_controller.js → webchat/emoji_picker_controller.cjs} +74 -29
- package/lib/controllers/webchat/emoji_picker_controller.js +11 -17
- package/lib/controllers/webchat_controller.cjs +433 -0
- package/lib/controllers/webchat_controller.js +49 -51
- package/lib/core/configuration/forms.cjs +49 -0
- package/lib/core/configuration/forms.js +2 -8
- package/lib/core/configuration/{web_chat.js → webchat.cjs} +53 -38
- package/lib/core/configuration/webchat.js +2 -9
- package/lib/core/configuration.cjs +65 -0
- package/lib/core/configuration.js +8 -13
- package/lib/core/event.cjs +71 -0
- package/lib/core/event.js +5 -11
- package/lib/core/index.cjs +20 -0
- package/lib/core/index.js +2 -20
- package/lib/errors/index.cjs +19 -0
- package/lib/errors/index.js +2 -19
- package/lib/errors/invalid_event.cjs +34 -0
- package/lib/errors/invalid_event.js +1 -7
- package/lib/errors/not_initialized_error.cjs +34 -0
- package/lib/errors/not_initialized_error.js +1 -7
- package/lib/hellotext.cjs +153 -0
- package/lib/hellotext.js +19 -27
- package/lib/index.cjs +19 -0
- package/lib/index.js +11 -20
- package/lib/locales/en.cjs +22 -0
- package/lib/locales/en.js +2 -9
- package/lib/locales/es.cjs +22 -0
- package/lib/locales/es.js +2 -9
- package/lib/locales/index.cjs +14 -0
- package/lib/locales/index.js +6 -14
- package/lib/models/business.cjs +62 -0
- package/lib/models/business.js +22 -24
- package/lib/models/cookies.cjs +40 -0
- package/lib/models/cookies.js +3 -10
- package/lib/models/form.cjs +166 -0
- package/lib/models/form.js +10 -17
- package/lib/models/form_collection.cjs +122 -0
- package/lib/models/form_collection.js +18 -22
- package/lib/models/index.cjs +54 -0
- package/lib/models/index.js +7 -54
- package/lib/models/query.cjs +51 -0
- package/lib/models/query.js +3 -9
- package/lib/models/session.cjs +58 -0
- package/lib/models/session.js +12 -17
- package/lib/models/{web_chat.js → webchat.cjs} +14 -22
- package/lib/models/webchat.js +6 -13
- package/lib/vanilla.cjs +13 -0
- package/lib/vanilla.js +1 -13
- package/package.json +41 -7
- package/src/controllers/webchat_controller.js +72 -47
- package/src/hellotext.js +5 -4
- package/src/index.bundle.js +5 -0
- package/src/index.js +1 -3
- package/src/models/business.js +3 -6
- package/src/models/form_collection.js +10 -4
- package/src/models/session.js +4 -3
- package/styles/index.css +22 -30
- package/.babelrc +0 -24
- package/.github/workflows/ci.yml +0 -24
- package/.prettierignore +0 -3
- package/.prettierrc.json +0 -18
- package/MIT-LICENSE +0 -20
- package/__tests__/builders/input_builder_test.js +0 -117
- package/__tests__/core/configuration/forms_test.js +0 -30
- package/__tests__/core/configuration/webchat_test.js +0 -163
- package/__tests__/core/configuration_test.js +0 -28
- package/__tests__/core/event_test.js +0 -56
- package/__tests__/hellotext_test.js +0 -197
- package/__tests__/models/business_test.js +0 -26
- package/__tests__/models/cookies_test.js +0 -25
- package/__tests__/models/form_collection_test.js +0 -103
- package/__tests__/models/form_test.js +0 -131
- package/__tests__/models/query_test.js +0 -97
- package/docs/forms.md +0 -176
- package/docs/tracking.md +0 -203
- package/docs/webchat.md +0 -101
- package/jest.config.js +0 -4
- package/jest.setup.js +0 -16
- package/lib/api/web_chat/messages.js +0 -74
- package/lib/api/web_chats.js +0 -53
- package/webpack.config.js +0 -24
package/docs/tracking.md
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
## Tracking Events
|
|
2
|
-
|
|
3
|
-
Track subscriber events as they happen on your website and let Hellotext report them back to your business.
|
|
4
|
-
|
|
5
|
-
Tracking events is straightforward and perhaps the simplest example is tracking a page view:
|
|
6
|
-
|
|
7
|
-
```javascript
|
|
8
|
-
Hellotext.track('page.viewed')
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
In the example above only the name of the action is required.
|
|
12
|
-
|
|
13
|
-
### Handling Responses
|
|
14
|
-
|
|
15
|
-
The `track` method returns a Promise that can be `await`ed using the async/await syntax. Or using `.then` on the returned Promise.
|
|
16
|
-
|
|
17
|
-
```javascript
|
|
18
|
-
const response = await Hellotext.track('page.viewed')
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
The return of the `Hellotext.track` method is an instance of a `Response` object that ships with the package. You can check the status of the response via methods, like:
|
|
22
|
-
|
|
23
|
-
```javascript
|
|
24
|
-
if (response.failed) {
|
|
25
|
-
console.log('failed because', response.data)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (response.succeeded) {
|
|
29
|
-
console.log('success')
|
|
30
|
-
console.log(response.data) // { status: "received" }
|
|
31
|
-
}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### Parameters
|
|
35
|
-
|
|
36
|
-
The parameters passed to the action must be a valid set of parameters as described in
|
|
37
|
-
[Tracking Actions](https://www.hellotext.com/api#tracking).
|
|
38
|
-
|
|
39
|
-
#### URL Parameter
|
|
40
|
-
|
|
41
|
-
The library takes care of handling the `url` parameter with the current URL automatically and is not required to specify it explicitly.
|
|
42
|
-
If you want to provide another url, you can pass a `url` key in the params object when tracking an event.
|
|
43
|
-
|
|
44
|
-
```javascript
|
|
45
|
-
Hellotext.track('page.viewed', {
|
|
46
|
-
url: 'www.example.org',
|
|
47
|
-
})
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### Headers
|
|
51
|
-
|
|
52
|
-
You can add any custom or additional headers to the request by passing a `headers` object in the parameter.
|
|
53
|
-
|
|
54
|
-
```javascript
|
|
55
|
-
Hellotext.track('page.viewed', {
|
|
56
|
-
headers: {
|
|
57
|
-
'X-Custom-Header': 'value',
|
|
58
|
-
},
|
|
59
|
-
// event related parameters
|
|
60
|
-
})
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### Errors
|
|
64
|
-
|
|
65
|
-
Failing to provide valid set of parameters will result in an error object being returned, describing the parameters that did not satisfy the rules.
|
|
66
|
-
|
|
67
|
-
```javascript
|
|
68
|
-
const response = await Hellotext.track('app.installed', { object_parameters: { name: null } })
|
|
69
|
-
|
|
70
|
-
console.log(response.data)
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
yields
|
|
74
|
-
|
|
75
|
-
```javascript
|
|
76
|
-
{
|
|
77
|
-
errors: [
|
|
78
|
-
{
|
|
79
|
-
type: 'parameter_invalid_empty',
|
|
80
|
-
parameter: 'name',
|
|
81
|
-
description: 'This required parameter has an empty value. Provide a valid value for the parameter.',
|
|
82
|
-
},
|
|
83
|
-
]
|
|
84
|
-
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
For a complete list of errors types. See [Error Types](https://www.hellotext.com/api#errors)
|
|
88
|
-
|
|
89
|
-
### Event parameters
|
|
90
|
-
|
|
91
|
-
Every tracked event has the following parameters which you can pass to the `track` method:
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
| Property | Description | Type | Default |
|
|
95
|
-
| -------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -------- | ------- |
|
|
96
|
-
| **amount** | Monetary amount that represents the revenue associated to this tracked event. | float | `0` |
|
|
97
|
-
| **currency** | Currency for the `amount` given in ISO 4217 format. If not specified, the currency default to the business' configured reporting currency. | currency | `USD` |
|
|
98
|
-
| **metadata** | Set of key-value pairs that you can attach to an event. This can be useful for storing additional information about the object in a structured format. | hash | `{}` |
|
|
99
|
-
| **tracked_at** | Original date when the event happened. This is useful if you want to record an event that happened in the past. If no value is provided its value will be the same from `created_at`. | epoch | `null` |
|
|
100
|
-
|
|
101
|
-
### Associated object parameters
|
|
102
|
-
|
|
103
|
-
Generally, most actions also require an associated object. These can be of type [`app`](https://www.hellotext.com/api#apps), [`coupon`](https://www.hellotext.com/api#coupons), [`form`](https://www.hellotext.com/api#forms), [`order`](https://www.hellotext.com/api#orders), [`product`](https://www.hellotext.com/api#products) and [`refund`](https://www.hellotext.com/api#refunds), these events require an existing object to be present
|
|
104
|
-
in order to be tracked aside from [Custom Actions](https://www.hellotext.com/api#create_an_action), which don't require the trackable to be present.
|
|
105
|
-
|
|
106
|
-
Associated objects are represented by three possible parameters:
|
|
107
|
-
|
|
108
|
-
- `object`: An ID of an existing object of the same type. For example, when tracking app events, the `object` must be a previously created app object.
|
|
109
|
-
- `object_parameters`: A set of parameters for creating a new object of the same type. For example, when tracking app events, the `object_parameters` must be a set of parameters for creating a new app object.
|
|
110
|
-
- `object_type`: An ID or `name` of an existing custom object. Only required when tracking custom objects. Lets Hellotext know which type of object is being tracked. Learn more about [Objects](https://www.hellotext.com/api#objects).
|
|
111
|
-
|
|
112
|
-
You can create the associated object directly by defining its parameters in a hash:
|
|
113
|
-
|
|
114
|
-
```javascript
|
|
115
|
-
Hellotext.track('order.placed', {
|
|
116
|
-
amount: 395.0,
|
|
117
|
-
currency: 'USD',
|
|
118
|
-
object_parameters: {
|
|
119
|
-
reference: '654321',
|
|
120
|
-
source: 'myshop',
|
|
121
|
-
items: [
|
|
122
|
-
{
|
|
123
|
-
product: 'erA2RAXE',
|
|
124
|
-
quantity: 2,
|
|
125
|
-
}
|
|
126
|
-
]
|
|
127
|
-
},
|
|
128
|
-
})
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
If you want to reuse existing objects, you must pass the identifier of an existing associated object. For example, to track a product purchase the identifier of a previously created product object as the `product`.
|
|
132
|
-
For more information about identifiers, view the [Tracking API](https://www.hellotext.com/api#tracking)
|
|
133
|
-
|
|
134
|
-
```javascript
|
|
135
|
-
Hellotext.track('product.purchased', {
|
|
136
|
-
amount: 395.0,
|
|
137
|
-
currency: 'USD',
|
|
138
|
-
object: 'erA2RAXE',
|
|
139
|
-
})
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
## List of actions
|
|
143
|
-
|
|
144
|
-
The following is a complete list of built-in actions and their required associated objects. Each associated action accepts a possible set of two parameters
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
| Action | Description | Required Parameter |
|
|
149
|
-
| --------------------- | -------------------------------------------------------- |---------------------------------------------------------------------------|
|
|
150
|
-
| **app.installed** | An app was installed. | `object` or [object_parameters](https://www.hellotext.com/api#app) |
|
|
151
|
-
| **app.removed** | An app was removed. | `object` or [object_parameters](https://www.hellotext.com/api#app) |
|
|
152
|
-
| **app.spent** | A customer spent on an app. | `object` or [object_parameters](https://www.hellotext.com/api#app) |
|
|
153
|
-
| **cart.abandoned** | A cart was abandoned. | `object` or [object_parameters](https://www.hellotext.com/api#products) |
|
|
154
|
-
| **cart.added** | Added an item to the cart. | `object` or [object_parameters](https://www.hellotext.com/api#products) |
|
|
155
|
-
| **cart.removed** | Removed an item from the cart. | `object` or [object_parameters](https://www.hellotext.com/api#products) |
|
|
156
|
-
| **coupon.redeemed** | A coupon was redeem by a customer. | `object` or [object_parameters](https://www.hellotext.com/api#coupons) |
|
|
157
|
-
| **form.completed** | A form was completed by the customer. | `object` or [object_parameters](https://www.hellotext.com/api#forms) |
|
|
158
|
-
| **order.placed** | Order has been placed. | `object` or [object_parameters](https://www.hellotext.com/api#orders) |
|
|
159
|
-
| **order.confirmed** | Order has been confirmed by you. | `object` or [object_parameters](https://www.hellotext.com/api#orders) |
|
|
160
|
-
| **order.cancelled** | Order has been cancelled either by you or your customer. | `object` or [object_parameters](https://www.hellotext.com/api#orders) |
|
|
161
|
-
| **order.shipped** | Order has been shipped to your customer. | `object` or [object_parameters](https://www.hellotext.com/api#orders) |
|
|
162
|
-
| **order.delivered** | Order has been delivered to your customer. | `object` or [object_parameters](https://www.hellotext.com/api#orders) |
|
|
163
|
-
| **page.viewed** | A page was viewed by a customer. | `url` |
|
|
164
|
-
| **product.purchased** | A product has been purchased. | `object` or [object_parameters](https://www.hellotext.com/api#products) |
|
|
165
|
-
| **product.viewed** | A product page has been viewed. | `object` or [object_parameters](https://www.hellotext.com/api#products) |
|
|
166
|
-
| **refund.requested** | A customer requested a refund. | `object` or [object_parameters](https://www.hellotext.com/api#refunds) |
|
|
167
|
-
| **refund.received** | A refund was issued by you to your customer. | `object` or [object_parameters](https://www.hellotext.com/api#refunds) |
|
|
168
|
-
|
|
169
|
-
You can also create your **[own defined actions](https://www.hellotext.com/api#actions)**.
|
|
170
|
-
|
|
171
|
-
### Tracking Custom Actions
|
|
172
|
-
|
|
173
|
-
Once you have created a custom action, you track it by specifying the action's name. Custom actions do not require an associated object to be present in order to be tracked.
|
|
174
|
-
However, it's possible to track custom actions alongside existing Objects, or new objects you introduce.
|
|
175
|
-
|
|
176
|
-
```javascript
|
|
177
|
-
// Custom Action without an associated object
|
|
178
|
-
|
|
179
|
-
Hellotext.track('appointment.booked')
|
|
180
|
-
|
|
181
|
-
// Custom Action with an existing custom object instance.
|
|
182
|
-
|
|
183
|
-
Hellotext.track('appointment.booked', {
|
|
184
|
-
object_type: 'appointment',
|
|
185
|
-
object: 'erA2RAXE',
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
// Custom Action with a new custom object instance.
|
|
189
|
-
Hellotext.track('appointment.booked', {
|
|
190
|
-
object_type: 'appointment',
|
|
191
|
-
object_parameters: {
|
|
192
|
-
room: 'AA-101',
|
|
193
|
-
booked_at: 1632313200,
|
|
194
|
-
}
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
// Custom Action with a builtin object instance.
|
|
198
|
-
|
|
199
|
-
Hellotext.track('appointment.booked', {
|
|
200
|
-
object_type: 'product',
|
|
201
|
-
object: 'erA2RAXE',
|
|
202
|
-
})
|
|
203
|
-
```
|
package/docs/webchat.md
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
## Webchat
|
|
2
|
-
|
|
3
|
-
Hellotext allows you to build webchats via the dashboard and allow Hellotext.js to load a given webchat with
|
|
4
|
-
a specific ID and show it to the user. A webchat can be specified when initializing the library by passing a `webchat` property
|
|
5
|
-
to the configuration option.
|
|
6
|
-
|
|
7
|
-
```js
|
|
8
|
-
Hellotext.initialize('PUBLIC_BUSINESS_ID', {
|
|
9
|
-
webchat: {
|
|
10
|
-
id,
|
|
11
|
-
container,
|
|
12
|
-
placement,
|
|
13
|
-
classes,
|
|
14
|
-
triggerClasses,
|
|
15
|
-
style: {
|
|
16
|
-
primaryColor,
|
|
17
|
-
secondaryColor,
|
|
18
|
-
typography
|
|
19
|
-
},
|
|
20
|
-
behaviour,
|
|
21
|
-
}
|
|
22
|
-
})
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
| Property | Description | Type | Default |
|
|
26
|
-
|----------------|------------------------------------------------------------------------------------------------------------------------------------------|--------|----------------|
|
|
27
|
-
| id | The id of the webchat to load. **required** | String | null |
|
|
28
|
-
| container | The container to append the webchat to, must be a valid CSS selector. If none specified, the webchat is appended at the end of the body. | String | `body` |
|
|
29
|
-
| placement | The placement of the webchat, determined according to the parent `container`. | Enum | `bottom-right` |
|
|
30
|
-
| classes | An array or comma separated String of additional CSS classes to apply to the webchat popover. | String | null |
|
|
31
|
-
| triggerClasses | An array or comma separated String of additional CSS classes to apply to the webchat trigger. | String | null |
|
|
32
|
-
| style | Style overrides to the WebChat's style configuration as created on the dashboard. | Object | null |
|
|
33
|
-
| behaviour | The behaviour of the webchat when it is open and a click was made outside of it | Enum | `popover` |
|
|
34
|
-
|
|
35
|
-
### Position
|
|
36
|
-
|
|
37
|
-
The default position for a webchat is `bottom-right`, but you can specify any of the following values
|
|
38
|
-
|
|
39
|
-
- `bottom-left`
|
|
40
|
-
- `bottom-right`
|
|
41
|
-
- `top-left`
|
|
42
|
-
- `top-right`
|
|
43
|
-
|
|
44
|
-
### Style
|
|
45
|
-
|
|
46
|
-
The following properties are accepted for the `style` object.
|
|
47
|
-
|
|
48
|
-
- `primaryColor` - The primary color of the Webchat. Must be either in hex or rgb/a formats. Affects the following elements:
|
|
49
|
-
- Trigger background
|
|
50
|
-
- Popover header background
|
|
51
|
-
- Agent icon color
|
|
52
|
-
- Toolbar button hover
|
|
53
|
-
- Incoming message background
|
|
54
|
-
|
|
55
|
-
The primary color is controlled via a `--webchat-primary-color` CSS variable.
|
|
56
|
-
|
|
57
|
-
- `secondaryColor` - The secondary color of the webchat. Must be either in hex or rgb/a formats. Affects the following elements:
|
|
58
|
-
- Trigger icon color
|
|
59
|
-
- Popover header text color
|
|
60
|
-
- Agent icon background
|
|
61
|
-
- Incoming message text color
|
|
62
|
-
|
|
63
|
-
The secondary color is controlled via a `--webchat-secondary-color` CSS variable.
|
|
64
|
-
- `typography` - The font family to use for the webchat.
|
|
65
|
-
|
|
66
|
-
All properties accept a valid CSS value, for example, `primaryColor: '#EEEEEE'` or `secondaryColor: '#ff0000'`.
|
|
67
|
-
|
|
68
|
-
### behaviour
|
|
69
|
-
|
|
70
|
-
Determines how the webchat functions when it is open and a click is made outside of it. The following values are accepted.
|
|
71
|
-
|
|
72
|
-
- `popover` - Closes the webchat when a click is made outside of it. This is the default behaviour.
|
|
73
|
-
- `modal` - Prevents the webchat from closing when a click is made outside of it. The webchat can only be closed by clicking on the trigger.
|
|
74
|
-
|
|
75
|
-
### Events
|
|
76
|
-
|
|
77
|
-
The webchat emits the following events which can be listened to, to add an event listener you can `Hellotext.addEventListener(event, callback)`.
|
|
78
|
-
|
|
79
|
-
- `webchat:mounted` - Emitted when the webchat is mounted
|
|
80
|
-
- `webchat:opened` - Emitted when the webchat is opened
|
|
81
|
-
- `webchat:closed` - Emitted when the webchat is closed
|
|
82
|
-
|
|
83
|
-
- `webchat:message:sent` - Emitted when a message is sent by the user. The message is passed as an argument to the callback, containing the following properties
|
|
84
|
-
|
|
85
|
-
```javascript
|
|
86
|
-
{
|
|
87
|
-
id: 'xxxxxx'
|
|
88
|
-
body: 'The message the client sent',
|
|
89
|
-
attachments: [], // An array of File objects that reference the attachments the user sent.
|
|
90
|
-
}
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
- `webchat:message:received` - Emitted when a message is received by the webchat from Hellotext. The message is passed as an argument to the callback, containing the following properties
|
|
94
|
-
|
|
95
|
-
```javascript
|
|
96
|
-
{
|
|
97
|
-
id: 'xxxxxx',
|
|
98
|
-
body: 'The message the client received from Hellotext',
|
|
99
|
-
attachments: [], // An Array of URLs referencing the attachments the user received.
|
|
100
|
-
}
|
|
101
|
-
```
|
package/jest.config.js
DELETED
package/jest.setup.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
require('whatwg-fetch');
|
|
2
|
-
|
|
3
|
-
global.crypto.randomUUID = () => {
|
|
4
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
5
|
-
const r = (Math.random() * 16) | 0;
|
|
6
|
-
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
7
|
-
return v.toString(16);
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
global.fetch = jest.fn(() =>
|
|
12
|
-
Promise.resolve({
|
|
13
|
-
json: () => Promise.resolve({}),
|
|
14
|
-
text: () => Promise.resolve(''),
|
|
15
|
-
})
|
|
16
|
-
);
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _hellotext = _interopRequireDefault(require("../../hellotext"));
|
|
8
|
-
var _core = require("../../core");
|
|
9
|
-
var _response = require("../response");
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
12
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
13
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
15
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
16
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
17
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
18
|
-
var WebChatMessagesAPI = /*#__PURE__*/function () {
|
|
19
|
-
function WebChatMessagesAPI(webChatId) {
|
|
20
|
-
_classCallCheck(this, WebChatMessagesAPI);
|
|
21
|
-
this.webChatId = webChatId;
|
|
22
|
-
}
|
|
23
|
-
_createClass(WebChatMessagesAPI, [{
|
|
24
|
-
key: "index",
|
|
25
|
-
value: function () {
|
|
26
|
-
var _index = _asyncToGenerator(function* (params) {
|
|
27
|
-
var url = new URL(this.url);
|
|
28
|
-
Object.entries(params).forEach(_ref => {
|
|
29
|
-
var [key, value] = _ref;
|
|
30
|
-
url.searchParams.append(key, value);
|
|
31
|
-
});
|
|
32
|
-
return yield fetch(url, {
|
|
33
|
-
method: 'GET',
|
|
34
|
-
headers: _hellotext.default.headers
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
function index(_x) {
|
|
38
|
-
return _index.apply(this, arguments);
|
|
39
|
-
}
|
|
40
|
-
return index;
|
|
41
|
-
}()
|
|
42
|
-
}, {
|
|
43
|
-
key: "create",
|
|
44
|
-
value: function () {
|
|
45
|
-
var _create = _asyncToGenerator(function* (formData) {
|
|
46
|
-
var response = yield fetch(this.url, {
|
|
47
|
-
method: 'POST',
|
|
48
|
-
headers: {
|
|
49
|
-
Authorization: "Bearer ".concat(_hellotext.default.business.id)
|
|
50
|
-
},
|
|
51
|
-
body: formData
|
|
52
|
-
});
|
|
53
|
-
return new _response.Response(response.ok, response);
|
|
54
|
-
});
|
|
55
|
-
function create(_x2) {
|
|
56
|
-
return _create.apply(this, arguments);
|
|
57
|
-
}
|
|
58
|
-
return create;
|
|
59
|
-
}()
|
|
60
|
-
}, {
|
|
61
|
-
key: "url",
|
|
62
|
-
get: function get() {
|
|
63
|
-
return WebChatMessagesAPI.endpoint.replace(':id', this.webChatId);
|
|
64
|
-
}
|
|
65
|
-
}], [{
|
|
66
|
-
key: "endpoint",
|
|
67
|
-
get: function get() {
|
|
68
|
-
return _core.Configuration.endpoint("public/webchats/:id/messages");
|
|
69
|
-
}
|
|
70
|
-
}]);
|
|
71
|
-
return WebChatMessagesAPI;
|
|
72
|
-
}();
|
|
73
|
-
var _default = WebChatMessagesAPI;
|
|
74
|
-
exports.default = _default;
|
package/lib/api/web_chats.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _hellotext = _interopRequireDefault(require("../hellotext"));
|
|
8
|
-
var _core = require("../core");
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
11
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
12
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
14
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
15
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
16
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
17
|
-
var WebChatsAPI = /*#__PURE__*/function () {
|
|
18
|
-
function WebChatsAPI() {
|
|
19
|
-
_classCallCheck(this, WebChatsAPI);
|
|
20
|
-
}
|
|
21
|
-
_createClass(WebChatsAPI, null, [{
|
|
22
|
-
key: "endpoint",
|
|
23
|
-
get: function get() {
|
|
24
|
-
return _core.Configuration.endpoint('public/webchats');
|
|
25
|
-
}
|
|
26
|
-
}, {
|
|
27
|
-
key: "get",
|
|
28
|
-
value: function () {
|
|
29
|
-
var _get = _asyncToGenerator(function* (id) {
|
|
30
|
-
var url = new URL("".concat(this.endpoint, "/").concat(id));
|
|
31
|
-
url.searchParams.append('session', _hellotext.default.session);
|
|
32
|
-
Object.entries(_core.Configuration.webChat.style).forEach(_ref => {
|
|
33
|
-
var [key, value] = _ref;
|
|
34
|
-
url.searchParams.append("style[".concat(key, "]"), value);
|
|
35
|
-
});
|
|
36
|
-
url.searchParams.append('placement', _core.Configuration.webChat.placement);
|
|
37
|
-
var response = yield fetch(url, {
|
|
38
|
-
method: 'GET',
|
|
39
|
-
headers: _hellotext.default.headers
|
|
40
|
-
});
|
|
41
|
-
var htmlText = yield response.text();
|
|
42
|
-
return new DOMParser().parseFromString(htmlText, "text/html").querySelector('article');
|
|
43
|
-
});
|
|
44
|
-
function get(_x) {
|
|
45
|
-
return _get.apply(this, arguments);
|
|
46
|
-
}
|
|
47
|
-
return get;
|
|
48
|
-
}()
|
|
49
|
-
}]);
|
|
50
|
-
return WebChatsAPI;
|
|
51
|
-
}();
|
|
52
|
-
var _default = WebChatsAPI;
|
|
53
|
-
exports.default = _default;
|
package/webpack.config.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
mode: 'production',
|
|
3
|
-
entry: ['@hotwired/stimulus', './lib/index.js'],
|
|
4
|
-
output: {
|
|
5
|
-
filename: 'hellotext.js',
|
|
6
|
-
},
|
|
7
|
-
module: {
|
|
8
|
-
rules: [
|
|
9
|
-
{
|
|
10
|
-
test: /\.m?js$/,
|
|
11
|
-
exclude: [/node_modules/],
|
|
12
|
-
use: [
|
|
13
|
-
{
|
|
14
|
-
loader: 'babel-loader',
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
test: /\.css$/i,
|
|
20
|
-
use: ['style-loader', 'css-loader'],
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
},
|
|
24
|
-
}
|