wingbot-dynamodb

3.3.1 • Public • Published

DynamoDB plugin for wingbot

DynamoDB tables definition

All tables uses ${self:custom.prefix} to be able to use configuration on different bots and environments.

Conversation States and bot configuration

StatesTable:
    Type: AWS::DynamoDB::Table
    Properties:
    TableName: ${self:custom.prefix}-states
    AttributeDefinitions:
      - AttributeName: senderId
        AttributeType: S
      - AttributeName: pageId
        AttributeType: S
    KeySchema:
      - AttributeName: senderId
        KeyType: HASH
      - AttributeName: pageId
        KeyType: RANGE
    ProvisionedThroughput:
      ReadCapacityUnits: 1
      WriteCapacityUnits: 1

BotConfigTable:
    Type: AWS::DynamoDB::Table
    Properties:
    TableName: ${self:custom.prefix}-botconfig
    AttributeDefinitions:
      - AttributeName: k
        AttributeType: S
    KeySchema:
      - AttributeName: k
        KeyType: HASH
    ProvisionedThroughput:
      ReadCapacityUnits: 1
      WriteCapacityUnits: 1

Chat Logs (optional)

ChatlogTable:
    Type: AWS::DynamoDB::Table
    Properties:
    TableName: ${self:custom.prefix}-chatlog
    AttributeDefinitions:
      - AttributeName: userId
        AttributeType: S
      - AttributeName: timestamp
        AttributeType: N
    KeySchema:
      - AttributeName: userId
        KeyType: HASH
      - AttributeName: timestamp
        KeyType: RANGE
    ProvisionedThroughput:
      ReadCapacityUnits: 1
      WriteCapacityUnits: 1

Chatbot tokens (optional)

BottokensTable:
    Type: AWS::DynamoDB::Table
    Properties:
    TableName: ${self:custom.prefix}-bottokens
    AttributeDefinitions:
      - AttributeName: senderId
        AttributeType: S
      - AttributeName: token
        AttributeType: S
      - AttributeName: pageId
        AttributeType: S
    KeySchema:
      - AttributeName: senderId
        KeyType: HASH
      - AttributeName: pageId
        KeyType: RANGE
    GlobalSecondaryIndexes:
        - IndexName: token
        KeySchema:
            - AttributeName: token
            KeyType: HASH
        Projection:
            ProjectionType: ALL
        ProvisionedThroughput:
            ReadCapacityUnits: 1
            WriteCapacityUnits: 1
    ProvisionedThroughput:
        ReadCapacityUnits: 1
        WriteCapacityUnits: 1

Facebook Attachment cache (optional)

AttachmentsTable:
  Type: AWS::DynamoDB::Table
  Properties:
    TableName: ${self:custom.prefix}-attachments
    AttributeDefinitions:
      - AttributeName: url
        AttributeType: S
    KeySchema:
      - AttributeName: url
        KeyType: HASH
    ProvisionedThroughput:
      ReadCapacityUnits: 1
      WriteCapacityUnits: 1

API

Classes

StateStorage

Conversation state DynamoDB storage

BotTokenStorage

Conversation DynamoDB state storage

ChatLogStorage

DynamoDB Chat Log storage

BotConfigStorage

Storage for wingbot.ai conversation config

AttachmentCache

Storage for Facebook attachment ids

Typedefs

State : Object
Token : Object

StateStorage

Conversation state DynamoDB storage

Kind: global class

new StateStorage([tableName], [dynamoDbService])

Param Type Default Description
[tableName] string "states"
[dynamoDbService] AWS.DynamoDB preconfigured dynamodb service

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>

Kind: instance method of StateStorage Returns: Promise.<Object> - - conversation state

Param Type Default Description
senderId string sender identifier
pageId string page/channel identifier
[defaultState] Object default state of the conversation
[timeout] number 300 given default state

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

Kind: instance method of StateStorage

Param Type Description
state Object conversation state

BotTokenStorage

Conversation DynamoDB state storage

Kind: global class

new BotTokenStorage([tableName], [tokensIndexName], [dynamoDbService])

Param Type Default Description
[tableName] string "wingbot-tokens" the table name
[tokensIndexName] string "token" index to query table by token
[dynamoDbService] AWS.DynamoDB preconfigured dynamodb service

botTokenStorage.findByToken(token) ⇒ Promise.<(Token|null)>

Kind: instance method of BotTokenStorage

Param Type
token string

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

Kind: instance method of BotTokenStorage

Param Type
senderId string
pageId string
customTokenFactory Object

botTokenStorage._getToken(senderId, pageId) ⇒ Promise.<({senderId:string, token:string}|null)>

Kind: instance method of BotTokenStorage

Param Type
senderId string
pageId string

ChatLogStorage

DynamoDB Chat Log storage

Kind: global class

new ChatLogStorage([tableName], [dynamoDbService], [log])

Param Type Default Description
[tableName] string "chatlog"
[dynamoDbService] AWS.DynamoDB preconfigured dynamodb service
[log] Object console like logger

chatLogStorage.log(userId, responses, request) ⇒ Promise

Log single event

Kind: instance method of ChatLogStorage

Param Type Description
userId string
responses Array.<Object> list of sent responses
request Object event request

BotConfigStorage

Storage for wingbot.ai conversation config

Kind: global class

new BotConfigStorage([tableName], [dynamoDbService])

Param Type Default Description
[tableName] string "wingbot-config" the table name
[dynamoDbService] AWS.DynamoDB preconfigured dynamodb service

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

Param Type
newConfig T

botConfigStorage.getConfig() ⇒ Promise.<(Object|null)>

Kind: instance method of BotConfigStorage

AttachmentCache

Storage for Facebook attachment ids

Kind: global class

new AttachmentCache([tableName], [dynamoDbService])

Param Type Default Description
[tableName] string "wingbot-attachment-cache" the table name
[dynamoDbService] AWS.DynamoDB preconfigured dynamodb service

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

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

Package Sidebar

Install

npm i wingbot-dynamodb

Weekly Downloads

3

Version

3.3.1

License

MIT

Unpacked Size

90.2 kB

Total Files

20

Last publish

Collaborators

  • wingbot.ai