npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wingbot-mongodb

v4.2.0

Published

MongoDB storage for wingbot.ai

Downloads

289

Readme

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)

| Param | Type | Default | Description | | --- | --- | --- | --- | | mongoDb | mongodb.Db | Object | | | | collectionName | string | "states" | | | [log] | Object | | console like logger | | isCosmo | boolean | false | |

~~stateStorage.addCustomIndex(index, options)~~

Deprecated

Add custom indexing rule

Kind: instance method of StateStorage

| Param | Type | | --- | --- | | index | object | | options | object | | options.name | string |

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.getStates(condition, limit, lastKey) ⇒ Promise.<{Array.<data:State>, lastKey:string}>

Kind: instance method of StateStorage

| Param | Type | Default | | --- | --- | --- | | condition | StateCondition | | | limit | number | 20 | | lastKey | string | null |

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

| Param | Type | | --- | --- | | token | string |

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], [isCosmo], [secret])

| 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 |

chatLogStorage.log(senderId, responses, request, [metadata]) ⇒ 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 | | [metadata] | object | request metadata |

BotConfigStorage

Storage for wingbot.ai conversation config

Kind: global class

new BotConfigStorage(mongoDb, collectionName)

| 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

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, [id]) ⇒ Promise.<T>

Kind: instance method of BotConfigStorage

| Param | Type | | --- | --- | | newConfig | T | | [id] | string |

botConfigStorage.setConfig(id, newConfig)

Kind: instance method of BotConfigStorage

| Param | Type | | --- | --- | | id | string | | newConfig | object |

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

Kind: instance method of BotConfigStorage

| Param | Type | | --- | --- | | [id] | string |

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

| Param | Type | | --- | --- | | url | string |

attachmentCache.saveAttachmentId(url, attachmentId) ⇒ Promise

Kind: instance method of AttachmentCache

| Param | Type | | --- | --- | | url | string | | attachmentId | number |

AuditLogStorage

Storage for audit logs with signatures chain

Kind: global class

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

| 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

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

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 | |

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

Kind: instance method of AuditLogStorage

| Param | Type | Default | Description | | --- | --- | --- | --- | | [wid] | string | | workspace id | | [fromSeq] | number | 0 | for paging | | [limit] | number | 40 | |

NotificationsStorage

Kind: global class

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

| Param | Type | Default | Description | | --- | --- | --- | --- | | mongoDb | mongodb.Db | Object | | | | collectionsPrefix | string | | | | [log] | Object | | console like logger | | isCosmo | boolean | false | |

notificationsStorage._collections : Map.<string, Promise.<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

| 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 |

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

Return Task By Id

Kind: instance method of NotificationsStorage

| Param | Type | | --- | --- | | taskId | string |

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, [updateCampaign]) ⇒ Promise.<Campaign>

Kind: instance method of NotificationsStorage

| Param | Type | Default | | --- | --- | --- | | campaign | object | | | [updateCampaign] | object | |

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

| Param | Type | | --- | --- | | [now] | number |

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 |

BaseStorage

Kind: global class

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

| 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

baseStorage.addFixtureDoc(...objects)

Insert defalt document to DB

Kind: instance method of BaseStorage

| Param | Type | | --- | --- | | ...objects | any |

baseStorage.addIndex(index, options)

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

State : object

Kind: global typedef
Properties

| Name | Type | | --- | --- | | senderId | string | | pageId | string | | state | object |

StateCondition : object

Kind: global typedef
Properties

| Name | Type | | --- | --- | | [search] | string |

Token : object

Kind: global typedef
Properties

| Name | Type | | --- | --- | | senderId | string | | pageId | string | | token | string |

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

| Name | Type | Default | | --- | --- | --- | | [type] | string | "'audit'" | | category | string | | | action | string | | | [label] | string | | | [payload] | object | |

User : object

Kind: global typedef
Properties

| Name | Type | Description | | --- | --- | --- | | [id] | string | | | [senderId] | string | | | [pageId] | string | | | [jwt] | string | jwt to check the authorship |

Meta : object

Kind: global typedef
Properties

| Name | Type | Description | | --- | --- | --- | | [ip] | string | | | [ua] | string | | | [ro] | string | referrer || origin |

LogEntry : object

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|Important|Debug) | | ok | boolean | | signature matches | | seq | number | | sequence number | | type | string | | (Error|Warn|Info) | | user | User | | | | wid | string | | workspace id | | meta | Meta | | |

JwtVerifier ⇒ Promise.<boolean>

JWT Verifier

Kind: global typedef

| Param | Type | | --- | --- | | token | string | | userId | string | | [user] | User |

AuditLogEntry : object

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|Important|Debug) | | type | string | | (Error|Warn|Info) | | user | User | | | | wid | string | | workspace id | | meta | Meta | | |

AuditLogCallback ⇒ Promise

Audit Log Callback

Kind: global typedef

| Param | Type | | --- | --- | | entry | AuditLogEntry |

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 | | | slideRound | number | | | active | boolean | | | in24hourWindow | boolean | | | startAt | number | |

Task : Object

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 |

Db : module:mongodb/lib/db

Kind: global typedef

Collection : module:mongodb/lib/collection

Kind: global typedef