@askdialog/dialog-sdk 1.0.0 → 1.0.2
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 +93 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
|
-
# Dialog
|
|
1
|
+
# Dialog SDK
|
|
2
|
+
|
|
3
|
+
## Dialog
|
|
4
|
+
|
|
5
|
+
Dialog is an AI assistant designed to boost e-commerce sales by providing intelligent product recommendations and seamless customer interactions.
|
|
6
|
+
|
|
7
|
+
Visit our website: [Dialog AI Assistant](https://www.askdialog.com/)
|
|
8
|
+
|
|
9
|
+
Need to see it in action? [Request one here](https://w1rsh3lwqfo.typeform.com/to/VxHL0RBR?typeform-source=dialog-sdk)
|
|
2
10
|
|
|
3
11
|
## Description
|
|
4
12
|
|
|
5
|
-
Dialog
|
|
13
|
+
Dialog SDK is a powerful TypeScript library that seamlessly integrates the Dialog AI assistant into your applications. It provides a comprehensive set of tools for managing assistant interactions, handling e-commerce operations like product fetching and cart management, and customizing the assistant's appearance to match your brand.
|
|
14
|
+
|
|
15
|
+
## Get started
|
|
16
|
+
|
|
17
|
+
### Prerequisites
|
|
18
|
+
|
|
19
|
+
Before using the Dialog SDK, you need:
|
|
6
20
|
|
|
7
|
-
|
|
21
|
+
- An active API Key, you can retrieve your api key in your [organization settings](https://app.askdialog.com/settings)
|
|
22
|
+
|
|
23
|
+
### Installation
|
|
8
24
|
|
|
9
25
|
```bash
|
|
10
26
|
npm install @dialog/dialog-sdk
|
|
@@ -14,9 +30,78 @@ pnpm add @dialog/dialog-sdk
|
|
|
14
30
|
yarn add @dialog/dialog-sdk
|
|
15
31
|
```
|
|
16
32
|
|
|
17
|
-
|
|
33
|
+
### Instantiate the client
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { Dialog } from '@dialog/dialog-sdk';
|
|
37
|
+
|
|
38
|
+
const client = new Dialog({
|
|
39
|
+
apiKey: 'YOUR_API_KEY', // required
|
|
40
|
+
locale: 'TARGETED_LOCALE', // required
|
|
41
|
+
callbacks: {
|
|
42
|
+
addToCart: () => Promise<void>, // required
|
|
43
|
+
getProduct: () => Promise<Product>, // required
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The apiKey is required to authenticate with our API and interact with our assistant.
|
|
49
|
+
The locale specifies the language you want to use.
|
|
50
|
+
The addToCart function is triggered when a user clicks the AddToCart button.
|
|
51
|
+
The getProduct function is used to display product information in the assistant.
|
|
52
|
+
|
|
53
|
+
### Features
|
|
18
54
|
|
|
19
|
-
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
55
|
+
- Send a message with context
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
client.sendProductMessage({
|
|
59
|
+
question: 'YOUR_QUESTION', // required
|
|
60
|
+
productId: 'PRODUCT_ID', // required
|
|
61
|
+
productTitle: 'PRODUCT_TITLE', // required
|
|
62
|
+
answer: '', // Optional
|
|
63
|
+
selectedVariantId?: 'CURRENT_VARIANT_ID', // Optional
|
|
64
|
+
})
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
- Send message without context
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
client.sendGenericMessage({
|
|
71
|
+
question: 'YOUR_QUESTION', // required
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
- Handler for fetch product
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const client = new Dialog({
|
|
79
|
+
...,
|
|
80
|
+
callbacks: {
|
|
81
|
+
getProduct: () => {
|
|
82
|
+
// Call your api to retrieve product information
|
|
83
|
+
const response = await fetch('....');
|
|
84
|
+
const data = await response.json();
|
|
85
|
+
// To define
|
|
86
|
+
return {};
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
- Handler for add to cart
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
const client = new Dialog({
|
|
96
|
+
...,
|
|
97
|
+
callbacks: {
|
|
98
|
+
addToCart: () => {
|
|
99
|
+
// Call your api to trigger addToCart
|
|
100
|
+
const response = await fetch('....');
|
|
101
|
+
|
|
102
|
+
// Trigger other stuff like confirmation modal
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
```
|