Returns a promise-based storage interface for botkit.
var controller = require('botkit').slackbot();
var promiseStorage = require('botkit-promise-storage')(controller);
promiseStorage.teams.get('teamId')
.then(function(team) {
console.log(team);
})
.fail(function(err) {
console.log(err);
});
This doesn't overwrite the storage interface for botkit but instead provides a new one interface you can use. Botkit relies on its own callback-based storage interface internally, so do not overwrite the existing storage module.
The returned storage object has the same interface as controller.storage
with the addition of a merge
method.
Each method returns a promise. The following methods are exported for each scope (teams
, channels
, users
):
Retrieves all data for this scope.
Takes an ID and will return either the data stored with that ID or undefined
.
A convenience method not found in the botkit storage modules. Takes an object with an id
property and will merge it with
any existing data with that ID. If there is no existing data with the given ID, this will function as a save
.
Generally, merge
should be preferred over save
.
Takes an object with an id
property and saves it. This will overwrite whatever data is previously stored with this ID.
This uses the promises A+ compliant q library for promises.