3.3.1 • Published 7 months ago

wingbot-dynamodb v3.3.1

Weekly downloads
4
License
MIT
Repository
github
Last release
7 months ago

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

Typedefs

StateStorage

Conversation state DynamoDB storage

Kind: global class

new StateStorage(tableName, dynamoDbService)

ParamTypeDefaultDescription
tableNamestring"states"
dynamoDbServiceAWS.DynamoDBpreconfigured dynamodb service

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

Kind: instance method of StateStorage

ParamType
senderIdstring
pageIdstring

stateStorage.getOrCreateAndLock(senderId, pageId, defaultState, timeout) ⇒ Promise.<Object>

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

ParamTypeDefaultDescription
senderIdstringsender identifier
pageIdstringpage/channel identifier
defaultStateObjectdefault state of the conversation
timeoutnumber300given default state

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

Kind: instance method of StateStorage

ParamTypeDescription
stateObjectconversation state

BotTokenStorage

Conversation DynamoDB state storage

Kind: global class

new BotTokenStorage(tableName, tokensIndexName, dynamoDbService)

ParamTypeDefaultDescription
tableNamestring"wingbot-tokens"the table name
tokensIndexNamestring"token"index to query table by token
dynamoDbServiceAWS.DynamoDBpreconfigured dynamodb service

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

Kind: instance method of BotTokenStorage

ParamType
tokenstring

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

Kind: instance method of BotTokenStorage

ParamType
senderIdstring
pageIdstring
customTokenFactoryObject

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

Kind: instance method of BotTokenStorage

ParamType
senderIdstring
pageIdstring

ChatLogStorage

DynamoDB Chat Log storage

Kind: global class

new ChatLogStorage(tableName, dynamoDbService, log)

ParamTypeDefaultDescription
tableNamestring"chatlog"
dynamoDbServiceAWS.DynamoDBpreconfigured dynamodb service
logObjectconsole like logger

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

Log single event

Kind: instance method of ChatLogStorage

ParamTypeDescription
userIdstring
responsesArray.<Object>list of sent responses
requestObjectevent request

BotConfigStorage

Storage for wingbot.ai conversation config

Kind: global class

new BotConfigStorage(tableName, dynamoDbService)

ParamTypeDefaultDescription
tableNamestring"wingbot-config"the table name
dynamoDbServiceAWS.DynamoDBpreconfigured dynamodb service

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) ⇒ Promise.<T>

Kind: instance method of BotConfigStorage Template: T

ParamType
newConfigT

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

Kind: instance method of BotConfigStorage

AttachmentCache

Storage for Facebook attachment ids

Kind: global class

new AttachmentCache(tableName, dynamoDbService)

ParamTypeDefaultDescription
tableNamestring"wingbot-attachment-cache"the table name
dynamoDbServiceAWS.DynamoDBpreconfigured dynamodb service

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

State : Object

Kind: global typedef Properties

NameType
senderIdstring
pageIdstring
stateObject

Token : Object

Kind: global typedef Properties

NameType
senderIdstring
pageIdstring
tokenstring
3.3.1

7 months ago

3.3.0

7 months ago

3.2.1

1 year ago

3.2.0

1 year ago

3.2.0-alpha.1

1 year ago

3.2.0-alpha.2

1 year ago

3.2.0-alpha.3

1 year ago

3.1.0

2 years ago

3.1.0-alpha.1

2 years ago

3.0.0

2 years ago

2.5.0

5 years ago

2.0.0

5 years ago

2.0.0-alpha.4

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.1.0-alpha.1

6 years ago

1.0.0-alpha.3

6 years ago

1.0.0-alpha.2

6 years ago

1.0.0-alpha.1

6 years ago