Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wingbot-mongodb

Package Overview
Dependencies
Maintainers
0
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wingbot-mongodb

MongoDB storage for wingbot.ai

  • 4.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
45
increased by66.67%
Maintainers
0
Weekly downloads
 
Created
Source

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

AuditLogStorage

Storage for audit logs with signatures chain

NotificationsStorage
BaseStorage

Typedefs

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
JwtVerifierPromise.<boolean>

JWT Verifier

AuditLogEntry : object
AuditLogCallbackPromise

Audit Log Callback

Target : Object
Subscribtion : Object
Campaign : object
Task : Object
Db : module:mongodb/lib/db
Collection : module:mongodb/lib/collection

StateStorage

Storage for chat states

Kind: global class

new StateStorage(mongoDb, collectionName, [log], isCosmo)

ParamTypeDefaultDescription
mongoDbmongodb.Db | Object
collectionNamestring"states"
[log]Objectconsole 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
[defaultState]objectdefault state of the conversation
[timeout]number300given 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"
[log]Objectconsole like logger
[isCosmo]booleanfalse
[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

ParamTypeDefaultDescription
senderIdstring
pageIdstring
[limit]number10
[endAt]numberiterate backwards to history
[startAt]numberiterate 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
[metadata]objectrequest 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
[onUpdate]functionasync 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, [id]) ⇒ Promise.<T>

Kind: instance method of BotConfigStorage

ParamType
newConfigT
[id]string

botConfigStorage.setConfig(id, newConfig)

Kind: instance method of BotConfigStorage

ParamType
idstring
newConfigobject

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

Kind: instance method of BotConfigStorage

ParamType
[id]string

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"
[log]Objectconsole like logger
[isCosmo]booleanfalse
[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

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

Add a log

Kind: instance method of AuditLogStorage

ParamTypeDescription
eventTrackingEvent
userUser
[meta]Meta
[wid]stringworkspace ID
[type]string
[level]string
[date]Date

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

Kind: instance method of AuditLogStorage

ParamTypeDefaultDescription
[wid]stringworkspace id
[fromSeq]number0for paging
[limit]number40

NotificationsStorage

Kind: global class

new NotificationsStorage(mongoDb, collectionsPrefix, [log], isCosmo)

ParamTypeDefaultDescription
mongoDbmongodb.Db | Object
collectionsPrefixstring
[log]Objectconsole 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
[sentWithoutReaction]booleanfalse
[pageId]stringnull

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
[updateCampaign]object

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
[now]number

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
[limit]number
[lastKey]object

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
[tag]stringnull

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

Kind: instance method of NotificationsStorage

ParamTypeDefault
includeArray.<string>
excludeArray.<string>
[pageId]stringnull

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

Kind: instance method of NotificationsStorage

ParamTypeDefault
includeArray.<string>
excludeArray.<string>
limitnumber
[pageId]stringnull
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
[log]Objectconsole like logger
[isCosmo]booleanfalse

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
[search]string

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
[type]string"'audit'"
categorystring
actionstring
[label]string
[payload]object

User : object

Kind: global typedef
Properties

NameTypeDescription
[id]string
[senderId]string
[pageId]string
[jwt]stringjwt to check the authorship

Meta : object

Kind: global typedef
Properties

NameTypeDescription
[ip]string
[ua]string
[ro]stringreferrer

LogEntry : object

Kind: global typedef
Properties

NameTypeDefaultDescription
datestringISO date
deltanumbertime skew in ms if there was a write conflict
[eventType]string"'audit'"
categorystring
actionstring
[label]string
[payload]object
levelstring(Critical
okbooleansignature matches
seqnumbersequence number
typestring(Error
userUser
widstringworkspace id
metaMeta

JwtVerifier ⇒ Promise.<boolean>

JWT Verifier

Kind: global typedef

ParamType
tokenstring
userIdstring
[user]User

AuditLogEntry : object

Kind: global typedef
Properties

NameTypeDefaultDescription
datestringISO date
[eventType]string"'audit'"
categorystring
actionstring
[label]string
[payload]object
levelstring(Critical
typestring(Error
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
[data]objectSetup
slidingboolean
slidenumber
slideRoundnumber
activeboolean
in24hourWindowboolean
startAtnumber

Task : Object

Kind: global typedef
Properties

NameTypeDescription
idstring
pageIdstring
senderIdstring
campaignIdstring
enqueuenumber
[read]number
[delivery]number
[sent]number
[insEnqueue]number
[reaction]booleanuser reacted
[leaved]numbertime the event was not sent because user left

Db : module:mongodb/lib/db

Kind: global typedef

Collection : module:mongodb/lib/collection

Kind: global typedef

Keywords

FAQs

Package last updated on 09 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc