SkillAgentSearch skills...

Flint

Webex Bot SDK for Node.js (deprecated in favor of https://github.com/webex/webex-bot-node-framework)

Install / Use

/learn @flint-bot/Flint
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

node-flint (v4)

Bot SDK for Node JS

News

03/01/2020 Please consider the Webex Node Bot Framework:

  • This framework is no longer being actively maintained by the original author. Developers who are familiar with flint may consider trying the webex-node-bot-framework. While not 100% directly compatible with flint, this framework is inspired by flint and should be extremely familiar to developers who already use flint. For more information see the migration from flint guide

10/25/19 Support for Adaptive Cards:

  • Cisco recently introduced support for Adaptive Cards in the Webex Teams. Bots can send cards, using the new attachment attribute of the message object. Cards are useful as an alternative to text messages and files in order to display or collect complex bits of information. Cards can be sent by passing an object to the bot.say() method that includes a valid attachment. To process user input to cards, apps must implement a flint.on('attachmentaction', ..) function. For more details see the adaptive-card-example

6/21/19 Deploying behind a firewall:

  • Cisco has recently introduced support in the Webex Javascript SDK which allows applications to register to receive the message, membership, and room events via a socket instead of via wehbhoks. This allows applications to be deployed behind firewalls and removes the requirement that webex bots and integrations must expose a public IP address to receive events. To take advantage of this in your flint applications simply remove the webhookUrl field from the configuration object passed to the flint constructor. If this field is not set, flint will register to listen for these events instead of creating webhooks.

6/21/18 IMPORTANT:

  • On August 31st, 2018 all bots with the sparkbot.io domain name will be renamed with a webex.bot domain. Today in flint, the code compares the bot's email with the trigger email to filter out messages from itself. If this code is running on August 31st the bot will start responding to its own messages. Please update to Flint v4.7.x as soon as possible to avoid interruption.

3/19/18 IMPORTANT:

  • Note that Flint v4 is still using the node-sparky library version 3.x. However the repo for node-sparky is now on version 4 which has some major differences. This misalignment between Flint and Sparky version will be fixed with the release of Flint v5. In the short term if you are accessing the spark object directly from Flint via flint.spark be sure to use the documentation for node-sparky 3.x.

See CHANGELOG.md for details on changes to versions of Flint.

Contents

<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> <!-- END doctoc generated TOC please keep comment here to allow auto update -->

Installation

Via Git

mkdir myproj
cd myproj
git clone https://github.com/nmarus/flint
npm install ./flint

Via NPM

mkdir myproj
cd myproj
npm install node-flint

Example Template Using Express

var 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
// This is not necessary if webhookUrl is not set in the config
app.post('/flint', webhook(flint));

// start express server
// This is not necessary if webhookUrl is not set in the config
// unless the bot uses express for other reasons
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();   // remove if not using webhooks and express
  flint.stop().then(function() {
    process.exit();
  });
});

Restify Example

Overview

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 the phrase is 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 the phrase.
  • commands : The commands that are ran when the phrase is heard.

Authentication

The token used to authenticate Flint to the Spark (now Webex) 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);
});

Storage

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 a promise with the value.
  • bot.recall(key) - Recall a value by 'key' from a bot instance. Returns a resolved promise with the value or a rejected promise 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. Returns a resolved promise if deleted or not found.

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. See docs for store, recall, forget for more details.

Example:

var redisDriver = require('node-flint/storage/redis');
flint.storageDriver(redisDriver('redis://localhost'));

Bot Accounts

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 (now Webex) 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.args is a filtered array of words from the message that begins after the first match of bot mention.

  • If defining a flint.hears() using regex, the trigger.args array is the entire message.

Flint Reference

Classes

<dl> <dt><a href="#Flint">Flint</a></dt> <dd></dd> <dt><a href="#Bot">Bot</a></dt> <dd></dd> </dl>

Objects

<dl> <dt><a href="#Message">Message</a> : <code>object</code></dt> <dd><p>Message Object</p> </dd> <dt><a href="#File">File</a> : <code>object</code></dt> <dd><p>File Object</p> </dd> <dt><a href="#Trigger">Trigger</a> : <code>object</code></dt> <dd><p>Trigger Object</p> </dd> </dl>

Events

<dl> <dt><a href="#event_log">"log"</a></dt> <dd><p>Flint log event.</p> </dd> <dt><a href="#event_stop">"stop"</a></dt> <dd><p>Flint stop event.</p> </dd> <dt><a href="#event_start">"start"</a></dt> <dd><p>Flint start event.</p> </dd> <dt><a href="#event_initialized">"initializ

Related Skills

View on GitHub
GitHub Stars86
CategoryDevelopment
Updated3mo ago
Forks24

Languages

JavaScript

Security Score

97/100

Audited on Dec 30, 2025

No findings