Contains storage for tokens, chat states, bot config and chat logs.
- StateStorage
-
Storage for chat states
- BotTokenStorage
-
Storage for webview tokens
- ChatLogStorage
-
Storage for conversation logs
- BotConfigStorage
-
Storage for wingbot.ai conversation config
- AttachmentCache
-
Cache storage for Facebook attachments
- AuditLogStorage
-
Storage for audit logs with signatures chain
- NotificationsStorage
- BaseStorage
-
State :
object
-
StateCondition :
object
-
Token :
object
-
Db :
module:mongodb/lib/db
-
Db :
module:mongodb/lib/db
-
Collection :
module:mongodb/lib/collection
-
Db :
module:mongodb/lib/db
-
TrackingEvent :
object
-
User :
object
-
Meta :
object
-
LogEntry :
object
-
JwtVerifier ⇒
Promise.<boolean>
-
JWT Verifier
-
AuditLogEntry :
object
-
AuditLogCallback ⇒
Promise
-
Audit Log Callback
-
Target :
Object
-
Subscribtion :
Object
-
Campaign :
object
-
Task :
Object
-
Db :
module:mongodb/lib/db
-
Collection :
module:mongodb/lib/collection
Storage for chat states
Kind: global class
-
StateStorage
- new StateStorage(mongoDb, collectionName, [log], isCosmo)
.addCustomIndex(index, options)-
.getState(senderId, pageId) ⇒
Promise.<(State|null)>
-
.getOrCreateAndLock(senderId, pageId, [defaultState], [timeout]) ⇒
Promise.<object>
-
.getStates(condition, limit, lastKey) ⇒
Promise.<{Array.<data:State>, lastKey:string}>
-
.saveState(state) ⇒
Promise.<object>
Param | Type | Default | Description |
---|---|---|---|
mongoDb |
mongodb.Db | Object
|
||
collectionName | string |
"states" |
|
[log] | Object |
console like logger | |
isCosmo | boolean |
false |
Deprecated
Add custom indexing rule
Kind: instance method of StateStorage
Param | Type |
---|---|
index | object |
options | object |
options.name | string |
Kind: instance method of StateStorage
Param | Type |
---|---|
senderId | string |
pageId | string |
Load state from database and lock it to prevent another reads
Kind: instance method of StateStorage
Returns: Promise.<object>
- - conversation state
Param | Type | Default | Description |
---|---|---|---|
senderId | string |
sender identifier | |
pageId | string |
page identifier | |
[defaultState] | object |
default state of the conversation | |
[timeout] | number |
300 |
given default state |
Kind: instance method of StateStorage
Param | Type | Default |
---|---|---|
condition | StateCondition |
|
limit | number |
20 |
lastKey | string |
null |
Save the state to database
Kind: instance method of StateStorage
Param | Type | Description |
---|---|---|
state | object |
conversation state |
Storage for webview tokens
Kind: global class
-
BotTokenStorage
- new BotTokenStorage(mongoDb, collectionName)
-
._collection :
mongodb.Collection
-
._getCollection() ⇒
Promise.<mongodb.Collection>
-
.findByToken(token) ⇒
Promise.<(Token|null)>
-
.getOrCreateToken(senderId, pageId, createToken) ⇒
Promise.<(Token|null)>
Param | Type | Default |
---|---|---|
mongoDb |
mongodb.Db | Object
|
|
collectionName | string |
"tokens" |
Kind: instance property of BotTokenStorage
Kind: instance method of BotTokenStorage
Kind: instance method of BotTokenStorage
Param | Type |
---|---|
token | string |
Kind: instance method of BotTokenStorage
Param | Type |
---|---|
senderId | string |
pageId | string |
createToken | Object |
Storage for conversation logs
Kind: global class
Param | Type | Default | Description |
---|---|---|---|
mongoDb |
Db | Object
|
||
collectionName | string |
"chatlogs" |
|
[log] | Object |
console like logger | |
[isCosmo] | boolean |
false |
|
[secret] |
string | Promise.<string>
|
null |
chatLogStorage.getInteractions(senderId, pageId, [limit], [endAt], [startAt]) ⇒ Promise.<Array.<object>>
Interate history all limits are inclusive
Kind: instance method of ChatLogStorage
Param | Type | Default | Description |
---|---|---|---|
senderId | string |
||
pageId | string |
||
[limit] | number |
10 |
|
[endAt] | number |
|
iterate backwards to history |
[startAt] | number |
|
iterate forward to last interaction |
Log single event
Kind: instance method of ChatLogStorage
Param | Type | Description |
---|---|---|
senderId | string |
|
responses | Array.<object> |
list of sent responses |
request | object |
event request |
[metadata] | object |
request metadata |
Storage for wingbot.ai conversation config
Kind: global class
-
BotConfigStorage
- new BotConfigStorage(mongoDb, collectionName)
-
._collection :
Collection
-
._getCollection() ⇒
Promise.<Collection>
-
.api([onUpdate], [acl]) ⇒
Object
-
.invalidateConfig() ⇒
Promise
-
.getConfigTimestamp() ⇒
Promise.<number>
-
.updateConfig(newConfig, [id]) ⇒
Promise.<T>
- .setConfig(id, newConfig)
-
.getConfig([id]) ⇒
Promise.<(object|null)>
Param | Type | Default |
---|---|---|
mongoDb |
Db | Object
|
|
collectionName | string |
"botconfig" |
botConfigStorage._collection : Collection
Kind: instance property of BotConfigStorage
botConfigStorage._getCollection() ⇒ Promise.<Collection>
Kind: instance method of BotConfigStorage
Returns botUpdate API for wingbot
Kind: instance method of BotConfigStorage
Param | Type | Description |
---|---|---|
[onUpdate] | function |
async update handler function |
[acl] |
function | Array.<string>
|
acl configuration |
Invalidates current configuration
Kind: instance method of BotConfigStorage
Kind: instance method of BotConfigStorage
Kind: instance method of BotConfigStorage
Param | Type |
---|---|
newConfig | T |
[id] | string |
Kind: instance method of BotConfigStorage
Param | Type |
---|---|
id | string |
newConfig | object |
Kind: instance method of BotConfigStorage
Param | Type |
---|---|
[id] | string |
Cache storage for Facebook attachments
Kind: global class
-
AttachmentCache
- new AttachmentCache(mongoDb, collectionName)
-
._collection :
mongodb.Collection
-
._getCollection() ⇒
Promise.<mongodb.Collection>
-
.findAttachmentByUrl(url) ⇒
Promise.<(number|null)>
-
.saveAttachmentId(url, attachmentId) ⇒
Promise
Param | Type | Default |
---|---|---|
mongoDb |
mongodb.Db | Object
|
|
collectionName | string |
"attachments" |
Kind: instance property of AttachmentCache
Kind: instance method of AttachmentCache
Kind: instance method of AttachmentCache
Param | Type |
---|---|
url | string |
Kind: instance method of AttachmentCache
Param | Type |
---|---|
url | string |
attachmentId | number |
Storage for audit logs with signatures chain
Kind: global class
Param | Type | Default | Description |
---|---|---|---|
mongoDb |
Db | Object
|
||
collectionName | string |
"auditlog" |
|
[log] | Object |
console like logger | |
[isCosmo] | boolean |
false |
|
[secret] |
string | Promise.<string>
|
null |
|
[jwtVerifier] |
string | Promise.<string>
|
null |
auditLogStorage._jwtVerify : JwtVerifier
Kind: instance property of AuditLogStorage
auditLogStorage.callback : AuditLogCallback
Kind: instance property of AuditLogStorage
Add a log
Kind: instance method of AuditLogStorage
Param | Type | Description |
---|---|---|
event | TrackingEvent |
|
user | User |
|
[meta] | Meta |
|
[wid] | string |
workspace ID |
[type] | string |
|
[level] | string |
|
[date] | Date |
Kind: instance method of AuditLogStorage
Param | Type | Default | Description |
---|---|---|---|
[wid] | string |
workspace id | |
[fromSeq] | number |
0 |
for paging |
[limit] | number |
40 |
Kind: global class
-
NotificationsStorage
- new NotificationsStorage(mongoDb, collectionsPrefix, [log], isCosmo)
-
._collections :
Map.<string, Promise.<mongodb.Collection>>
-
._getCollection(collectionName) ⇒
Promise.<mongodb.Collection>
-
.pushTasks(tasks) ⇒
Promise.<Array.<Task>>
- .getUnsuccessfulSubscribersByCampaign(campaignId, [sentWithoutReaction], [pageId])
-
.getTaskById(taskId) ⇒
Promise.<(Task|null)>
- .updateTask(taskId, data)
-
.getSentTask(pageId, senderId, campaignId) ⇒
Promise.<(Task|null)>
-
.getSentCampagnIds(pageId, senderId, checkCampaignIds) ⇒
Promise.<Array.<string>>
-
.updateTasksByWatermark(senderId, pageId, watermark, eventType, ts) ⇒
Promise.<Array.<Task>>
-
.upsertCampaign(campaign, [updateCampaign]) ⇒
Promise.<Campaign>
-
.removeCampaign(campaignId) ⇒
Promise
-
.incrementCampaign(campaignId, increment) ⇒
Promise
-
.updateCampaign(campaignId, data) ⇒
Promise.<(Campaign|null)>
-
.popCampaign([now]) ⇒
Promise.<(Campaign|null)>
-
.getCampaignById(campaignId) ⇒
Promise.<(null|Campaign)>
-
.getCampaignByIds(campaignIds) ⇒
Promise.<Array.<Campaign>>
-
.getCampaigns(condition, [limit], [lastKey]) ⇒
Promise.<{Array.<data:Campaign>, lastKey:string}>
-
.subscribe(senderId, pageId, tag) ⇒
Promise
-
.unsubscribe(senderId, pageId, [tag]) ⇒
Promise.<Array.<string>>
-
.getSubscribtionsCount(include, exclude, [pageId]) ⇒
Promise.<number>
-
.getSubscribtions(include, exclude, limit, [pageId], lastKey) ⇒
Promise.<{data: Array.<Target>, lastKey: string}>
-
.getSenderSubscribtions(senderId, pageId) ⇒
Promise.<Array.<string>>
Param | Type | Default | Description |
---|---|---|---|
mongoDb |
mongodb.Db | Object
|
||
collectionsPrefix | string |
||
[log] | Object |
console like logger | |
isCosmo | boolean |
false |
Kind: instance property of NotificationsStorage
Kind: instance method of NotificationsStorage
Param | Type |
---|---|
collectionName | string |
Kind: instance method of NotificationsStorage
Param | Type |
---|---|
tasks | object |
notificationsStorage.getUnsuccessfulSubscribersByCampaign(campaignId, [sentWithoutReaction], [pageId])
Kind: instance method of NotificationsStorage
Param | Type | Default |
---|---|---|
campaignId | string |
|
[sentWithoutReaction] | boolean |
false |
[pageId] | string |
null |
Return Task By Id
Kind: instance method of NotificationsStorage
Param | Type |
---|---|
taskId | string |
Kind: instance method of NotificationsStorage
Param | Type |
---|---|
taskId | string |
data | object |
Get last sent task from campaign
Kind: instance method of NotificationsStorage
Param | Type |
---|---|
pageId | string |
senderId | string |
campaignId | string |
notificationsStorage.getSentCampagnIds(pageId, senderId, checkCampaignIds) ⇒ Promise.<Array.<string>>
Kind: instance method of NotificationsStorage
Param | Type |
---|---|
pageId | string |
senderId | string |
checkCampaignIds | Array.<string> |
notificationsStorage.updateTasksByWatermark(senderId, pageId, watermark, eventType, ts) ⇒ Promise.<Array.<Task>>
Kind: instance method of NotificationsStorage
Param | Type |
---|---|
senderId | string |
pageId | string |
watermark | number |
eventType |
'read' | 'delivery'
|
ts | number |
notificationsStorage.upsertCampaign(campaign, [updateCampaign]) ⇒ Promise.<Campaign>
Kind: instance method of NotificationsStorage
Param | Type | Default |
---|---|---|
campaign | object |
|
[updateCampaign] | object |
|
Kind: instance method of NotificationsStorage
Param | Type |
---|---|
campaignId | string |
Kind: instance method of NotificationsStorage
Param | Type |
---|---|
campaignId | string |
increment | object |
Kind: instance method of NotificationsStorage
Param | Type |
---|---|
campaignId | string |
data | object |
Kind: instance method of NotificationsStorage
Param | Type |
---|---|
[now] | number |
Kind: instance method of NotificationsStorage
Param | Type |
---|---|
campaignId | string |
Kind: instance method of NotificationsStorage
Param | Type |
---|---|
campaignIds | Array.<string> |
notificationsStorage.getCampaigns(condition, [limit], [lastKey]) ⇒ Promise.<{Array.<data:Campaign>, lastKey:string}>
Kind: instance method of NotificationsStorage
Param | Type | Default |
---|---|---|
condition | object |
|
[limit] | number |
|
[lastKey] | object |
|
Kind: instance method of NotificationsStorage
Param | Type |
---|---|
senderId | string |
pageId | string |
tag | string |
Kind: instance method of NotificationsStorage
Param | Type | Default |
---|---|---|
senderId | string |
|
pageId | string |
|
[tag] | string |
null |
Kind: instance method of NotificationsStorage
Param | Type | Default |
---|---|---|
include | Array.<string> |
|
exclude | Array.<string> |
|
[pageId] | string |
null |
notificationsStorage.getSubscribtions(include, exclude, limit, [pageId], lastKey) ⇒ Promise.<{data: Array.<Target>, lastKey: string}>
Kind: instance method of NotificationsStorage
Param | Type | Default |
---|---|---|
include | Array.<string> |
|
exclude | Array.<string> |
|
limit | number |
|
[pageId] | string |
null |
lastKey | * |
|
Kind: instance method of NotificationsStorage
Param | Type |
---|---|
senderId | string |
pageId | string |
Kind: global class
Param | Type | Default | Description |
---|---|---|---|
mongoDb |
Db | Object
|
||
collectionName | string |
||
[log] | Object |
console like logger | |
[isCosmo] | boolean |
false |
Example
const { BaseStorage } = require('winbot-mongodb');
class MyCoolDataStorage extends BaseStorage {
constructor (mongoDb, collectionName = 'myCoolData', log = console, isCosmo = false) {
super(mongoDb, collectionName, log, isCosmo);
this.addIndex({
foo: -1
}, {
name: 'foo_1'
});
this.addIndex({
bar: -1,
baz: 1
}, {
name: 'bar_-1_baz_1'
});
}
}
baseStorage._collection : Collection
| Promise.<Collection>
Kind: instance property of BaseStorage
Insert defalt document to DB
Kind: instance method of BaseStorage
Param | Type |
---|---|
...objects | any |
Add custom indexing rule
Kind: instance method of BaseStorage
Param | Type |
---|---|
index | object |
options | mongodb.IndexOptions |
baseStorage._getCollection() ⇒ Promise.<Collection>
Returns the collection to operate with
Kind: instance method of BaseStorage
Kind: global typedef
Properties
Name | Type |
---|---|
senderId | string |
pageId | string |
state | object |
Kind: global typedef
Properties
Name | Type |
---|---|
[search] | string |
Kind: global typedef
Properties
Name | Type |
---|---|
senderId | string |
pageId | string |
token | string |
Kind: global typedef
Properties
Name | Type | Default |
---|---|---|
[type] | string |
"'audit'" |
category | string |
|
action | string |
|
[label] | string |
|
[payload] | object |
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
[id] | string |
|
[senderId] | string |
|
[pageId] | string |
|
[jwt] | string |
jwt to check the authorship |
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
[ip] | string |
|
[ua] | string |
|
[ro] | string |
referrer |
Kind: global typedef
Properties
Name | Type | Default | Description |
---|---|---|---|
date | string |
ISO date | |
delta | number |
time skew in ms if there was a write conflict | |
[eventType] | string |
"'audit'" |
|
category | string |
||
action | string |
||
[label] | string |
||
[payload] | object |
||
level | string |
(Critical | |
ok | boolean |
signature matches | |
seq | number |
sequence number | |
type | string |
(Error | |
user | User |
||
wid | string |
workspace id | |
meta | Meta |
JWT Verifier
Kind: global typedef
Param | Type |
---|---|
token | string |
userId | string |
[user] | User |
Kind: global typedef
Properties
Name | Type | Default | Description |
---|---|---|---|
date | string |
ISO date | |
[eventType] | string |
"'audit'" |
|
category | string |
||
action | string |
||
[label] | string |
||
[payload] | object |
||
level | string |
(Critical | |
type | string |
(Error | |
user | User |
||
wid | string |
workspace id | |
meta | Meta |
Audit Log Callback
Kind: global typedef
Param | Type |
---|---|
entry | AuditLogEntry |
Kind: global typedef
Properties
Name | Type |
---|---|
senderId | string |
pageId | string |
Kind: global typedef
Properties
Name | Type |
---|---|
senderId | string |
pageId | string |
subs | Array.<string> |
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
id | string |
|
name | string |
Tatgeting |
include | Array.<string> |
|
exclude | Array.<string> |
Stats |
sent | number |
|
succeeded | number |
|
failed | number |
|
unsubscribed | number |
|
delivery | number |
|
read | number |
|
notSent | number |
|
leaved | number |
|
queued | number |
Interaction |
action | string |
|
[data] | object |
Setup |
sliding | boolean |
|
slide | number |
|
slideRound | number |
|
active | boolean |
|
in24hourWindow | boolean |
|
startAt | number |
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
id | string |
|
pageId | string |
|
senderId | string |
|
campaignId | string |
|
enqueue | number |
|
[read] | number |
|
[delivery] | number |
|
[sent] | number |
|
[insEnqueue] | number |
|
[reaction] | boolean |
user reacted |
[leaved] | number |
time the event was not sent because user left |
Kind: global typedef