4.2.0 • Published 10 months ago

wingbot-mongodb v4.2.0

Weekly downloads
95
License
MIT
Repository
github
Last release
10 months ago

MongoDB plugin for wingbot.ai

Contains storage for tokens, chat states, bot config and chat logs.


API

Classes

Typedefs

StateStorage

Storage for chat states

Kind: global class

new StateStorage(mongoDb, collectionName, log, isCosmo)

ParamTypeDefaultDescription
mongoDbmongodb.Db | Object
collectionNamestring"states"
logObjectconsole like logger
isCosmobooleanfalse

stateStorage.addCustomIndex(index, options)

Deprecated

Add custom indexing rule

Kind: instance method of StateStorage

ParamType
indexobject
optionsobject
options.namestring

stateStorage.getState(senderId, pageId) ⇒ Promise.<(State|null)>

Kind: instance method of StateStorage

ParamType
senderIdstring
pageIdstring

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

ParamTypeDefaultDescription
senderIdstringsender identifier
pageIdstringpage identifier
defaultStateobjectdefault state of the conversation
timeoutnumber300given default state

stateStorage.getStates(condition, limit, lastKey) ⇒ Promise.<{Array.<data:State>, lastKey:string}>

Kind: instance method of StateStorage

ParamTypeDefault
conditionStateCondition
limitnumber20
lastKeystringnull

stateStorage.saveState(state) ⇒ Promise.<object>

Save the state to database

Kind: instance method of StateStorage

ParamTypeDescription
stateobjectconversation state

BotTokenStorage

Storage for webview tokens

Kind: global class

new BotTokenStorage(mongoDb, collectionName)

ParamTypeDefault
mongoDbmongodb.Db | Object
collectionNamestring"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

ParamType
tokenstring

botTokenStorage.getOrCreateToken(senderId, pageId, createToken) ⇒ Promise.<(Token|null)>

Kind: instance method of BotTokenStorage

ParamType
senderIdstring
pageIdstring
createTokenObject

ChatLogStorage

Storage for conversation logs

Kind: global class

new ChatLogStorage(mongoDb, collectionName, log, isCosmo, secret)

ParamTypeDefaultDescription
mongoDbDb | Object
collectionNamestring"chatlogs"
logObjectconsole like logger
isCosmobooleanfalse
secretstring | Promise.<string>null

chatLogStorage.getInteractions(senderId, pageId, limit, endAt, startAt) ⇒ Promise.<Array.<object>>

Interate history all limits are inclusive

Kind: instance method of ChatLogStorage

ParamTypeDefaultDescription
senderIdstring
pageIdstring
limitnumber10
endAtnumberiterate backwards to history
startAtnumberiterate forward to last interaction

chatLogStorage.log(senderId, responses, request, metadata) ⇒ Promise

Log single event

Kind: instance method of ChatLogStorage

ParamTypeDescription
senderIdstring
responsesArray.<object>list of sent responses
requestobjectevent request
metadataobjectrequest metadata

BotConfigStorage

Storage for wingbot.ai conversation config

Kind: global class

new BotConfigStorage(mongoDb, collectionName)

ParamTypeDefault
mongoDbDb | Object
collectionNamestring"botconfig"

botConfigStorage._collection : Collection

Kind: instance property of BotConfigStorage

botConfigStorage._getCollection() ⇒ Promise.<Collection>

Kind: instance method of BotConfigStorage

botConfigStorage.api(onUpdate, acl) ⇒ Object

Returns botUpdate API for wingbot

Kind: instance method of BotConfigStorage

ParamTypeDescription
onUpdatefunctionasync update handler function
aclfunction | 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, id) ⇒ Promise.<T>

Kind: instance method of BotConfigStorage

ParamType
newConfigT
idstring

botConfigStorage.setConfig(id, newConfig)

Kind: instance method of BotConfigStorage

ParamType
idstring
newConfigobject

botConfigStorage.getConfig(id) ⇒ Promise.<(object|null)>

Kind: instance method of BotConfigStorage

ParamType
idstring

AttachmentCache

Cache storage for Facebook attachments

Kind: global class

new AttachmentCache(mongoDb, collectionName)

ParamTypeDefault
mongoDbmongodb.Db | Object
collectionNamestring"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

ParamType
urlstring

attachmentCache.saveAttachmentId(url, attachmentId) ⇒ Promise

Kind: instance method of AttachmentCache

ParamType
urlstring
attachmentIdnumber

AuditLogStorage

Storage for audit logs with signatures chain

Kind: global class

new AuditLogStorage(mongoDb, collectionName, log, isCosmo, secret, jwtVerifier)

ParamTypeDefaultDescription
mongoDbDb | Object
collectionNamestring"auditlog"
logObjectconsole like logger
isCosmobooleanfalse
secretstring | Promise.<string>null
jwtVerifierstring | Promise.<string>null

auditLogStorage._jwtVerify : JwtVerifier

Kind: instance property of AuditLogStorage

auditLogStorage.callback : AuditLogCallback

Kind: instance property of AuditLogStorage

auditLogStorage.log(event, user, meta, wid, type, level, date) ⇒ Promise

Add a log

Kind: instance method of AuditLogStorage

ParamTypeDescription
eventTrackingEvent
userUser
metaMeta
widstringworkspace ID
typestring
levelstring
dateDate

auditLogStorage.list(wid, fromSeq, limit) ⇒ Promise.<Array.<LogEntry>>

Kind: instance method of AuditLogStorage

ParamTypeDefaultDescription
widstringworkspace id
fromSeqnumber0for paging
limitnumber40

NotificationsStorage

Kind: global class

new NotificationsStorage(mongoDb, collectionsPrefix, log, isCosmo)

ParamTypeDefaultDescription
mongoDbmongodb.Db | Object
collectionsPrefixstring
logObjectconsole like logger
isCosmobooleanfalse

notificationsStorage._collections : Map.<string, Promise.<mongodb.Collection>>

Kind: instance property of NotificationsStorage

notificationsStorage._getCollection(collectionName) ⇒ Promise.<mongodb.Collection>

Kind: instance method of NotificationsStorage

ParamType
collectionNamestring

notificationsStorage.pushTasks(tasks) ⇒ Promise.<Array.<Task>>

Kind: instance method of NotificationsStorage

ParamType
tasksobject

notificationsStorage.getUnsuccessfulSubscribersByCampaign(campaignId, sentWithoutReaction, pageId)

Kind: instance method of NotificationsStorage

ParamTypeDefault
campaignIdstring
sentWithoutReactionbooleanfalse
pageIdstringnull

notificationsStorage.getTaskById(taskId) ⇒ Promise.<(Task|null)>

Return Task By Id

Kind: instance method of NotificationsStorage

ParamType
taskIdstring

notificationsStorage.updateTask(taskId, data)

Kind: instance method of NotificationsStorage

ParamType
taskIdstring
dataobject

notificationsStorage.getSentTask(pageId, senderId, campaignId) ⇒ Promise.<(Task|null)>

Get last sent task from campaign

Kind: instance method of NotificationsStorage

ParamType
pageIdstring
senderIdstring
campaignIdstring

notificationsStorage.getSentCampagnIds(pageId, senderId, checkCampaignIds) ⇒ Promise.<Array.<string>>

Kind: instance method of NotificationsStorage

ParamType
pageIdstring
senderIdstring
checkCampaignIdsArray.<string>

notificationsStorage.updateTasksByWatermark(senderId, pageId, watermark, eventType, ts) ⇒ Promise.<Array.<Task>>

Kind: instance method of NotificationsStorage

ParamType
senderIdstring
pageIdstring
watermarknumber
eventType'read' | 'delivery'
tsnumber

notificationsStorage.upsertCampaign(campaign, updateCampaign) ⇒ Promise.<Campaign>

Kind: instance method of NotificationsStorage

ParamTypeDefault
campaignobject
updateCampaignobject

notificationsStorage.removeCampaign(campaignId) ⇒ Promise

Kind: instance method of NotificationsStorage

ParamType
campaignIdstring

notificationsStorage.incrementCampaign(campaignId, increment) ⇒ Promise

Kind: instance method of NotificationsStorage

ParamType
campaignIdstring
incrementobject

notificationsStorage.updateCampaign(campaignId, data) ⇒ Promise.<(Campaign|null)>

Kind: instance method of NotificationsStorage

ParamType
campaignIdstring
dataobject

notificationsStorage.popCampaign(now) ⇒ Promise.<(Campaign|null)>

Kind: instance method of NotificationsStorage

ParamType
nownumber

notificationsStorage.getCampaignById(campaignId) ⇒ Promise.<(null|Campaign)>

Kind: instance method of NotificationsStorage

ParamType
campaignIdstring

notificationsStorage.getCampaignByIds(campaignIds) ⇒ Promise.<Array.<Campaign>>

Kind: instance method of NotificationsStorage

ParamType
campaignIdsArray.<string>

notificationsStorage.getCampaigns(condition, limit, lastKey) ⇒ Promise.<{Array.<data:Campaign>, lastKey:string}>

Kind: instance method of NotificationsStorage

ParamTypeDefault
conditionobject
limitnumber
lastKeyobject

notificationsStorage.subscribe(senderId, pageId, tag) ⇒ Promise

Kind: instance method of NotificationsStorage

ParamType
senderIdstring
pageIdstring
tagstring

notificationsStorage.unsubscribe(senderId, pageId, tag) ⇒ Promise.<Array.<string>>

Kind: instance method of NotificationsStorage

ParamTypeDefault
senderIdstring
pageIdstring
tagstringnull

notificationsStorage.getSubscribtionsCount(include, exclude, pageId) ⇒ Promise.<number>

Kind: instance method of NotificationsStorage

ParamTypeDefault
includeArray.<string>
excludeArray.<string>
pageIdstringnull

notificationsStorage.getSubscribtions(include, exclude, limit, pageId, lastKey) ⇒ Promise.<{data: Array.<Target>, lastKey: string}>

Kind: instance method of NotificationsStorage

ParamTypeDefault
includeArray.<string>
excludeArray.<string>
limitnumber
pageIdstringnull
lastKey*

notificationsStorage.getSenderSubscribtions(senderId, pageId) ⇒ Promise.<Array.<string>>

Kind: instance method of NotificationsStorage

ParamType
senderIdstring
pageIdstring

BaseStorage

Kind: global class

new BaseStorage(mongoDb, collectionName, log, isCosmo)

ParamTypeDefaultDescription
mongoDbDb | Object
collectionNamestring
logObjectconsole like logger
isCosmobooleanfalse

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

baseStorage.addFixtureDoc(...objects)

Insert defalt document to DB

Kind: instance method of BaseStorage

ParamType
...objectsany

baseStorage.addIndex(index, options)

Add custom indexing rule

Kind: instance method of BaseStorage

ParamType
indexobject
optionsmongodb.IndexOptions

baseStorage._getCollection() ⇒ Promise.<Collection>

Returns the collection to operate with

Kind: instance method of BaseStorage

State : object

Kind: global typedef
Properties

NameType
senderIdstring
pageIdstring
stateobject

StateCondition : object

Kind: global typedef
Properties

NameType
searchstring

Token : object

Kind: global typedef
Properties

NameType
senderIdstring
pageIdstring
tokenstring

Db : module:mongodb/lib/db

Kind: global typedef

Db : module:mongodb/lib/db

Kind: global typedef

Collection : module:mongodb/lib/collection

Kind: global typedef

Db : module:mongodb/lib/db

Kind: global typedef

TrackingEvent : object

Kind: global typedef
Properties

NameTypeDefault
typestring"'audit'"
categorystring
actionstring
labelstring
payloadobject

User : object

Kind: global typedef
Properties

NameTypeDescription
idstring
senderIdstring
pageIdstring
jwtstringjwt to check the authorship

Meta : object

Kind: global typedef
Properties

NameTypeDescription
ipstring
uastring
rostringreferrerorigin

LogEntry : object

Kind: global typedef
Properties

NameTypeDefaultDescription
datestringISO date
deltanumbertime skew in ms if there was a write conflict
eventTypestring"'audit'"
categorystring
actionstring
labelstring
payloadobject
levelstring(CriticalImportantDebug)
okbooleansignature matches
seqnumbersequence number
typestring(ErrorWarnInfo)
userUser
widstringworkspace id
metaMeta

JwtVerifier ⇒ Promise.<boolean>

JWT Verifier

Kind: global typedef

ParamType
tokenstring
userIdstring
userUser

AuditLogEntry : object

Kind: global typedef
Properties

NameTypeDefaultDescription
datestringISO date
eventTypestring"'audit'"
categorystring
actionstring
labelstring
payloadobject
levelstring(CriticalImportantDebug)
typestring(ErrorWarnInfo)
userUser
widstringworkspace id
metaMeta

AuditLogCallback ⇒ Promise

Audit Log Callback

Kind: global typedef

ParamType
entryAuditLogEntry

Target : Object

Kind: global typedef
Properties

NameType
senderIdstring
pageIdstring

Subscribtion : Object

Kind: global typedef
Properties

NameType
senderIdstring
pageIdstring
subsArray.<string>

Campaign : object

Kind: global typedef
Properties

NameTypeDescription
idstring
namestringTatgeting
includeArray.<string>
excludeArray.<string>Stats
sentnumber
succeedednumber
failednumber
unsubscribednumber
deliverynumber
readnumber
notSentnumber
leavednumber
queuednumberInteraction
actionstring
dataobjectSetup
slidingboolean
slidenumber
slideRoundnumber
activeboolean
in24hourWindowboolean
startAtnumber

Task : Object

Kind: global typedef
Properties

NameTypeDescription
idstring
pageIdstring
senderIdstring
campaignIdstring
enqueuenumber
readnumber
deliverynumber
sentnumber
insEnqueuenumber
reactionbooleanuser reacted
leavednumbertime the event was not sent because user left

Db : module:mongodb/lib/db

Kind: global typedef

Collection : module:mongodb/lib/collection

Kind: global typedef

4.2.0

10 months ago

4.1.2

1 year ago

4.1.1

1 year ago

4.1.0

2 years ago

4.0.0-alpha.7

2 years ago

4.0.0-alpha.5

2 years ago

4.0.0-alpha.3

2 years ago

4.0.0-alpha.4

2 years ago

4.0.0-alpha.1

2 years ago

4.0.0-alpha.2

2 years ago

3.2.6

2 years ago

3.2.6-alpha.1

2 years ago

4.0.0

2 years ago

3.2.5-test.1

2 years ago

3.2.2

2 years ago

3.2.1

2 years ago

3.2.0

2 years ago

3.2.5

2 years ago

3.2.4

2 years ago

3.2.3

2 years ago

3.1.2

3 years ago

3.0.0

3 years ago

2.22.1

3 years ago

2.22.0

3 years ago

2.21.8-canary.1

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

2.21.3-beta.1

3 years ago

2.21.3-beta.2

3 years ago

3.0.0-alpha.7

3 years ago

2.21.7

3 years ago

3.0.0-alpha.9

3 years ago

3.0.0-alpha.8

3 years ago

2.21.4

3 years ago

2.21.3

3 years ago

2.21.6

3 years ago

2.21.5

3 years ago

3.0.0-alpha.10

3 years ago

2.22.0-alpha.6

3 years ago

2.22.0-alpha.5

3 years ago

2.22.0-alpha.4

3 years ago

2.22.0-alpha.3

3 years ago

2.22.0-alpha.2

3 years ago

2.22.0-alpha.1

3 years ago

2.21.0

3 years ago

2.21.2

3 years ago

2.21.1

3 years ago

2.19.0

4 years ago

2.19.1

4 years ago

2.20.0

4 years ago

2.20.1

4 years ago

2.17.0

4 years ago

2.18.0

4 years ago

2.17.0-alpha.1

4 years ago

2.16.3

4 years ago

2.16.2

4 years ago

2.16.1

4 years ago

2.16.0

4 years ago

2.16.0-alpha.11

4 years ago

2.16.0-alpha.12

4 years ago

2.16.0-alpha.13

4 years ago

2.16.0-alpha.8

4 years ago

2.16.0-alpha.9

4 years ago

2.16.0-alpha.6

4 years ago

2.16.0-alpha.7

4 years ago

2.16.0-alpha.4

4 years ago

2.16.0-alpha.5

4 years ago

2.16.0-alpha.10

4 years ago

2.16.0-alpha.3

5 years ago

2.16.0-alpha.2

5 years ago

2.16.0-alpha.1

5 years ago

2.15.3

6 years ago

2.15.2

6 years ago

2.15.1

6 years ago

2.15.0

6 years ago

2.15.0-alpha.2

6 years ago

2.15.0-alpha.1

6 years ago

2.10.0

6 years ago

2.5.6

6 years ago

2.5.5

6 years ago

2.5.4

6 years ago

2.5.3

6 years ago

2.5.2

6 years ago

2.5.1

6 years ago

2.5.0

6 years ago

2.5.0-alpha.1

6 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

2.0.0-alpha.4

7 years ago

2.0.0-alpha.3

7 years ago

2.0.0-alpha.2

7 years ago

2.0.0-alpha.1

7 years ago

1.3.0-alpha.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.1.0-alpha.3

7 years ago

1.1.0-alpha.2

7 years ago

1.1.0-alpha.1

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago