MongoDB plugin for wingbot.ai
Contains storage for tokens, chat states, bot config and chat logs.
API
Classes
- 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
- NotificationsStorage
Typedefs
- State :
Object
- Token :
Object
- Target :
Object
- Subscribtion :
Object
- Campaign :
Object
- Task :
Object
StateStorage
Storage for chat states
Kind: global class
new StateStorage(mongoDb, collectionName)
Param | Type | Default |
---|
mongoDb | mongodb.Db | Object | |
collectionName | string | "states" |
stateStorage._collection : mongodb.Collection
Kind: instance property of StateStorage
stateStorage._getCollection() ⇒ Promise.<mongodb.Collection>
Kind: instance method of StateStorage
stateStorage.getState(senderId, pageId) ⇒ Promise.<(State|null)>
Kind: instance method of StateStorage
Param | Type |
---|
senderId | string |
pageId | string |
stateStorage.getOrCreateAndLock(senderId, pageId, [defaultState], [timeout]) ⇒ Promise.<Object>
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 |
stateStorage.saveState(state) ⇒ Promise.<Object>
Save the state to database
Kind: instance method of StateStorage
Param | Type | Description |
---|
state | Object | conversation state |
BotTokenStorage
Storage for webview tokens
Kind: global class
new BotTokenStorage(mongoDb, collectionName)
Param | Type | Default |
---|
mongoDb | mongodb.Db | Object | |
collectionName | string | "tokens" |
botTokenStorage._collection : mongodb.Collection
Kind: instance property of BotTokenStorage
botTokenStorage._getCollection() ⇒ Promise.<mongodb.Collection>
Kind: instance method of BotTokenStorage
botTokenStorage.findByToken(token) ⇒ Promise.<(Token|null)>
Kind: instance method of BotTokenStorage
botTokenStorage.getOrCreateToken(senderId, pageId, createToken) ⇒ Promise.<(Token|null)>
Kind: instance method of BotTokenStorage
Param | Type |
---|
senderId | string |
pageId | string |
createToken | Object |
ChatLogStorage
Storage for conversation logs
Kind: global class
new ChatLogStorage(mongoDb, collectionName, [log])
Param | Type | Default | Description |
---|
mongoDb | mongodb.Db | Object | | |
collectionName | string | "chatlogs" | |
[log] | Object | | console like logger |
chatLogStorage._collection : mongodb.Collection
Kind: instance property of ChatLogStorage
chatLogStorage._getCollection() ⇒ Promise.<mongodb.Collection>
Kind: instance method of ChatLogStorage
chatLogStorage.log(senderId, responses, request) ⇒ Promise
Log single event
Kind: instance method of ChatLogStorage
Param | Type | Description |
---|
senderId | string | |
responses | Array.<Object> | list of sent responses |
request | Object | event request |
BotConfigStorage
Storage for wingbot.ai conversation config
Kind: global class
new BotConfigStorage(mongoDb, collectionName)
Param | Type | Default |
---|
mongoDb | mongodb.Db | Object | |
collectionName | string | "botconfig" |
botConfigStorage._collection : mongodb.Collection
Kind: instance property of BotConfigStorage
botConfigStorage._getCollection() ⇒ Promise.<mongodb.Collection>
Kind: instance method of BotConfigStorage
botConfigStorage.api([onUpdate], [acl]) ⇒ Object
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 |
botConfigStorage.invalidateConfig() ⇒ Promise
Invalidates current configuration
Kind: instance method of BotConfigStorage
botConfigStorage.getConfigTimestamp() ⇒ Promise.<number>
Kind: instance method of BotConfigStorage
botConfigStorage.updateConfig(newConfig) ⇒ Promise.<T>
Kind: instance method of BotConfigStorage
Template: T
botConfigStorage.getConfig() ⇒ Promise.<(Object|null)>
Kind: instance method of BotConfigStorage
AttachmentCache
Cache storage for Facebook attachments
Kind: global class
new AttachmentCache(mongoDb, collectionName)
Param | Type | Default |
---|
mongoDb | mongodb.Db | Object | |
collectionName | string | "attachments" |
attachmentCache._collection : mongodb.Collection
Kind: instance property of AttachmentCache
attachmentCache._getCollection() ⇒ Promise.<mongodb.Collection>
Kind: instance method of AttachmentCache
attachmentCache.findAttachmentByUrl(url) ⇒ Promise.<(number|null)>
Kind: instance method of AttachmentCache
attachmentCache.saveAttachmentId(url, attachmentId) ⇒ Promise
Kind: instance method of AttachmentCache
Param | Type |
---|
url | string |
attachmentId | number |
NotificationsStorage
Kind: global class
- NotificationsStorage
- new NotificationsStorage(mongoDb, collectionsPrefix)
- ._collections :
Map.<string, mongodb.Collection>
- ._getCollection(collectionName) ⇒
Promise.<mongodb.Collection>
- .pushTasks(tasks) ⇒
Promise.<Array.<Task>>
- .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) ⇒
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>>
new NotificationsStorage(mongoDb, collectionsPrefix)
Param | Type |
---|
mongoDb | mongodb.Db | Object |
collectionsPrefix | string |
notificationsStorage._collections : Map.<string, mongodb.Collection>
Kind: instance property of NotificationsStorage
notificationsStorage._getCollection(collectionName) ⇒ Promise.<mongodb.Collection>
Kind: instance method of NotificationsStorage
Param | Type |
---|
collectionName | string |
notificationsStorage.pushTasks(tasks) ⇒ Promise.<Array.<Task>>
Kind: instance method of NotificationsStorage
notificationsStorage.updateTask(taskId, data)
Kind: instance method of NotificationsStorage
Param | Type |
---|
taskId | string |
data | Object |
notificationsStorage.getSentTask(pageId, senderId, campaignId) ⇒ Promise.<(Task|null)>
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) ⇒ Promise.<Campaign>
Kind: instance method of NotificationsStorage
notificationsStorage.removeCampaign(campaignId) ⇒ Promise
Kind: instance method of NotificationsStorage
Param | Type |
---|
campaignId | string |
notificationsStorage.incrementCampaign(campaignId, increment) ⇒ Promise
Kind: instance method of NotificationsStorage
Param | Type |
---|
campaignId | string |
increment | Object |
notificationsStorage.updateCampaign(campaignId, data) ⇒ Promise.<(Campaign|null)>
Kind: instance method of NotificationsStorage
Param | Type |
---|
campaignId | string |
data | Object |
notificationsStorage.popCampaign([now]) ⇒ Promise.<(Campaign|null)>
Kind: instance method of NotificationsStorage
notificationsStorage.getCampaignById(campaignId) ⇒ Promise.<(null|Campaign)>
Kind: instance method of NotificationsStorage
Param | Type |
---|
campaignId | string |
notificationsStorage.getCampaignByIds(campaignIds) ⇒ Promise.<Array.<Campaign>>
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 |
|
notificationsStorage.subscribe(senderId, pageId, tag) ⇒ Promise
Kind: instance method of NotificationsStorage
Param | Type |
---|
senderId | string |
pageId | string |
tag | string |
notificationsStorage.unsubscribe(senderId, pageId, [tag]) ⇒ Promise.<Array.<string>>
Kind: instance method of NotificationsStorage
Param | Type | Default |
---|
senderId | string | |
pageId | string | |
[tag] | string | null |
notificationsStorage.getSubscribtionsCount(include, exclude, [pageId]) ⇒ Promise.<number>
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 | * |
|
notificationsStorage.getSenderSubscribtions(senderId, pageId) ⇒ Promise.<Array.<string>>
Kind: instance method of NotificationsStorage
Param | Type |
---|
senderId | string |
pageId | string |
State : Object
Kind: global typedef
Properties
Name | Type |
---|
senderId | string |
pageId | string |
state | Object |
Token : Object
Kind: global typedef
Properties
Name | Type |
---|
senderId | string |
pageId | string |
token | string |
Target : Object
Kind: global typedef
Properties
Name | Type |
---|
senderId | string |
pageId | string |
Subscribtion : Object
Kind: global typedef
Properties
Name | Type |
---|
senderId | string |
pageId | string |
subs | Array.<string> |
Campaign : Object
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 | |
active | boolean | |
in24hourWindow | boolean | |
startAt | number | |
Task : Object
Kind: global typedef
Properties
Name | Type |
---|
id | string |
pageId | string |
senderId | string |
campaignId | string |
enqueue | number |
[read] | number |
[delivery] | number |
[sent] | number |
[insEnqueue] | number |