botnaut
Version:
Facebook Messenger Chatbot Framework
52 lines (41 loc) • 1.07 kB
JavaScript
/*
* @author Václav Oborník
*/
;
const AWS = require('aws-sdk');
/**
* Conversation DynamoDB state storage
*/
class DynamoAttachmentCache {
/**
* @param {AWS.DynamoDB} dynamoDb
* @param {string} tableName
*/
constructor (dynamoDb, tableName) {
this._documentClient = new AWS.DynamoDB.DocumentClient({
service: dynamoDb,
convertEmptyValues: true
});
this._tableName = tableName;
}
findAttachmentByUrl (url) {
return this._documentClient.get({
TableName: this._tableName,
Key: { url }
})
.promise()
.then((data) => {
if (!data.Item) {
return null;
}
return data.Item.attachmentId;
});
}
saveAttachmentId (url, attachmentId) {
return this._documentClient.put({
TableName: this._tableName,
Item: { url, attachmentId }
}).promise();
}
}
module.exports = DynamoAttachmentCache;