@cse-public/webex-node-bot-framework
Version:
Webex Teams Bot Framework for Node JS
84 lines (69 loc) • 1.91 kB
Markdown
# Flint Quick Start on Cloud 9
The following is a quick demo of building a bot using the new FLint version 4 framework. The example code used in the video is included below.
#### Video
[](https://www.youtube.com/watch?v=nx3kvs-gB_I)
#### package.json
```json
{
"name": "workspace",
"version": "1.0.0",
"description": "",
"main": "mybot.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.15.2",
"express": "^4.14.0",
"node-flint": "^4.0.1"
}
}
```
#### mybot.js
```js
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: 'https://<host>/flint',
token: '<token>',
port: 8080,
removeWebhooksOnStart: false,
maxConcurrent: 5,
minTime: 50
};
// init flint
var flint = new Flint(config);
flint.start();
// say hello
flint.hears('/hello', function(bot, trigger) {
bot.say('Hello %s!', trigger.personDisplayName);
});
// add flint event listeners
flint.on('message', function(bot, trigger, id) {
flint.debug('"%s" said "%s" in room "%s"', trigger.personEmail, trigger.text, trigger.roomTitle);
});
flint.on('initialized', function() {
flint.debug('initialized %s rooms', flint.bots.length);
});
// 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();
});
});
```