wingbot-dynamodb v3.3.1
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
- StateStorage
- new StateStorage([tableName], [dynamoDbService])
- .getState(senderId, pageId) ⇒ Promise.<(State|null)>
- .getOrCreateAndLock(senderId, pageId, [defaultState], [timeout]) ⇒ Promise.<Object>
- .saveState(state) ⇒ Promise.<Object>
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
- BotTokenStorage
- new BotTokenStorage([tableName], [tokensIndexName], [dynamoDbService])
- .findByToken(token) ⇒ Promise.<(Token|null)>
- .getOrCreateToken(senderId, pageId, customTokenFactory) ⇒ Promise.<(Token|null)>
- ._getToken(senderId, pageId) ⇒ Promise.<({senderId:string, token:string}|null)>
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
- BotConfigStorage
- new BotConfigStorage([tableName], [dynamoDbService])
- .api([onUpdate], [acl]) ⇒ Object
- .invalidateConfig() ⇒ Promise
- .getConfigTimestamp() ⇒ Promise.<number>
- .updateConfig(newConfig) ⇒ Promise.<T>
- .getConfig() ⇒ Promise.<(Object|null)>
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
- AttachmentCache
- new AttachmentCache([tableName], [dynamoDbService])
- .findAttachmentByUrl(url) ⇒ Promise.<(number|null)>
- .saveAttachmentId(url, attachmentId) ⇒ Promise
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 |
7 months ago
7 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago