wingbot-mongodb 4.2.7 → 4.2.9
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/package.json +7 -2
- package/src/AttachmentCache.js +8 -2
- package/src/BaseStorage.js +28 -10
- package/src/BotConfigStorage.js +3 -1
- package/tsconfig.json +16 -0
- package/types/AttachmentCache.d.ts +55 -0
- package/types/AuditLogStorage.d.ts +231 -0
- package/types/BaseStorage.d.ts +189 -0
- package/types/BotConfigStorage.d.ts +74 -0
- package/types/BotTokenStorage.d.ts +61 -0
- package/types/ChatLogStorage.d.ts +66 -0
- package/types/NotificationsStorage.d.ts +295 -0
- package/types/StateStorage.d.ts +97 -0
- package/types/compact.d.ts +53 -0
- package/types/defaultLogger.d.ts +4 -0
- package/types/getNestedObjects.d.ts +10 -0
- package/types/main.d.ts +9 -0
- package/types/tokenFactory.d.ts +5 -0
- package/baseStorage.d.ts +0 -50
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export = BotConfigStorage;
|
|
2
|
+
/**
|
|
3
|
+
* Storage for wingbot.ai conversation config
|
|
4
|
+
*
|
|
5
|
+
* @class
|
|
6
|
+
*/
|
|
7
|
+
declare class BotConfigStorage {
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param {Db|{():Promise<Db>}} mongoDb
|
|
11
|
+
* @param {string} collectionName
|
|
12
|
+
*/
|
|
13
|
+
constructor(mongoDb: Db | {
|
|
14
|
+
(): Promise<Db>;
|
|
15
|
+
}, collectionName?: string);
|
|
16
|
+
_mongoDb: import("mongodb").Db | (() => Promise<Db>);
|
|
17
|
+
_collectionName: string;
|
|
18
|
+
/**
|
|
19
|
+
* @type {Collection}
|
|
20
|
+
*/
|
|
21
|
+
_collection: Collection;
|
|
22
|
+
/**
|
|
23
|
+
* @returns {Promise<Collection>}
|
|
24
|
+
*/
|
|
25
|
+
_getCollection(): Promise<Collection>;
|
|
26
|
+
/**
|
|
27
|
+
* Returns botUpdate API for wingbot
|
|
28
|
+
*
|
|
29
|
+
* @param {Function} [onUpdate] - async update handler function
|
|
30
|
+
* @param {Function|string[]} [acl] - acl configuration
|
|
31
|
+
* @returns {{updateBot:Function}}
|
|
32
|
+
*/
|
|
33
|
+
api(onUpdate?: Function, acl?: Function | string[]): {
|
|
34
|
+
updateBot: Function;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Invalidates current configuration
|
|
38
|
+
*
|
|
39
|
+
* @returns {Promise}
|
|
40
|
+
*/
|
|
41
|
+
invalidateConfig(): Promise<any>;
|
|
42
|
+
/**
|
|
43
|
+
* @returns {Promise<number>}
|
|
44
|
+
*/
|
|
45
|
+
getConfigTimestamp(): Promise<number>;
|
|
46
|
+
/**
|
|
47
|
+
* @template T
|
|
48
|
+
* @param {T} newConfig
|
|
49
|
+
* @param {string} [id]
|
|
50
|
+
* @returns {Promise<T>}
|
|
51
|
+
*/
|
|
52
|
+
updateConfig<T>(newConfig: T, id?: string): Promise<T>;
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* @param {string} id
|
|
56
|
+
* @param {object} newConfig
|
|
57
|
+
*/
|
|
58
|
+
setConfig(id: string, newConfig: object): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* @param {string} [id]
|
|
61
|
+
* @returns {Promise<object | null>}
|
|
62
|
+
*/
|
|
63
|
+
getConfig(id?: string): Promise<object | null>;
|
|
64
|
+
}
|
|
65
|
+
declare namespace BotConfigStorage {
|
|
66
|
+
export { BaseConfig, Db, Collection };
|
|
67
|
+
}
|
|
68
|
+
type BaseConfig = {
|
|
69
|
+
[key: string]: any;
|
|
70
|
+
} & {
|
|
71
|
+
_id: string;
|
|
72
|
+
};
|
|
73
|
+
type Db = import("mongodb").Db;
|
|
74
|
+
type Collection = import("mongodb").Collection<BaseConfig>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export = BotTokenStorage;
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {object} Token
|
|
4
|
+
* @prop {string} senderId
|
|
5
|
+
* @prop {string} pageId
|
|
6
|
+
* @prop {string} token
|
|
7
|
+
*/
|
|
8
|
+
/** @typedef {import('mongodb').Db} Db */
|
|
9
|
+
/** @typedef {import('mongodb').Collection} Collection */
|
|
10
|
+
/**
|
|
11
|
+
* Storage for webview tokens
|
|
12
|
+
*
|
|
13
|
+
* @class
|
|
14
|
+
*/
|
|
15
|
+
declare class BotTokenStorage {
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param {Db|{():Promise<Db>}} mongoDb
|
|
19
|
+
* @param {string} collectionName
|
|
20
|
+
*/
|
|
21
|
+
constructor(mongoDb: Db | {
|
|
22
|
+
(): Promise<Db>;
|
|
23
|
+
}, collectionName?: string);
|
|
24
|
+
_mongoDb: import("mongodb").Db | (() => Promise<Db>);
|
|
25
|
+
_collectionName: string;
|
|
26
|
+
/**
|
|
27
|
+
* @type {Collection}
|
|
28
|
+
*/
|
|
29
|
+
_collection: Collection;
|
|
30
|
+
/**
|
|
31
|
+
* @returns {Promise<Collection>}
|
|
32
|
+
*/
|
|
33
|
+
_getCollection(): Promise<Collection>;
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param {string} token
|
|
37
|
+
* @returns {Promise<Token|null>}
|
|
38
|
+
*/
|
|
39
|
+
findByToken(token: string): Promise<Token | null>;
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @param {string} senderId
|
|
43
|
+
* @param {string} pageId
|
|
44
|
+
* @param {{(): Promise<string>}} createToken
|
|
45
|
+
* @returns {Promise<Token|null>}
|
|
46
|
+
*/
|
|
47
|
+
getOrCreateToken(senderId: string, pageId: string, createToken?: {
|
|
48
|
+
(): Promise<string>;
|
|
49
|
+
}): Promise<Token | null>;
|
|
50
|
+
_wait(ms: any): Promise<any>;
|
|
51
|
+
}
|
|
52
|
+
declare namespace BotTokenStorage {
|
|
53
|
+
export { Token, Db, Collection };
|
|
54
|
+
}
|
|
55
|
+
type Token = {
|
|
56
|
+
senderId: string;
|
|
57
|
+
pageId: string;
|
|
58
|
+
token: string;
|
|
59
|
+
};
|
|
60
|
+
type Db = import("mongodb").Db;
|
|
61
|
+
type Collection = import("mongodb").Collection;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export = ChatLogStorage;
|
|
2
|
+
/** @typedef {import('mongodb').Db} Db */
|
|
3
|
+
/**
|
|
4
|
+
* Storage for conversation logs
|
|
5
|
+
*
|
|
6
|
+
* @class
|
|
7
|
+
*/
|
|
8
|
+
declare class ChatLogStorage extends BaseStorage<any> {
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param {Db|{():Promise<Db>}} mongoDb
|
|
12
|
+
* @param {string} collectionName
|
|
13
|
+
* @param {{error:Function,log:Function}} [log] - console like logger
|
|
14
|
+
* @param {boolean} [isCosmo]
|
|
15
|
+
* @param {string|Promise<string>} [secret]
|
|
16
|
+
*/
|
|
17
|
+
constructor(mongoDb: Db | {
|
|
18
|
+
(): Promise<Db>;
|
|
19
|
+
}, collectionName?: string, log?: {
|
|
20
|
+
error: Function;
|
|
21
|
+
log: Function;
|
|
22
|
+
}, isCosmo?: boolean, secret?: string | Promise<string>);
|
|
23
|
+
muteErrors: boolean;
|
|
24
|
+
_secret: string | Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Interate history
|
|
27
|
+
* all limits are inclusive
|
|
28
|
+
*
|
|
29
|
+
* @param {string} senderId
|
|
30
|
+
* @param {string} pageId
|
|
31
|
+
* @param {number} [limit]
|
|
32
|
+
* @param {number} [endAt] - iterate backwards to history
|
|
33
|
+
* @param {number} [startAt] - iterate forward to last interaction
|
|
34
|
+
* @returns {Promise<object[]>}
|
|
35
|
+
*/
|
|
36
|
+
getInteractions(senderId: string, pageId: string, limit?: number, endAt?: number, startAt?: number): Promise<object[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Log single event
|
|
39
|
+
*
|
|
40
|
+
* @param {string} senderId
|
|
41
|
+
* @param {object[]} responses - list of sent responses
|
|
42
|
+
* @param {object} request - event request
|
|
43
|
+
* @param {object} [metadata] - request metadata
|
|
44
|
+
* @returns {Promise}
|
|
45
|
+
*/
|
|
46
|
+
log(senderId: string, responses?: object[], request?: object, metadata?: object): Promise<any>;
|
|
47
|
+
_storeLog(event: any): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Log single event
|
|
50
|
+
*
|
|
51
|
+
* @method
|
|
52
|
+
* @name ChatLog#error
|
|
53
|
+
* @param {any} err - error
|
|
54
|
+
* @param {string} senderId
|
|
55
|
+
* @param {object[]} [responses] - list of sent responses
|
|
56
|
+
* @param {object} [request] - event request
|
|
57
|
+
* @param {object} [metadata] - request metadata
|
|
58
|
+
* @returns {Promise}
|
|
59
|
+
*/
|
|
60
|
+
error(err: any, senderId: string, responses?: object[], request?: object, metadata?: object): Promise<any>;
|
|
61
|
+
}
|
|
62
|
+
declare namespace ChatLogStorage {
|
|
63
|
+
export { Db };
|
|
64
|
+
}
|
|
65
|
+
import BaseStorage = require("./BaseStorage");
|
|
66
|
+
type Db = import("mongodb").Db;
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
export = NotificationsStorage;
|
|
2
|
+
declare class NotificationsStorage {
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {mongodb.Db|{():Promise<mongodb.Db>}} mongoDb
|
|
6
|
+
* @param {string} collectionsPrefix
|
|
7
|
+
* @param {{error:Function,log:Function}} [log] - console like logger
|
|
8
|
+
* @param {boolean} isCosmo
|
|
9
|
+
*/
|
|
10
|
+
constructor(mongoDb: mongodb.Db | {
|
|
11
|
+
(): Promise<mongodb.Db>;
|
|
12
|
+
}, collectionsPrefix?: string, log?: {
|
|
13
|
+
error: Function;
|
|
14
|
+
log: Function;
|
|
15
|
+
}, isCosmo?: boolean);
|
|
16
|
+
_mongoDb: mongodb.Db | (() => Promise<mongodb.Db>);
|
|
17
|
+
taksCollection: string;
|
|
18
|
+
campaignsCollection: string;
|
|
19
|
+
subscribtionsCollection: string;
|
|
20
|
+
_isCosmo: boolean;
|
|
21
|
+
_log: {
|
|
22
|
+
error: Function;
|
|
23
|
+
log: Function;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* @type {Map<string,Promise<mongodb.Collection>>}
|
|
27
|
+
*/
|
|
28
|
+
_collections: Map<string, Promise<mongodb.Collection>>;
|
|
29
|
+
_getOrCreateCollection(name: any): Promise<mongodb.Collection<mongodb.BSON.Document>>;
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} collectionName
|
|
32
|
+
* @returns {Promise<mongodb.Collection>}
|
|
33
|
+
*/
|
|
34
|
+
_getCollection(collectionName: string): Promise<mongodb.Collection>;
|
|
35
|
+
_ensureIndexes(collection: any, indexes: any): Promise<void>;
|
|
36
|
+
_doesNotSupportTextIndex: boolean;
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param {object} tasks
|
|
40
|
+
* @returns {Promise<Task[]>}
|
|
41
|
+
*/
|
|
42
|
+
pushTasks(tasks: object): Promise<Task[]>;
|
|
43
|
+
_mapGenericObject(obj: any): any;
|
|
44
|
+
_mapCampaign(camp: any): any;
|
|
45
|
+
popTasks(limit: any, until?: number): Promise<any[]>;
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
* @param {string} campaignId
|
|
49
|
+
* @param {boolean} [sentWithoutReaction]
|
|
50
|
+
* @param {string} [pageId]
|
|
51
|
+
*/
|
|
52
|
+
getUnsuccessfulSubscribersByCampaign(campaignId: string, sentWithoutReaction?: boolean, pageId?: string): Promise<mongodb.BSON.Document[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Return Task By Id
|
|
55
|
+
*
|
|
56
|
+
* @param {string} taskId
|
|
57
|
+
* @returns {Promise<Task|null>}
|
|
58
|
+
*/
|
|
59
|
+
getTaskById(taskId: string): Promise<Task | null>;
|
|
60
|
+
/**
|
|
61
|
+
*
|
|
62
|
+
* @param {string} taskId
|
|
63
|
+
* @param {object} data
|
|
64
|
+
*/
|
|
65
|
+
updateTask(taskId: string, data: object): Promise<any>;
|
|
66
|
+
/**
|
|
67
|
+
* Get last sent task from campaign
|
|
68
|
+
*
|
|
69
|
+
* @param {string} pageId
|
|
70
|
+
* @param {string} senderId
|
|
71
|
+
* @param {string} campaignId
|
|
72
|
+
* @returns {Promise<Task|null>}
|
|
73
|
+
*/
|
|
74
|
+
getSentTask(pageId: string, senderId: string, campaignId: string): Promise<Task | null>;
|
|
75
|
+
/**
|
|
76
|
+
*
|
|
77
|
+
* @param {string} pageId
|
|
78
|
+
* @param {string} senderId
|
|
79
|
+
* @param {string[]} checkCampaignIds
|
|
80
|
+
* @returns {Promise<string[]>}
|
|
81
|
+
*/
|
|
82
|
+
getSentCampagnIds(pageId: string, senderId: string, checkCampaignIds: string[]): Promise<string[]>;
|
|
83
|
+
/**
|
|
84
|
+
*
|
|
85
|
+
* @param {string} senderId
|
|
86
|
+
* @param {string} pageId
|
|
87
|
+
* @param {number} watermark
|
|
88
|
+
* @param {('read'|'delivery')} eventType
|
|
89
|
+
* @param {number} ts
|
|
90
|
+
* @returns {Promise<Task[]>}
|
|
91
|
+
*/
|
|
92
|
+
updateTasksByWatermark(senderId: string, pageId: string, watermark: number, eventType: ("read" | "delivery"), ts?: number): Promise<Task[]>;
|
|
93
|
+
/**
|
|
94
|
+
*
|
|
95
|
+
* @param {object} campaign
|
|
96
|
+
* @param {object} [updateCampaign]
|
|
97
|
+
* @returns {Promise<Campaign>}
|
|
98
|
+
*/
|
|
99
|
+
upsertCampaign(campaign: object, updateCampaign?: object): Promise<Campaign>;
|
|
100
|
+
/**
|
|
101
|
+
*
|
|
102
|
+
* @param {string} campaignId
|
|
103
|
+
* @returns {Promise}
|
|
104
|
+
*/
|
|
105
|
+
removeCampaign(campaignId: string): Promise<any>;
|
|
106
|
+
/**
|
|
107
|
+
*
|
|
108
|
+
* @param {string} campaignId
|
|
109
|
+
* @param {object} increment
|
|
110
|
+
* @returns {Promise}
|
|
111
|
+
*/
|
|
112
|
+
incrementCampaign(campaignId: string, increment?: object): Promise<any>;
|
|
113
|
+
/**
|
|
114
|
+
*
|
|
115
|
+
* @param {string} campaignId
|
|
116
|
+
* @param {object} data
|
|
117
|
+
* @returns {Promise<Campaign|null>}
|
|
118
|
+
*/
|
|
119
|
+
updateCampaign(campaignId: string, data: object): Promise<Campaign | null>;
|
|
120
|
+
/**
|
|
121
|
+
*
|
|
122
|
+
* @param {number} [now]
|
|
123
|
+
* @returns {Promise<Campaign|null>}
|
|
124
|
+
*/
|
|
125
|
+
popCampaign(now?: number): Promise<Campaign | null>;
|
|
126
|
+
/**
|
|
127
|
+
*
|
|
128
|
+
* @param {string} campaignId
|
|
129
|
+
* @returns {Promise<null|Campaign>}
|
|
130
|
+
*/
|
|
131
|
+
getCampaignById(campaignId: string): Promise<null | Campaign>;
|
|
132
|
+
/**
|
|
133
|
+
*
|
|
134
|
+
* @param {string[]} campaignIds
|
|
135
|
+
* @returns {Promise<Campaign[]>}
|
|
136
|
+
*/
|
|
137
|
+
getCampaignByIds(campaignIds: string[]): Promise<Campaign[]>;
|
|
138
|
+
/**
|
|
139
|
+
*
|
|
140
|
+
* @param {object} condition
|
|
141
|
+
* @param {number} [limit]
|
|
142
|
+
* @param {object} [lastKey]
|
|
143
|
+
* @returns {Promise<{data:Campaign[],lastKey:string}>}
|
|
144
|
+
*/
|
|
145
|
+
getCampaigns(condition: object, limit?: number, lastKey?: object): Promise<{
|
|
146
|
+
data: Campaign[];
|
|
147
|
+
lastKey: string;
|
|
148
|
+
}>;
|
|
149
|
+
/**
|
|
150
|
+
*
|
|
151
|
+
* @param {SubscriptionData[]} subscriptionData
|
|
152
|
+
* @param {boolean} [onlyToKnown=false]
|
|
153
|
+
* @returns {Promise}
|
|
154
|
+
*/
|
|
155
|
+
batchSubscribe(subscriptionData: SubscriptionData[], onlyToKnown?: boolean): Promise<any>;
|
|
156
|
+
/**
|
|
157
|
+
*
|
|
158
|
+
* @param {string|string[]} senderId
|
|
159
|
+
* @param {string} pageId
|
|
160
|
+
* @param {string} tag
|
|
161
|
+
* @param {boolean} [onlyToKnown]
|
|
162
|
+
* @returns {Promise}
|
|
163
|
+
*/
|
|
164
|
+
subscribe(senderId: string | string[], pageId: string, tag: string, onlyToKnown?: boolean): Promise<any>;
|
|
165
|
+
/**
|
|
166
|
+
*
|
|
167
|
+
* @param {string} senderId
|
|
168
|
+
* @param {string} pageId
|
|
169
|
+
* @param {string} [tag]
|
|
170
|
+
* @returns {Promise<string[]>}
|
|
171
|
+
*/
|
|
172
|
+
unsubscribe(senderId: string, pageId: string, tag?: string): Promise<string[]>;
|
|
173
|
+
_createSubscribtionsCondition(include: any, exclude: any, pageId?: any): {};
|
|
174
|
+
/**
|
|
175
|
+
*
|
|
176
|
+
* @param {string[]} include
|
|
177
|
+
* @param {string[]} exclude
|
|
178
|
+
* @param {string} [pageId]
|
|
179
|
+
* @returns {Promise<number>}
|
|
180
|
+
*/
|
|
181
|
+
getSubscribtionsCount(include: string[], exclude: string[], pageId?: string): Promise<number>;
|
|
182
|
+
/**
|
|
183
|
+
*
|
|
184
|
+
* @param {string[]} include
|
|
185
|
+
* @param {string[]} exclude
|
|
186
|
+
* @param {number} limit
|
|
187
|
+
* @param {string} [pageId]
|
|
188
|
+
* @param {*} lastKey
|
|
189
|
+
* @returns {Promise<{data: Target[], lastKey: string }>}
|
|
190
|
+
*/
|
|
191
|
+
getSubscribtions(include: string[], exclude: string[], limit: number, pageId?: string, lastKey?: any): Promise<{
|
|
192
|
+
data: Target[];
|
|
193
|
+
lastKey: string;
|
|
194
|
+
}>;
|
|
195
|
+
/**
|
|
196
|
+
* @param {string} senderId
|
|
197
|
+
* @param {string} pageId
|
|
198
|
+
* @returns {Promise<Subscription[]>}
|
|
199
|
+
*/
|
|
200
|
+
getSenderSubscriptions(senderId: string, pageId: string): Promise<Subscription[]>;
|
|
201
|
+
/**
|
|
202
|
+
*
|
|
203
|
+
* @param {string} senderId
|
|
204
|
+
* @param {string} pageId
|
|
205
|
+
* @returns {Promise<string[]>}
|
|
206
|
+
*/
|
|
207
|
+
getSenderSubscribtions(senderId: string, pageId: string): Promise<string[]>;
|
|
208
|
+
getTags(pageId?: any): Promise<{
|
|
209
|
+
tag: any;
|
|
210
|
+
subscribtions: any;
|
|
211
|
+
}[]>;
|
|
212
|
+
}
|
|
213
|
+
declare namespace NotificationsStorage {
|
|
214
|
+
export { Target, Subscribtion, Campaign, Task, Subscription, SubscriptionData };
|
|
215
|
+
}
|
|
216
|
+
import mongodb = require("mongodb");
|
|
217
|
+
type Target = {
|
|
218
|
+
senderId: string;
|
|
219
|
+
pageId: string;
|
|
220
|
+
meta?: {
|
|
221
|
+
[key: string]: object;
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
type Subscribtion = {
|
|
225
|
+
senderId: string;
|
|
226
|
+
pageId: string;
|
|
227
|
+
subs: string[];
|
|
228
|
+
};
|
|
229
|
+
type Campaign = {
|
|
230
|
+
id: string;
|
|
231
|
+
/**
|
|
232
|
+
* Tatgeting
|
|
233
|
+
*/
|
|
234
|
+
name: string;
|
|
235
|
+
include: string[];
|
|
236
|
+
/**
|
|
237
|
+
* Stats
|
|
238
|
+
*/
|
|
239
|
+
exclude: string[];
|
|
240
|
+
sent: number;
|
|
241
|
+
succeeded: number;
|
|
242
|
+
failed: number;
|
|
243
|
+
unsubscribed: number;
|
|
244
|
+
delivery: number;
|
|
245
|
+
read: number;
|
|
246
|
+
notSent: number;
|
|
247
|
+
leaved: number;
|
|
248
|
+
/**
|
|
249
|
+
* Interaction
|
|
250
|
+
*/
|
|
251
|
+
queued: number;
|
|
252
|
+
action: string;
|
|
253
|
+
/**
|
|
254
|
+
* Setup
|
|
255
|
+
*/
|
|
256
|
+
data?: object;
|
|
257
|
+
sliding: boolean;
|
|
258
|
+
slide: number;
|
|
259
|
+
slideRound: number;
|
|
260
|
+
active: boolean;
|
|
261
|
+
in24hourWindow: boolean;
|
|
262
|
+
startAt: number;
|
|
263
|
+
};
|
|
264
|
+
type Task = {
|
|
265
|
+
id: string;
|
|
266
|
+
pageId: string;
|
|
267
|
+
senderId: string;
|
|
268
|
+
campaignId: string;
|
|
269
|
+
enqueue: number;
|
|
270
|
+
read?: number;
|
|
271
|
+
delivery?: number;
|
|
272
|
+
sent?: number;
|
|
273
|
+
insEnqueue?: number;
|
|
274
|
+
/**
|
|
275
|
+
* - user reacted
|
|
276
|
+
*/
|
|
277
|
+
reaction?: boolean;
|
|
278
|
+
/**
|
|
279
|
+
* - time the event was not sent because user left
|
|
280
|
+
*/
|
|
281
|
+
leaved?: number;
|
|
282
|
+
};
|
|
283
|
+
type Subscription = {
|
|
284
|
+
tag: string;
|
|
285
|
+
meta: object;
|
|
286
|
+
};
|
|
287
|
+
type SubscriptionData = {
|
|
288
|
+
pageId: string;
|
|
289
|
+
senderId: string;
|
|
290
|
+
tags: string[];
|
|
291
|
+
remove?: boolean;
|
|
292
|
+
meta?: {
|
|
293
|
+
[key: string]: object;
|
|
294
|
+
};
|
|
295
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export = StateStorage;
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {object} State
|
|
4
|
+
* @prop {string} senderId
|
|
5
|
+
* @prop {string} pageId
|
|
6
|
+
* @prop {object} state
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {object} StateCondition
|
|
10
|
+
* @prop {string} [search]
|
|
11
|
+
* @prop {string[]} [senderIds]
|
|
12
|
+
* @prop {string} [pageId]
|
|
13
|
+
*/
|
|
14
|
+
/** @typedef {import('mongodb').Db} Db */
|
|
15
|
+
/**
|
|
16
|
+
* Storage for chat states
|
|
17
|
+
*
|
|
18
|
+
* @class
|
|
19
|
+
*/
|
|
20
|
+
declare class StateStorage extends BaseStorage<any> {
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param {Db|{():Promise<Db>}} mongoDb
|
|
24
|
+
* @param {string} collectionName
|
|
25
|
+
* @param {{error:Function,log:Function}} [log] - console like logger
|
|
26
|
+
* @param {boolean|number} isCosmo - boolean or number of failures in last 10min to kill app
|
|
27
|
+
*/
|
|
28
|
+
constructor(mongoDb: Db | {
|
|
29
|
+
(): Promise<Db>;
|
|
30
|
+
}, collectionName?: string, log?: {
|
|
31
|
+
error: Function;
|
|
32
|
+
log: Function;
|
|
33
|
+
}, isCosmo?: boolean | number);
|
|
34
|
+
logCollisionsAsErrors: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Add custom indexing rule
|
|
37
|
+
*
|
|
38
|
+
* @param {object} index
|
|
39
|
+
* @param {object} options
|
|
40
|
+
* @param {string} options.name
|
|
41
|
+
* @deprecated
|
|
42
|
+
*/
|
|
43
|
+
addCustomIndex(index: object, options: {
|
|
44
|
+
name: string;
|
|
45
|
+
}): void;
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
* @param {string} senderId
|
|
49
|
+
* @param {string} pageId
|
|
50
|
+
* @returns {Promise<State|null>}
|
|
51
|
+
*/
|
|
52
|
+
getState(senderId: string, pageId: string): Promise<State | null>;
|
|
53
|
+
/**
|
|
54
|
+
* Load state from database and lock it to prevent another reads
|
|
55
|
+
*
|
|
56
|
+
* @param {string} senderId - sender identifier
|
|
57
|
+
* @param {string} pageId - page identifier
|
|
58
|
+
* @param {object} [defaultState] - default state of the conversation
|
|
59
|
+
* @param {number} [timeout=300] - given default state
|
|
60
|
+
* @returns {Promise<object>} - conversation state
|
|
61
|
+
*/
|
|
62
|
+
getOrCreateAndLock(senderId: string, pageId: string, defaultState?: object, timeout?: number): Promise<object>;
|
|
63
|
+
/**
|
|
64
|
+
*
|
|
65
|
+
* @param {StateCondition} condition
|
|
66
|
+
* @param {number} limit
|
|
67
|
+
* @param {string} lastKey
|
|
68
|
+
* @returns {Promise<{data:State[],lastKey:string}>}
|
|
69
|
+
*/
|
|
70
|
+
getStates(condition?: StateCondition, limit?: number, lastKey?: string): Promise<{
|
|
71
|
+
data: State[];
|
|
72
|
+
lastKey: string;
|
|
73
|
+
}>;
|
|
74
|
+
_mapState(state: any): any;
|
|
75
|
+
/**
|
|
76
|
+
* Save the state to database
|
|
77
|
+
*
|
|
78
|
+
* @param {object} state - conversation state
|
|
79
|
+
* @returns {Promise<object>}
|
|
80
|
+
*/
|
|
81
|
+
saveState(state: object): Promise<object>;
|
|
82
|
+
}
|
|
83
|
+
declare namespace StateStorage {
|
|
84
|
+
export { State, StateCondition, Db };
|
|
85
|
+
}
|
|
86
|
+
import BaseStorage = require("./BaseStorage");
|
|
87
|
+
type State = {
|
|
88
|
+
senderId: string;
|
|
89
|
+
pageId: string;
|
|
90
|
+
state: object;
|
|
91
|
+
};
|
|
92
|
+
type StateCondition = {
|
|
93
|
+
search?: string;
|
|
94
|
+
senderIds?: string[];
|
|
95
|
+
pageId?: string;
|
|
96
|
+
};
|
|
97
|
+
type Db = import("mongodb").Db;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export = compact;
|
|
2
|
+
/**
|
|
3
|
+
* @param {Db} db
|
|
4
|
+
* @param {string} dbUrl
|
|
5
|
+
* @param {string} dbName
|
|
6
|
+
* @param {any} log
|
|
7
|
+
* @returns {Promise<{bytesFreed: number}>}
|
|
8
|
+
*/
|
|
9
|
+
declare function compact(db: Db, dbUrl: string, dbName: string, log?: any): Promise<{
|
|
10
|
+
bytesFreed: number;
|
|
11
|
+
}>;
|
|
12
|
+
declare namespace compact {
|
|
13
|
+
export { compactNode, getCompactableCollections, getReplicaSetNodes, Db };
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Compacts all collections on a given replica set node
|
|
17
|
+
*
|
|
18
|
+
* @param {object} props
|
|
19
|
+
* @param {string} props.nodeUrl
|
|
20
|
+
* @param {boolean} [props.force]
|
|
21
|
+
* @param {string} props.dbUrl
|
|
22
|
+
* @param {string} props.dbName
|
|
23
|
+
* @param {string[]} props.collections
|
|
24
|
+
* @param {any} props.log
|
|
25
|
+
* @returns {Promise<{bytesFreed:number}>}
|
|
26
|
+
*/
|
|
27
|
+
declare function compactNode({ nodeUrl, collections, force, dbUrl, dbName, log }: {
|
|
28
|
+
nodeUrl: string;
|
|
29
|
+
force?: boolean;
|
|
30
|
+
dbUrl: string;
|
|
31
|
+
dbName: string;
|
|
32
|
+
collections: string[];
|
|
33
|
+
log: any;
|
|
34
|
+
}): Promise<{
|
|
35
|
+
bytesFreed: number;
|
|
36
|
+
}>;
|
|
37
|
+
/** @typedef {import('mongodb').Db} Db */
|
|
38
|
+
/**
|
|
39
|
+
* @param {Db} db
|
|
40
|
+
* @returns {Promise<string[]>}
|
|
41
|
+
*/
|
|
42
|
+
declare function getCompactableCollections(db: Db): Promise<string[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Returns host addresses of replica set nodes
|
|
45
|
+
*
|
|
46
|
+
* @param {Db} db
|
|
47
|
+
* @returns {Promise<{primary: string, secondaries: string[]}>}
|
|
48
|
+
*/
|
|
49
|
+
declare function getReplicaSetNodes(db: Db): Promise<{
|
|
50
|
+
primary: string;
|
|
51
|
+
secondaries: string[];
|
|
52
|
+
}>;
|
|
53
|
+
type Db = import("mongodb").Db;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export = getNestedObjects;
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {any} obj
|
|
5
|
+
* @param {boolean} nested
|
|
6
|
+
* @param {string} [attr]
|
|
7
|
+
* @param {object} [ret]
|
|
8
|
+
* @returns {object}
|
|
9
|
+
*/
|
|
10
|
+
declare function getNestedObjects(obj: any, nested: boolean, attr?: string, ret?: object): object;
|
package/types/main.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import BaseStorage = require("./BaseStorage");
|
|
2
|
+
import StateStorage = require("./StateStorage");
|
|
3
|
+
import BotTokenStorage = require("./BotTokenStorage");
|
|
4
|
+
import ChatLogStorage = require("./ChatLogStorage");
|
|
5
|
+
import BotConfigStorage = require("./BotConfigStorage");
|
|
6
|
+
import AttachmentCache = require("./AttachmentCache");
|
|
7
|
+
import NotificationsStorage = require("./NotificationsStorage");
|
|
8
|
+
import AuditLogStorage = require("./AuditLogStorage");
|
|
9
|
+
export { BaseStorage, StateStorage, BotTokenStorage, ChatLogStorage, BotConfigStorage, AttachmentCache, NotificationsStorage, AuditLogStorage };
|