All tables uses ${self:custom.prefix} to be able to use configuration on different bots and environments.
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: 1ChatlogTable:
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: 1BottokensTable:
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: 1AttachmentsTable:
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- 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
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>
| Param | Type | Default | Description |
|---|---|---|---|
| [tableName] | string |
"states" |
|
| [dynamoDbService] | AWS.DynamoDB |
preconfigured dynamodb service |
Kind: instance method of StateStorage
| Param | Type |
|---|---|
| senderId | string |
| pageId | string |
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 |
Kind: instance method of StateStorage
| Param | Type | Description |
|---|---|---|
| state | Object |
conversation state |
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)>
| 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 |
Kind: instance method of BotTokenStorage
| Param | Type |
|---|---|
| token | string |
Kind: instance method of BotTokenStorage
| Param | Type |
|---|---|
| senderId | string |
| pageId | string |
| customTokenFactory | Object |
Kind: instance method of BotTokenStorage
| Param | Type |
|---|---|
| senderId | string |
| pageId | string |
DynamoDB Chat Log storage
Kind: global class
| Param | Type | Default | Description |
|---|---|---|---|
| [tableName] | string |
"chatlog" |
|
| [dynamoDbService] | AWS.DynamoDB |
|
preconfigured dynamodb service |
| [log] | Object |
console like logger |
Log single event
Kind: instance method of ChatLogStorage
| Param | Type | Description |
|---|---|---|
| userId | string |
|
| responses | Array.<Object> |
list of sent responses |
| request | Object |
event request |
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)>
| Param | Type | Default | Description |
|---|---|---|---|
| [tableName] | string |
"wingbot-config" |
the table name |
| [dynamoDbService] | AWS.DynamoDB |
|
preconfigured dynamodb service |
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 |
Invalidates current configuration
Kind: instance method of BotConfigStorage
Kind: instance method of BotConfigStorage
Kind: instance method of BotConfigStorage
Template: T
| Param | Type |
|---|---|
| newConfig | T |
Kind: instance method of BotConfigStorage
Storage for Facebook attachment ids
Kind: global class
- AttachmentCache
- new AttachmentCache([tableName], [dynamoDbService])
- .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 |
Kind: instance method of AttachmentCache
| Param | Type |
|---|---|
| url | string |
Kind: instance method of AttachmentCache
| Param | Type |
|---|---|
| url | string |
| attachmentId | number |
Kind: global typedef Properties
| Name | Type |
|---|---|
| senderId | string |
| pageId | string |
| state | Object |
Kind: global typedef Properties
| Name | Type |
|---|---|
| senderId | string |
| pageId | string |
| token | string |