4.2.x Update
- Persistent Storage for
bot.store(),bot.recall(), andbot.forget()through new modular storage functionality. - Added in-memory storage module (default unless storage module is specified)
- Added Redis storage module
- Added boolean property flint.isUserAccount
- Added method
flint.storageDriver()to define storage backend - The
flint.hears()method now can have a weight specified. This allows for overlapping and default actions. - Auto detection of Bot accounts
- If Bot account is detected, the behavior of the
trigger.argsproperty inside theflint.hears()method performs additional parsing.
Potential Breaking Changes in 4.2.x
flint.machineboolean property renamed toflint.isBotAccount
4.3.x Update
bot.add()andbot.remove()now return an array of successfully added / removed room membership emails rather than the bot object itself.- Debug error messages for archived team rooms suppressed.
mkdir myproj
cd myproj
git clone https://github.com/nmarus/flint
npm install ./flintmkdir myproj
cd myproj
npm install node-flintvar Flint = require('node-flint');
var webhook = require('node-flint/webhook');
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
// flint options
var config = {
webhookUrl: 'http://myserver.com/flint',
token: 'Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u',
port: 80
};
// init flint
var flint = new Flint(config);
flint.start();
// say hello
flint.hears('/hello', function(bot, trigger) {
bot.say('Hello %s!', trigger.personDisplayName);
});
// define express path for incoming webhooks
app.post('/flint', webhook(flint));
// start express server
var server = app.listen(config.port, function () {
flint.debug('Flint listening on port %s', config.port);
});
// gracefully shutdown (ctrl-c)
process.on('SIGINT', function() {
flint.debug('stoppping...');
server.close();
flint.stop().then(function() {
process.exit();
});
});Most of Flint's functionality is based around the flint.hears function. This defines the phrase or pattern the bot is listening for and what actions to take when that phrase or pattern is matched. The flint.hears function gets a callback than includes two objects. The bot object, and the trigger object.
Flint generates a bot object instance of the Bot class for each room the Spark account Flint is running under. The bot object instance tracks the specifics about the room it is running in and is passed to the "hears" command callback when a phrase is heard.
Flint also generates a trigger object based on the person and room that the flint.hears function was triggered.
A simple example of a flint.hears() function setup:
flint.hears(phrase, function(bot, trigger) {
bot.<command>
.then(function(returnedValue) {
// do something with returned value
})
.catch(function(err) {
// handle errors
});
});phrase: This can be either a string or a regex pattern. If a string, the string is matched against the first word in the room message. message. If a regex pattern is used, it is matched against the entire message text.bot: The bot object that is used to execute commands when thephraseis triggered.bot.<command>: The Bot method to execute.then: Node JS Promise keyword that invokes additional logic once the previous command is executed.catch: handle errors that happen at either the original command or in any of the chained 'then' functions.trigger: The object that describes the details around what triggered thephrase.commands: The commands that are ran when thephraseis heard.
The token used to authenticate Flint to the Spark API is passed as part of the options used when instantiating the Flint class. To change or update the token, use the Flint#setSparkToken() method.
Example:
var newToken = 'Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u';
flint.setSparkToken(newToken)
.then(function(token) {
console.log('token updated to: ' + token);
});The storage system used in flint is a simple key/value store and resolves around these 3 methods:
bot.store(key, value)- Store a value to a bot instance where 'key' is a string and 'value' is a boolean, number, string, array, or object. This does not not support functions or any non serializable data. Returns the value.bot.recall(key)- Recall a value by 'key' from a bot instance. Returns the value or undefined if not found.bot.forget([key])- Forget (remove) value(s) from a bot instance where 'key' is an optional property that when defined, removes the specific key, and when undefined, removes all keys.
When a bot despawns (removed from room), the key/value store for that bot
instance will automatically be removed from the store. Flint currently has an
in-memory store and a Redis based store. By default, the in-memory store is
used. Other backend stores are possible by replicating any one of the built-in
storage modules and passing it to the flint.storeageDriver() method.
The following app is titled "Hotel California" and demonstrates how to use the
Redis driver along with bot.store() and bot.recall().
Hotel California:
var Flint = require('node-flint');
var webhook = require('node-flint/webhook');
var RedisStore = require('node-flint/storage/redis'); // load driver
var express = require('express');
var bodyParser = require('body-parser');
var _ = require('lodash');
var app = express();
app.use(bodyParser.json());
// flint options
var config = {
webhookUrl: 'http://myserver.com/flint',
token: 'Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u',
port: 80
};
// init flint
var flint = new Flint(config);
// use redis storage
flint.storageDriver(new RedisStore('redis://127.0.0.1')); // select driver
//start flint
flint.start();
// The Flint event is expecting a function that has a bot, person, and id parameter.
function checkin(eventBot, person, id) {
// retrieve value of key 'htc'. When this is ran initially, this will return 'undefined'.
var htc = eventBot.recall('htc');
// if room bot has htc.enabled...
if(eventBot && eventBot.active && htc.enabled) {
// wait 5 seconds, add person back, and let them know they can never leave!
setTimeout(() => {
var email = person.emails[0];
var name = person.displayName.split(' ')[0]; // reference first name
// add person back to room...
eventBot.add(email);
// let person know where they ended up...
eventBot.say('<@personEmail:%s|%s>, you can **check out any time you like**, but you can **never** leave!', email, name);
}, 5000); // 5000 ms = 5 seconds
}
}
// set default messages to use markdown globally for this flint instance...
flint.messageFormat = 'markdown';
// check if htc is already active in room...
flint.on('spawn', bot => {
// retrieve value of key 'htc'. When this is ran initially, this will return 'undefined'.
var htc = bot.recall('htc');
// if enabled...
if(htc && htc.enabled) {
// resume event
bot.on('personExits', checkin);
}
});
// open the hotel
flint.hears('open', function(bot, trigger) {
// retrieve value of key 'htc'. When this is ran initially, this will return 'undefined'.
var htc = bot.recall('htc');
// if htc has not been initialized to bot memory...
if(!htc) {
// init key
htc = bot.store('htc', {});
// store default value
htc.enabled = false;
}
// if not enabled...
if(!htc.enabled) {
htc.enabled = true;
// create event
bot.on('personExits', checkin);
// announce Hotel California is open
bot.say('**Hotel California** mode activated!');
} else {
// announce Hotel California is already open
bot.say('**Hotel California** mode is already activated!');
}
});
// close the hotel
flint.hears('close', function(bot, trigger) {
// retrieve value of key 'htc'. When this is ran initially, this will return 'undefined'.
var htc = bot.recall('htc');
if(htc && htc.enabled) {
htc.enabled = false;
// remove event (removeListener is an inherited function from EventEmitter)
bot.removeListener('personExits', checkin);
// announce Hotel California is closed
bot.say('**Hotel California** mode deactivated!');
} else {
// announce Hotel California is already closed
bot.say('**Hotel California** mode is already deactivated!');
}
});
// default message for unrecognized commands
flint.hears(/.*/, function(bot, trigger) {
bot.say('You see a shimmering light, but it is growing dim...');
}, 20);
// define express path for incoming webhooks
app.post('/flint', webhook(flint));
// start express server
var server = app.listen(config.port, function () {
flint.debug('Flint listening on port %s', config.port);
});
// gracefully shutdown (ctrl-c)
process.on('SIGINT', function() {
flint.debug('stoppping...');
server.close();
flint.stop().then(function() {
process.exit();
});
});When using "Bot Accounts" the major differences are:
- Webhooks for message:created only trigger when the Bot is mentioned by name
- Unable to read messages in rooms using the Spark API
Differences with trigger.args using Flint with a "Bot Account":
The trigger.args array is a shortcut in processing the trigger.text string. It consists of an array of the words that are in the trigger.message string split by one or more spaces. Punctation is included if there is no space between the symbol and the word. With bot accounts, this behaves a bit differently.
-
If defining a
flint.hears()using a string (not regex),trigger.argsis a filtered array of words from the message that begin with the first match of the string.-
For example if the message.text is
'Yo yo yo Bot, find me tacos!'(where Bot is the mentioned name of the Bot Account) and the hears string is defined as'find', then:- args[0] :
'find' - args[1] :
'me' - etc..
- args[0] :
-
If the message text is "Hey, Find me tacos, Bot!", then:
- args[0] :
'Find' - args[1] :
'me' - args[2] :
'tacos,' - args[3] :
'Bot!'
- args[0] :
-
-
If defining a flint.hears() using regex, the trigger.args array is the entire message.
- "log"
Flint log event.
- "stop"
Flint stop event.
- "start"
Flint start event.
- "initialized"
Flint initialized event.
- "roomLocked"
Room Locked event.
- "roomUnocked"
Room Unocked event.
- "personEnters"
Person Enter Room event.
- "botAddedAsModerator"
Bot Added as Room Moderator.
- "botRemovedAsModerator"
Bot Removed as Room Moderator.
- "personAddedAsModerator"
Person Added as Moderator.
- "personRemovedAsModerator"
Person Removed as Moderator.
- "personExits"
Person Exits Room.
- "mentioned"
Bot Mentioned.
- "message"
Message Recieved.
- "files"
File Recieved.
- "spawn"
Bot Spawned.
- "despawn"
Bot Despawned.
Kind: global class
Properties
| Name | Type | Description |
|---|---|---|
| id | string |
Flint UUID |
| active | boolean |
Flint active state |
| intialized | boolean |
Flint fully initialized |
| isBotAccount | boolean |
Is Flint attached to Spark using a bot account? |
| isUserAccount | boolean |
Is Flint attached to Spark using a user account? |
| person | object |
Flint person object |
string |
Flint email | |
| spark | object |
The Spark instance used by flint |
- Flint
- new Flint(options)
- .options :
object - .setSparkToken(token) ⇒
Promise.<String> - .stop() ⇒
Promise.<Boolean> - .start() ⇒
Promise.<Boolean> - .restart() ⇒
Promise.<Boolean> - .getMessage(messageId) ⇒
Promise.<Message> - .getFiles(messageId) ⇒
Promise.<Array> - .hears(phrase, action, [helpText], [preference]) ⇒
String - .clearHears(id) ⇒
null - .showHelp([header], [footer]) ⇒
String - .setAuthorizer(Action) ⇒
Boolean - .clearAuthorizer() ⇒
null - .storageDriver(Driver) ⇒
null - .use(path) ⇒
Boolean
Creates an instance of Flint.
| Param | Type | Description |
|---|---|---|
| options | Object |
Configuration object containing Flint settings. |
Example
var options = {
webhookUrl: 'http://myserver.com/flint',
token: 'Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u'
};
var flint = new Flint(options);Options Object
Kind: instance namespace of Flint
Properties
| Name | Type | Default | Description |
|---|---|---|---|
| token | string |
Spark Token. | |
| webhookUrl | string |
URL that is used for SPark API to send callbacks. | |
| webhookSecret | string |
If specified, inbound webhooks are authorized before being processed. | |
| messageFormat | string |
"text" |
Default Spark message format to use with bot.say(). |
| maxPageItems | number |
50 |
Max results that the paginator uses. |
| maxConcurrent | number |
3 |
Max concurrent sessions to the Spark API |
| minTime | number |
600 |
Min time between consecutive request starts. |
| requeueMinTime | number |
minTime*10 |
Min time between consecutive request starts of requests that have been re-queued. |
| requeueMaxRetry | number |
3 |
Msx number of atteempts to make for failed request. |
| requeueCodes | array |
[429,500,503] |
Array of http result codes that should be retried. |
| requestTimeout | number |
20000 |
Timeout for an individual request recieving a response. |
| queueSize | number |
10000 |
Size of the buffer that holds outbound requests. |
| requeueSize | number |
10000 |
Size of the buffer that holds outbound re-queue requests. |
| id | string |
"random" |
The id this instance of flint uses. |
| webhookRequestJSONLocation | string |
"body" |
The property under the Request to find the JSON contents. |
| removeWebhooksOnStart | Boolean |
true |
If you wish to have the bot remove all account webhooks when starting. |
Tests, and then sets a new Spark Token.
Kind: instance method of Flint
| Param | Type | Description |
|---|---|---|
| token | String |
New Spark Token for Flint to use. |
Example
flint.setSparkToken('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
.then(function(token) {
console.log('token updated to: ' + token);
});Stop Flint.
Kind: instance method of Flint
Example
flint.stop();Start Flint.
Kind: instance method of Flint
Example
flint.start();Restart Flint.
Kind: instance method of Flint
Example
flint.restart();flint.getMessage(messageId) ⇒ Promise.<Message>
Get Message Object by ID
Kind: instance method of Flint
| Param | Type | Description |
|---|---|---|
| messageId | String |
Message ID from Spark API. |
Get Files from Message Object by ID
Kind: instance method of Flint
| Param | Type | Description |
|---|---|---|
| messageId | String |
Message ID from Spark API. |
Add action to be performed when bot hears a phrase.
Kind: instance method of Flint
| Param | Type | Default | Description |
|---|---|---|---|
| phrase | Regex | String |
The phrase as either a regex or string. If regex, matches on entire message.If string, matches on first word. | |
| action | function |
The function to execute when phrase is matched. Function is executed with 2 variables. Trigger and Bot. The Trigger Object contains information about the person who entered a message that matched the phrase. The Bot Object is an instance of the Bot Class as it relates to the room the message was heard. | |
| [helpText] | String |
The string of text that describes how this command operates. | |
| [preference] | Number |
0 |
Specifies preference of phrase action when overlapping phrases are matched. On multiple matches with same preference, all matched actions are excuted. On multiple matches with difference preference values, only the lower preferenced matched action(s) are executed. |
Example
// using a string to match first word and defines help text
flint.hears('/say', function(bot, trigger, id) {
bot.say(trigger.args.slice(1, trigger.arges.length - 1));
}, '/say <greeting> - Responds with a greeting');Example
// using regex to match across entire message
flint.hears(/(^| )beer( |.|$)/i, function(bot, trigger, id) {
bot.say('Enjoy a beer, %s! 🍻', trigger.personDisplayName);
});Remove a "flint.hears()" entry.
Kind: instance method of Flint
| Param | Type | Description |
|---|---|---|
| id | String |
The "hears" ID. |
Example
// using a string to match first word and defines help text
var hearsHello = flint.hears('/flint', function(bot, trigger, id) {
bot.say('Hello %s!', trigger.personDisplayName);
});
flint.clearHears(hearsHello);Display help for registered Flint Commands.
Kind: instance method of Flint
| Param | Type | Default | Description |
|---|---|---|---|
| [header] | String |
Usage: |
String to use in header before displaying help message. |
| [footer] | String |
Powered by Flint - https://github.com/nmarus/flint |
String to use in footer before displaying help message. |
Example
flint.hears('/help', function(bot, trigger, id) {
bot.say(flint.showHelp());
});Attaches authorizer function.
Kind: instance method of Flint
| Param | Type | Description |
|---|---|---|
| Action | function |
The function to execute when phrase is matched to authenticate a user. The function is passed the bot, trigger, and id and expects a return value of true or false. |
Example
function myAuthorizer(bot, trigger, id) {
if(trigger.personEmail === 'john@test.com') {
return true;
}
else if(trigger.personDomain === 'test.com') {
return true;
}
else {
return false;
}
}
flint.setAuthorizer(myAuthorizer);Removes authorizer function.
Kind: instance method of Flint
Example
flint.clearAuthorizer();Defines storage backend.
Kind: instance method of Flint
| Param | Type | Description |
|---|---|---|
| Driver | function |
The storage driver. |
Example
// define redis store
flint.storageDriver(new RedisStore('redis://user:password@redishost:6379'));Example
// define memory store
flint.storageDriver(new MemStore());Load a Plugin from a external file.
Kind: instance method of Flint
| Param | Type | Description |
|---|---|---|
| path | String |
Load a plugin at given path. |
Example
flint.use('events.js');Example
// events.js
module.exports = function(flint) {
flint.on('spawn', function(bot) {
console.log('new bot spawned in room: %s', bot.myroom.title);
});
flint.on('despawn', function(bot) {
console.log('bot despawned in room: %s', bot.myroom.title);
});
flint.on('messageCreated', function(message, bot) {
console.log('"%s" said "%s" in room "%s"', message.personEmail, message.text, bot.myroom.title);
});
};Kind: global class
Properties
| Name | Type | Description |
|---|---|---|
| id | string |
Bot UUID |
| active | boolean |
Bot active state |
| person | object |
Bot Person Object |
string |
Bot email | |
| team | object |
Bot team object |
| room | object |
Bot room object |
| membership | object |
Bot membership object |
| isLocked | boolean |
If bot is locked |
| isModerator | boolean |
If bot is a moderator |
| isGroup | boolean |
If bot is in Group Room |
| isDirect | boolean |
If bot is in 1:1/Direct Room |
| isTeam | boolean |
If bot is in Team Room |
| lastActivity | date |
Last bot activity |
- Bot
- new Bot(flint)
- .exit() ⇒
Promise.<Boolean> - .add(email(s), [moderator]) ⇒
Promise.<Array> - .remove(email(s)) ⇒
Promise.<Array> - .getModerators() ⇒
Promise.<Array> - .newRoom(name, emails) ⇒
Promise.<Bot> - .newTeamRoom(name, emails) ⇒
Promise.<Bot> - .moderateRoom() ⇒
Promise.<Bot> - .unmoderateRoom() ⇒
Promise.<Bot> - .moderatorSet(email(s)) ⇒
Promise.<Bot> - .moderatorClear(email(s)) ⇒
Promise.<Bot> - .implode() ⇒
Promise.<Boolean> - .say([format], message) ⇒
Promise.<Message> - .dm(email, [format], message) ⇒
Promise.<Message> - .uploadStream(filename, stream) ⇒
Promise.<Message> - .upload(filepath) ⇒
Promise.<Message> - .censor(messageId) ⇒
Promise.<Message> - .roomRename(title) ⇒
Promise.<Room> - .getMessages(count) ⇒
Promise.<Array> - .store(id, key, value) ⇒
String|Number|Boolean|Array|Object - .recall(id, key) ⇒
String|Number|Boolean|Array|Object|undefined - .forget(id, [key]) ⇒
Boolean
Creates a Bot instance that is then attached to a Spark Room.
| Param | Type | Description |
|---|---|---|
| flint | Object |
The flint object this Bot spawns under. |
Instructs Bot to exit from room.
Kind: instance method of Bot
Example
bot.exit();Instructs Bot to add person(s) to room.
Kind: instance method of Bot
Returns: Promise.<Array> - Array of emails added
| Param | Type | Description |
|---|---|---|
| email(s) | String | Array |
Email Address (or Array of Email Addresses) of Person(s) to add to room. |
| [moderator] | Boolean |
Add as moderator. |
Example
// add one person to room by email
bot.add('john@test.com');Example
// add one person as moderator to room by email
bot.add('john@test.com', true)
.catch(function(err) {
// log error if unsuccessful
console.log(err.message);
});Example
// add 3 people to room by email
bot.add(['john@test.com', 'jane@test.com', 'bill@test.com']);Instructs Bot to remove person from room.
Kind: instance method of Bot
Returns: Promise.<Array> - Array of emails removed
| Param | Type | Description |
|---|---|---|
| email(s) | String | Array |
Email Address (or Array of Email Addresses) of Person(s) to remove from room. |
Example
// remove one person to room by email
bot.remove('john@test.com');Example
// remove 3 people from room by email
bot.remove(['john@test.com', 'jane@test.com', 'bill@test.com']);Get room moderators.
Kind: instance method of Bot
Example
bot.getModerators()
.then(function(moderators) {
console.log(moderators);
});bot.newRoom(name, emails) ⇒ Promise.<Bot>
Create new room with people by email
Kind: instance method of Bot
| Param | Type | Description |
|---|---|---|
| name | String |
Name of room. |
| emails | Array |
Emails of people to add to room. |
bot.newTeamRoom(name, emails) ⇒ Promise.<Bot>
Create new Team Room
Kind: instance method of Bot
| Param | Type | Description |
|---|---|---|
| name | String |
Name of room. |
| emails | Array |
Emails of people to add to room. |
bot.moderateRoom() ⇒ Promise.<Bot>
Enable Room Moderation.Enable.
Kind: instance method of Bot
Example
bot.moderateRoom()
.then(function(err) {
console.log(err.message)
});bot.unmoderateRoom() ⇒ Promise.<Bot>
Disable Room Moderation.
Kind: instance method of Bot
Example
bot.unmoderateRoom()
.then(function(err) {
console.log(err.message)
});bot.moderatorSet(email(s)) ⇒ Promise.<Bot>
Assign Moderator in Room
Kind: instance method of Bot
| Param | Type | Description |
|---|---|---|
| email(s) | String | Array |
Email Address (or Array of Email Addresses) of Person(s) to assign as moderator. |
Example
bot.moderatorSet('john@test.com')
.then(function(err) {
console.log(err.message)
});bot.moderatorClear(email(s)) ⇒ Promise.<Bot>
Unassign Moderator in Room
Kind: instance method of Bot
| Param | Type | Description |
|---|---|---|
| email(s) | String | Array |
Email Address (or Array of Email Addresses) of Person(s) to unassign as moderator. |
Example
bot.moderatorClear('john@test.com')
.then(function(err) {
console.log(err.message)
});Remove a room and all memberships.
Kind: instance method of Bot
Example
flint.hears('/implode', function(bot, trigger) {
bot.implode();
});bot.say([format], message) ⇒ Promise.<Message>
Send text with optional file to room.
Kind: instance method of Bot
| Param | Type | Default | Description |
|---|---|---|---|
| [format] | String |
text |
Set message format. Valid options are 'text' or 'markdown'. |
| message | String | Object |
Message to send to room. This can be a simple string, or a object for advanced use. |
Example
// Simple example
flint.hears('/hello', function(bot, trigger) {
bot.say('hello');
});Example
// Simple example to send message and file
flint.hears('/file', function(bot, trigger) {
bot.say({text: 'Here is your file!', file: 'http://myurl/file.doc'});
});Example
// Markdown Method 1 - Define markdown as default
flint.messageFormat = 'markdown';
flint.hears('/hello', function(bot, trigger) {
bot.say('**hello**, How are you today?');
});Example
// Markdown Method 2 - Define message format as part of argument string
flint.hears('/hello', function(bot, trigger) {
bot.say('markdown', '**hello**, How are you today?');
});Example
// Mardown Method 3 - Use an object (use this method of bot.say() when needing to send a file in the same message as markdown text.
flint.hears('/hello', function(bot, trigger) {
bot.say({markdown: '*Hello <@personEmail:' + trigger.personEmail + '|' + trigger.personDisplayName + '>*'});
});bot.dm(email, [format], message) ⇒ Promise.<Message>
Send text with optional file in a direct message. This sends a message to a 1:1 room with the user (creates 1:1, if one does not already exist)
Kind: instance method of Bot
| Param | Type | Default | Description |
|---|---|---|---|
String |
Email of person to send Direct Message. | ||
| [format] | String |
text |
Set message format. Valid options are 'text' or 'markdown'. |
| message | String | Object |
Message to send to room. This can be a simple string, or a object for advanced use. |
Example
// Simple example
flint.hears('/dm', function(bot, trigger) {
bot.dm('someone@domain.com', 'hello');
});Example
// Simple example to send message and file
flint.hears('/dm', function(bot, trigger) {
bot.dm('someone@domain.com', {text: 'Here is your file!', file: 'http://myurl/file.doc'});
});Example
// Markdown Method 1 - Define markdown as default
flint.messageFormat = 'markdown';
flint.hears('/dm', function(bot, trigger) {
bot.dm('someone@domain.com', '**hello**, How are you today?');
});Example
// Markdown Method 2 - Define message format as part of argument string
flint.hears('/dm', function(bot, trigger) {
bot.dm('markdown', 'someone@domain.com', '**hello**, How are you today?');
});Example
// Mardown Method 3 - Use an object (use this method of bot.dm() when needing to send a file in the same message as markdown text.
flint.hears('/dm', function(bot, trigger) {
bot.dm('someone@domain.com', {markdown: '*Hello <@personEmail:' + trigger.personEmail + '|' + trigger.personDisplayName + '>*'});
});bot.uploadStream(filename, stream) ⇒ Promise.<Message>
Upload a file to a room using a Readable Stream
Kind: instance method of Bot
| Param | Type | Description |
|---|---|---|
| filename | String |
File name used when uploading to room |
| stream | Stream.Readable |
Stream Readable |
Example
flint.hears('/file', function(bot, trigger) {
// define filename used when uploading to room
var filename = 'test.png';
// create readable stream
var stream = fs.createReadStream('/my/file/test.png');
bot.uploadStream(filename, stream);
});bot.upload(filepath) ⇒ Promise.<Message>
Upload a file to room.
Kind: instance method of Bot
| Param | Type | Description |
|---|---|---|
| filepath | String |
File Path to upload |
Example
flint.hears('/file', function(bot, trigger) {
bot.upload('test.png');
});bot.censor(messageId) ⇒ Promise.<Message>
Remove Message By Id.
Kind: instance method of Bot
| Param | Type |
|---|---|
| messageId | String |
Set Title of Room.
Kind: instance method of Bot
| Param | Type |
|---|---|
| title | String |
Example
bot.roomRename('My Renamed Room')
.then(function(err) {
console.log(err.message)
});Get messages from room. Returned data has newest message at bottom.
Kind: instance method of Bot
| Param | Type |
|---|---|
| count | Integer |
Example
bot.getMessages(5).then(function(messages) {
messages.forEach(function(message) {
// display message text
if(message.text) {
console.log(message.text);
}
});
});Store key/value data.
Kind: instance method of Bot
| Param | Type |
|---|---|
| id | String |
| key | String |
| value | String | Number | Boolean | Array | Object |
Recall value of data stored by 'key'.
Kind: instance method of Bot
| Param | Type |
|---|---|
| id | String |
| key | String |
Forget a key or entire store.
Kind: instance method of Bot
| Param | Type | Description |
|---|---|---|
| id | String |
|
| [key] | String |
Optional key value to forget. If key is not passed, id is removed. |
Message Object
Kind: global namespace
Properties
| Name | Type | Description |
|---|---|---|
| id | string |
Message ID |
| personId | string |
Person ID |
| personEmail | string |
Person Email |
| personAvatar | string |
PersonAvatar URL |
| personDomain | string |
Person Domain Name |
| personDisplayName | string |
Person Display Name |
| roomId | string |
Room ID |
| text | string |
Message text |
| files | array |
Array of File objects |
| created | date |
Date Message created |
File Object
Kind: global namespace
Properties
| Name | Type | Description |
|---|---|---|
| id | string |
Spark API Content ID |
| name | string |
File name |
| ext | string |
File extension |
| type | string |
Header [content-type] for file |
| binary | buffer |
File contents as binary |
| base64 | string |
File contents as base64 encoded string |
| personId | string |
Person ID of who added file |
| personEmail | string |
Person Email of who added file |
| personAvatar | string |
PersonAvatar URL |
| personDomain | string |
Person Domain Name |
| personDisplayName | string |
Person Display Name |
| created | date |
Date file was added to room |
Trigger Object
Kind: global namespace
Properties
| Name | Type | Description |
|---|---|---|
| id | string |
Message ID |
| phrase | string | regex |
Matched lexicon phrase |
| text | string |
Message Text (or false if no text) |
| html | string |
Message HTML (or false if no html) |
| markdown | string |
Message Markdown (or false if no markdown) |
| mentionedPeople | array |
Mentioned People (or false if no mentioned) |
| files | array |
Message Files (or false if no files in trigger) |
| args | array |
Filtered array of words in message text. |
| created | date |
Message Created date |
| roomId | string |
Room ID |
| roomTitle | string |
Room Title |
| roomType | string |
Room Type (group or direct) |
| roomIsLocked | boolean |
Room Locked/Moderated status |
| personId | string |
Person ID |
| personEmail | string |
Person Email |
| personDisplayName | string |
Person Display Name |
| personUsername | string |
Person Username |
| personDomain | string |
Person Domain name |
| personAvatar | string |
Person Avatar URL |
| personMembership | object |
Person Membership object for person |
Flint log event.
Kind: event emitted
Properties
| Name | Type | Description |
|---|---|---|
| message | string |
Log Message |
Flint stop event.
Kind: event emitted
Properties
| Name | Type | Description |
|---|---|---|
| id | string |
Flint UUID |
Flint start event.
Kind: event emitted
Properties
| Name | Type | Description |
|---|---|---|
| id | string |
Flint UUID |
Flint initialized event.
Kind: event emitted
Properties
| Name | Type | Description |
|---|---|---|
| id | string |
Flint UUID |
Room Locked event.
Kind: event emitted
Properties
| Name | Type | Description |
|---|---|---|
| bot | object |
Bot Object |
| id | string |
Flint UUID |
Room Unocked event.
Kind: event emitted
Properties
| Name | Type | Description |
|---|---|---|
| bot | object |
Bot Object |
| id | string |
Flint UUID |
Person Enter Room event.
Kind: event emitted
Properties
| Name | Type | Description |
|---|---|---|
| bot | object |
Bot Object |
| person | object |
Person Object |
| id | string |
Flint UUID |
Bot Added as Room Moderator.
Kind: event emitted
Properties
| Name | Type | Description |
|---|---|---|
| bot | object |
Bot Object |
| id | string |
Flint UUID |
Bot Removed as Room Moderator.
Kind: event emitted
Properties
| Name | Type | Description |
|---|---|---|
| bot | object |
Bot Object |
| id | string |
Flint UUID |
Person Added as Moderator.
Kind: event emitted
Properties
| Name | Type | Description |
|---|---|---|
| bot | object |
Bot Object |
| person | object |
Person Object |
| id | string |
Flint UUID |
Person Removed as Moderator.
Kind: event emitted
Properties
| Name | Type | Description |
|---|---|---|
| bot | object |
Bot Object |
| person | object |
Person Object |
| id | string |
Flint UUID |
Person Exits Room.
Kind: event emitted
Properties
| Name | Type | Description |
|---|---|---|
| bot | object |
Bot Object |
| person | object |
Person Object |
| id | string |
Flint UUID |
Bot Mentioned.
Kind: event emitted
Properties
| Name | Type | Description |
|---|---|---|
| bot | object |
Bot Object |
| trigger | object |
Trigger Object |
| id | string |
Flint UUID |
Message Recieved.
Kind: event emitted
Properties
| Name | Type | Description |
|---|---|---|
| bot | object |
Bot Object |
| trigger | object |
Trigger Object |
| id | string |
Flint UUID |
File Recieved.
Kind: event emitted
Properties
| Name | Type | Description |
|---|---|---|
| bot | object |
Bot Object |
| trigger | trigger |
Trigger Object |
| id | string |
Flint UUID |
Bot Spawned.
Kind: event emitted
Properties
| Name | Type | Description |
|---|---|---|
| bot | object |
Bot Object |
| id | string |
Flint UUID |
Bot Despawned.
Kind: event emitted
Properties
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.

