@botpress/webchat-client 0.1.1 → 0.2.0-beta.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.
@@ -0,0 +1,219 @@
1
+ export type MessageStatusChanged = {
2
+ type: 'message_status_changed'
3
+ data: {
4
+ /**
5
+ * The Message object represents a message in a [Conversation](#schema_conversation) for a specific [User](#schema_user).
6
+ */
7
+ message: {
8
+ /**
9
+ * Id of the [Message](#schema_message)
10
+ */
11
+ id: string
12
+ /**
13
+ * Creation date of the [Message](#schema_message) in ISO 8601 format
14
+ */
15
+ createdAt: string
16
+ /**
17
+ * Payload is the content of the message.
18
+ */
19
+ payload:
20
+ | {
21
+ audioUrl: string
22
+ type: 'audio'
23
+ [k: string]: any
24
+ }
25
+ | {
26
+ title: string
27
+ subtitle?: string
28
+ imageUrl?: string
29
+ actions: {
30
+ action: 'postback' | 'url' | 'say'
31
+ label: string
32
+ value: string
33
+ [k: string]: any
34
+ }[]
35
+ type: 'card'
36
+ [k: string]: any
37
+ }
38
+ | {
39
+ items: {
40
+ title: string
41
+ subtitle?: string
42
+ imageUrl?: string
43
+ actions: {
44
+ action: 'postback' | 'url' | 'say'
45
+ label: string
46
+ value: string
47
+ [k: string]: any
48
+ }[]
49
+ [k: string]: any
50
+ }[]
51
+ type: 'carousel'
52
+ [k: string]: any
53
+ }
54
+ | {
55
+ text: string
56
+ options: {
57
+ label: string
58
+ value: string
59
+ [k: string]: any
60
+ }[]
61
+ disableFreeText?: boolean
62
+ type: 'choice'
63
+ [k: string]: any
64
+ }
65
+ | {
66
+ text: string
67
+ options: {
68
+ label: string
69
+ value: string
70
+ [k: string]: any
71
+ }[]
72
+ disableFreeText?: boolean
73
+ type: 'dropdown'
74
+ [k: string]: any
75
+ }
76
+ | {
77
+ fileUrl: string
78
+ title?: string
79
+ type: 'file'
80
+ [k: string]: any
81
+ }
82
+ | {
83
+ imageUrl: string
84
+ type: 'image'
85
+ [k: string]: any
86
+ }
87
+ | {
88
+ latitude: number
89
+ longitude: number
90
+ address?: string
91
+ title?: string
92
+ type: 'location'
93
+ [k: string]: any
94
+ }
95
+ | {
96
+ text: string
97
+ value?: string
98
+ type: 'text'
99
+ [k: string]: any
100
+ }
101
+ | {
102
+ videoUrl: string
103
+ type: 'video'
104
+ [k: string]: any
105
+ }
106
+ | {
107
+ items: (
108
+ | {
109
+ type: 'text'
110
+ payload: {
111
+ text: string
112
+ value?: string
113
+ [k: string]: any
114
+ }
115
+ [k: string]: any
116
+ }
117
+ | {
118
+ type: 'markdown'
119
+ payload: {
120
+ markdown: string
121
+ [k: string]: any
122
+ }
123
+ [k: string]: any
124
+ }
125
+ | {
126
+ type: 'image'
127
+ payload: {
128
+ imageUrl: string
129
+ [k: string]: any
130
+ }
131
+ [k: string]: any
132
+ }
133
+ | {
134
+ type: 'audio'
135
+ payload: {
136
+ audioUrl: string
137
+ [k: string]: any
138
+ }
139
+ [k: string]: any
140
+ }
141
+ | {
142
+ type: 'video'
143
+ payload: {
144
+ videoUrl: string
145
+ [k: string]: any
146
+ }
147
+ [k: string]: any
148
+ }
149
+ | {
150
+ type: 'file'
151
+ payload: {
152
+ fileUrl: string
153
+ title?: string
154
+ [k: string]: any
155
+ }
156
+ [k: string]: any
157
+ }
158
+ | {
159
+ type: 'location'
160
+ payload: {
161
+ latitude: number
162
+ longitude: number
163
+ address?: string
164
+ title?: string
165
+ [k: string]: any
166
+ }
167
+ [k: string]: any
168
+ }
169
+ )[]
170
+ type: 'bloc'
171
+ [k: string]: any
172
+ }
173
+ | {
174
+ markdown: string
175
+ type: 'markdown'
176
+ [k: string]: any
177
+ }
178
+ | {
179
+ url: string
180
+ name: string
181
+ data?: any
182
+ type: 'custom'
183
+ [k: string]: any
184
+ }
185
+ /**
186
+ * ID of the [User](#schema_user)
187
+ */
188
+ userId: string
189
+ /**
190
+ * ID of the [Conversation](#schema_conversation)
191
+ */
192
+ conversationId: string
193
+ /**
194
+ * Metadata of the message
195
+ */
196
+ metadata?: {
197
+ [k: string]: any
198
+ }
199
+ /**
200
+ * ID of the message this message is replying to
201
+ */
202
+ replyTo?: string
203
+ /**
204
+ * ID of the user who selected this message. Undefined if not selected.
205
+ */
206
+ selectedBy?: string
207
+ /**
208
+ * Feedback of the message
209
+ */
210
+ feedback?: {
211
+ value: 'positive' | 'negative'
212
+ comment?: string
213
+ }
214
+ }
215
+ oldStatus?: 'scheduled' | 'pending' | 'processing' | 'processed' | 'failed' | 'skipped'
216
+ newStatus: 'scheduled' | 'pending' | 'processing' | 'processed' | 'failed' | 'skipped'
217
+ failureReason?: string
218
+ }
219
+ }
@@ -0,0 +1,37 @@
1
+ export type ParticipantAdded = {
2
+ type: 'participant_added'
3
+ data: {
4
+ conversationId: string
5
+ /**
6
+ * The user object represents someone interacting with the bot within a specific integration. The same person interacting with a bot in slack and messenger will be represented with two different users.
7
+ */
8
+ participant: {
9
+ /**
10
+ * Name of the [User](#schema_user)
11
+ */
12
+ name?: string
13
+ /**
14
+ * Picture url of the [User](#schema_user)
15
+ */
16
+ pictureUrl?: string
17
+ /**
18
+ * User data
19
+ */
20
+ data?: {
21
+ [k: string]: any
22
+ }
23
+ /**
24
+ * Id of the [User](#schema_user)
25
+ */
26
+ id: string
27
+ /**
28
+ * Creation date of the [User](#schema_user) in ISO 8601 format
29
+ */
30
+ createdAt: string
31
+ /**
32
+ * Updating date of the [User](#schema_user) in ISO 8601 format
33
+ */
34
+ updatedAt: string
35
+ }
36
+ }
37
+ }
@@ -0,0 +1,7 @@
1
+ export type ParticipantRemoved = {
2
+ type: 'participant_removed'
3
+ data: {
4
+ conversationId: string
5
+ participantId: string
6
+ }
7
+ }
@@ -0,0 +1,4 @@
1
+ export type UserCredentials = {
2
+ userId: string
3
+ userToken: string
4
+ }
package/src/index.ts CHANGED
@@ -1,2 +1,9 @@
1
- export { createClient, createUser, type Client } from './client'
1
+ export {
2
+ createClient,
3
+ createUser,
4
+ generateUserKey,
5
+ type Client,
6
+ type UserCredentials,
7
+ type IntegrationError,
8
+ } from './client'
2
9
  export * from './gen/client/types.gen'
@@ -1,36 +0,0 @@
1
- type CallbackFn<T> = (args: T) => void
2
-
3
- export class EventEmitter<T extends Record<string, any>> {
4
- private readonly eventMap: Partial<Record<keyof T, Set<CallbackFn<any>>>>
5
-
6
- constructor() {
7
- this.eventMap = {}
8
- }
9
-
10
- on<U extends keyof T>(event: U, callback: CallbackFn<T[U]>): () => void {
11
- if (!this.eventMap[event]) {
12
- this.eventMap[event] = new Set<CallbackFn<T[U]>>()
13
- }
14
- this.eventMap[event]?.add(callback)
15
-
16
- return () => {
17
- this.eventMap[event]?.delete(callback)
18
- }
19
- }
20
-
21
- emit<U extends keyof T>(event: U, arg?: T[U]): void {
22
- this.eventMap[event]?.forEach((callback) => {
23
- callback(arg)
24
- })
25
-
26
- this.eventMap['*']?.forEach((callback) => {
27
- callback({ type: event, payload: arg })
28
- })
29
- }
30
- }
31
-
32
- export type Events = {
33
- [key: string]: undefined
34
- }
35
-
36
- export const eventEmitter = new EventEmitter<Events>()