DynamoDB storage for wingbot
npm install wingbot-dynamodbAll tables uses ${self:custom.prefix} to be able to use configuration on different bots and environments.
``yaml
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
`
`yaml`
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
`yaml`
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
`yaml``
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
-----------------
Conversation state DynamoDB storage
Conversation DynamoDB state storage
DynamoDB Chat Log storage
Storage for wingbot.ai conversation config
Storage for Facebook attachment ids
Kind: global class
* StateStorage
* [new StateStorage([tableName], [dynamoDbService])](#new_StateStorage_new)
* .getState(senderId, pageId) ⇒ Promise.<(State\|null)>
* [.getOrCreateAndLock(senderId, pageId, [defaultState], [timeout])](#StateStorage+getOrCreateAndLock) ⇒ Promise.<Object>
* .saveState(state) ⇒ Promise.<Object>
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [tableName] | string | "states" | |
| [dynamoDbService] | AWS.DynamoDB | | preconfigured dynamodb service |
StateStorage| Param | Type |
| --- | --- |
| senderId | string |
| pageId | string |
StateStoragePromise.<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| Param | Type | Description |
| --- | --- | --- |
| state | Object | conversation state |
Kind: global class
* BotTokenStorage
* [new BotTokenStorage([tableName], [tokensIndexName], [dynamoDbService])](#new_BotTokenStorage_new)
* .findByToken(token) ⇒ Promise.<(Token\|null)>
* .getOrCreateToken(senderId, pageId, customTokenFactory) ⇒ Promise.<(Token\|null)>
* ._getToken(senderId, pageId) ⇒ Promise.<({senderId:string, token:string}\|null)>
| 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| Param | Type |
| --- | --- |
| token | string |
BotTokenStorage| Param | Type |
| --- | --- |
| senderId | string |
| pageId | string |
| customTokenFactory | Object |
BotTokenStorage| Param | Type |
| --- | --- |
| senderId | string |
| pageId | string |
Kind: global class
* ChatLogStorage
* [new ChatLogStorage([tableName], [dynamoDbService], [log])](#new_ChatLogStorage_new)
* .log(userId, responses, request) ⇒ Promise
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [tableName] | string | "chatlog" | |
| [dynamoDbService] | AWS.DynamoDB | | preconfigured dynamodb service |
| [log] | Object | | console like logger |
Kind: instance method of ChatLogStorage
| Param | Type | Description |
| --- | --- | --- |
| userId | string | |
| responses | Array.<Object> | list of sent responses |
| request | Object | event request |
Kind: global class
* BotConfigStorage
* [new BotConfigStorage([tableName], [dynamoDbService])](#new_BotConfigStorage_new)
* [.api([onUpdate], [acl])](#BotConfigStorage+api) ⇒ Object
* .invalidateConfig() ⇒ Promise
* .getConfigTimestamp() ⇒ Promise.<number>
* .updateConfig(newConfig) ⇒ Promise.<T>
* .getConfig() ⇒ Promise.<(Object\|null)>
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [tableName] | string | "wingbot-config" | the table name |
| [dynamoDbService] | AWS.DynamoDB | | preconfigured dynamodb service |
Kind: instance method of BotConfigStorage
| Param | Type | Description |
| --- | --- | --- |
| [onUpdate] | function | async update handler function |
| [acl] | function \| Array.<string> | acl configuration |
Kind: instance method of BotConfigStorage
BotConfigStorageBotConfigStorage| Param | Type |
| --- | --- |
| newConfig | T |
BotConfigStorageKind: global class
* AttachmentCache
* [new AttachmentCache([tableName], [dynamoDbService])](#new_AttachmentCache_new)
* .findAttachmentByUrl(url) ⇒ Promise.<(number\|null)>
* .saveAttachmentId(url, attachmentId) ⇒ Promise
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [tableName] | string | "wingbot-attachment-cache" | the table name |
| [dynamoDbService] | AWS.DynamoDB | | preconfigured dynamodb service |
AttachmentCache| Param | Type |
| --- | --- |
| url | string |
AttachmentCache| Param | Type |
| --- | --- |
| url | string |
| attachmentId | number |
Object| Name | Type |
| --- | --- |
| senderId | string |
| pageId | string |
| state | Object |
Object| Name | Type |
| --- | --- |
| senderId | string |
| pageId | string |
| token | string |