Skip to content

Commit

Permalink
Renamed flint to framework
Browse files Browse the repository at this point in the history
  • Loading branch information
jpjpjp committed Nov 16, 2019
1 parent 2ee92a4 commit a6f3121
Show file tree
Hide file tree
Showing 41 changed files with 1,380 additions and 1,139 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Expand Up @@ -16,4 +16,8 @@ node_modules

# Private environments
.env
ToDo.private
ToDo.private

# Test version of sample
example1.js

547 changes: 318 additions & 229 deletions README.md

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions docs/adaptive-card-example.md
@@ -1,31 +1,31 @@
#### Adaptive Card Template Using Express
```js
var Flint = require('node-flint');
var webhook = require('node-flint/webhook');
var Framework = require('webex-node-bot-framework');
var webhook = require('webex-node-bot-framework/webhook');
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());

// flint options
// framework options
var config = {
webhookUrl: 'http://myserver.com/flint',
webhookUrl: 'http://myserver.com/framework',
token: 'Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u',
port: 80
};

// init flint
var flint = new Flint(config);
flint.start();
// init framework
var framework = new Framework(config);
framework.start();

flint.on("initialized", async function () {
flint.debug("Flint initialized successfully! [Press CTRL-C to quit]");
framework.on("initialized", async function () {
framework.debug("Framework initialized successfully! [Press CTRL-C to quit]");
});



// send an example card in response to any input
flint.hears(/.*/, function(bot) {
framework.hears(/.*/, function(bot) {
bot.say({
// Fallback text for clients that don't render cards
markdown: "[Tell us about yourself](https://www.example.com/form/book-vacation). We just need a few more details to get you booked for the trip of a lifetime!",
Expand All @@ -34,23 +34,23 @@ flint.hears(/.*/, function(bot) {
});

// Process a submitted card
flint.on('attachmentAction', function (bot, attachmentAction) {
bot.say(`Got an attachmentAction:\n${JSON.stringify(attachmentAction, null, 2)}`);
framework.on('attachmentAction', function (bot, trigger) {
bot.say(`Got an attachmentAction:\n${JSON.stringify(trigger.attachmentAction, null, 2)}`);
});

// define express path for incoming webhooks
app.post('/', webhook(flint));
app.post('/', webhook(framework));

// start express server
var server = app.listen(config.port, function () {
flint.debug('Flint listening on port %s', config.port);
framework.debug('Framework listening on port %s', config.port);
});

// gracefully shutdown (ctrl-c)
process.on('SIGINT', function() {
flint.debug('stoppping...');
framework.debug('stoppping...');
server.close();
flint.stop().then(function() {
framework.stop().then(function() {
process.exit();
});
});
Expand Down
4 changes: 2 additions & 2 deletions docs/build.sh
Expand Up @@ -11,8 +11,8 @@ cat overview.md >> ${README}

${DOCTOC} --github --notitle --maxlevel 4 ${README}

echo -e "\n# Flint Reference\n\n" >> ${README}
echo -e "\n# Framework Reference\n\n" >> ${README}

${JSDOC} ../lib/flint.js ../lib/bot.js >> ${README}
${JSDOC} ../lib/framework.js ../lib/bot.js >> ${README}

cat license.md >> ${README}
56 changes: 56 additions & 0 deletions docs/contributing.md
@@ -0,0 +1,56 @@
## Contributing

#### Build

## Rebuilding Docs

The `build.sh` script in this folder generates the README.md for the project.
This build script requires that you have installed the dev dependencies of this project.

To build the docs:
```bash
npm i --only=dev
npm run build
```
(note: the dependencies only need to be installed once)

#### Test

Before submitting a pull request, please validate that all tests work and are augmented as necessary, to test your new functionality. It is reccomended that you familiarize yourself with the tests BEFORE beginning any feature related work.

The tests require the following environment variables which will be read in from a .env file if one is available.
| Variable| Value | Purpose |
| --------------- | -------------- | ------------------------------ |
|BOT_API_TOKEN | Token of a bot created on [Webex For Developers](https://developer.webex.com/my-apps/new/bot)| Identity of bot to test framework with. There is no need to have any actual bot code associated with this token, in fact its probably better if there isnt.|
|USER_API_TOKEN | Token of a user that the test bot will interact with. This can be grabbed from [Webex For Developers](https://developer.webex.com/docs/api/getting-started/accounts-and-authentication)| This user will create rooms with the bot, (and vice versa) and exchange messages with it. Rooms will be deleted at the end of the test.|
|HOSTED_FILE | URL for a file to upload in some of the message tests.| Any file suppported by Webex Teams will do, perhaps the one here: https://www.webex.com/content/dam/wbx/us/images/hp/hp_56565/Teams_Iconx2.png|
|DEBUG | framework| Optionally set DEBUG=framework for extended debug output during the test run.|

When the environment is set, run the tests:
```bash
npm i --only=dev
npm run test
```
(note: the dependencies only need to be installed once)

The test suite includes direct message tests. These will run ONLY if an existing one-one space exists between the test bot and test user. To run these tests, manually create this 1-1 space.

It is also possible to run the tests by instantiating the framework with an authorized user token (as an integration would do). At this time the framework is not optimized for use as an integration, however the tests are provided as a convenience. These tests are similar but the user does not at-mention the bot.

To run the user tests set the following environment variables:
| Variable| Value | Purpose |
| --------------- | -------------- | ------------------------------ |
|AUTHORIZED_FLINT_USER_API_TOKEN | Token of a user. This can be extracted from the developer portal or obtained by via an OAuth flow with an integration.| Identity of a non bot user to test framework with. There is no need to have any actual integration code associated with this token, in fact its probably better if there isnt.|
|USER_API_TOKEN | Token of a user that the test bot will interact with. This can be grabbed from [Webex For Developers](https://developer.webex.com/docs/api/getting-started/accounts-and-authentication)| This user will create rooms with the bot, (and vice versa) and exchange messages with it. Rooms will be deleted at the end of the test. **Make sure this is a different user from the AUTHORIZED_FLINT_USER**|
|HOSTED_FILE | URL for a file to upload in some of the message tests.| Any file suppported by Webex Teams will do, perhaps the one here: https://www.webex.com/content/dam/wbx/us/images/hp/hp_56565/Teams_Iconx2.png|

When the environment is set, run the tests:
```bash
npm i --only=dev
npm run test-as-user
```


# Support this Project

Find this project useful? Help suppport the continued development by submitting issues, feature requests, or code.
58 changes: 44 additions & 14 deletions docs/example1.md
@@ -1,44 +1,74 @@
#### Example Template Using Express
```js
var Flint = require('node-flint');
var webhook = require('node-flint/webhook');
var Framework = require('webex-node-bot-framework');
var webhook = require('webex-node-bot-framework/webhook');

var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());

// flint options
// framework options
var config = {
webhookUrl: 'http://myserver.com/flint',
webhookUrl: 'http://myserver.com/framework',
token: 'Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u',
port: 80
};

// init flint
var flint = new Flint(config);
flint.start();
// init framework
var framework = new Framework(config);
framework.start();

// An initialized event means your webhooks are all registered and the
// framework has created a bot object for all the spaces your bot is in
framework.on("initialized", function () {
framework.debug("Framework initialized successfully! [Press CTRL-C to quit]");
});

// A spawn event is generated when the framework finds a space with your bot in it
framework.on('spawn', function (bot) {
if (!framework.initialized) {
// don't say anything here or your bot's spaces will get
// spammed every time your server is restarted
framework.debug(`While starting up framework found our bot in a space called: ${bot.room.title}`);
} else {
// After initialization, a spawn event means your bot got added to
// a new space. Say hello, and tell users what you do!
bot.say('Hi there, you can say hello to me. Don\'t forget you need to mention me in a group space!');
}
});

var responded = false;
// say hello
flint.hears('/hello', function(bot, trigger) {
bot.say('Hello %s!', trigger.personDisplayName);
framework.hears('hello', function(bot, trigger) {
bot.say('Hello %s!', trigger.person.displayName);
responded = true;
});

// Its a good practice to handle unexpected input
framework.hears(/.*/gim, function(bot, trigger) {
if (!responded) {
bot.say('Sorry, I don\'t know how to respond to "%s"', trigger.message.text);
}
responded = false;
});

// define express path for incoming webhooks
app.post('/flint', webhook(flint));
app.post('/framework', webhook(framework));

// start express server
var server = app.listen(config.port, function () {
flint.debug('Flint listening on port %s', config.port);
framework.debug('Framework listening on port %s', config.port);
});

// gracefully shutdown (ctrl-c)
process.on('SIGINT', function() {
flint.debug('stoppping...');
framework.debug('stoppping...');
server.close();
flint.stop().then(function() {
framework.stop().then(function() {
process.exit();
});
});
```

[**Restify Example**](https://github.com/nmarus/flint/blob/master/docs/example2.md)
[**Restify Example**](https://github.com/nmarus/framework/blob/master/docs/example2.md)
26 changes: 13 additions & 13 deletions docs/example2.md
@@ -1,40 +1,40 @@
## Example #2 Using Restify
```js
var Flint = require('node-flint');
var webhook = require('node-flint/webhook');
var Framework = require('webex-node-bot-framework');
var webhook = require('webex-node-bot-framework/webhook');
var Restify = require('restify');
var server = Restify.createServer();
server.use(Restify.bodyParser());

// flint options
// framework options
var config = {
webhookUrl: 'http://myserver.com/flint',
webhookUrl: 'http://myserver.com/framework',
token: 'Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u',
port: 80
};

// init flint
var flint = new Flint(config);
flint.start();
// init framework
var framework = new Framework(config);
framework.start();

// say hello
flint.hears('/hello', function(bot, trigger) {
bot.say('Hello %s!', trigger.personDisplayName);
framework.hears('/hello', function(bot, trigger) {
bot.say('Hello %s!', trigger.person.displayName);
});

// define restify path for incoming webhooks
server.post('/flint', webhook(flint));
server.post('/framework', webhook(framework));

// start restify server
server.listen(config.port, function () {
flint.debug('Flint listening on port %s', config.port);
framework.debug('Framework listening on port %s', config.port);
});

// gracefully shutdown (ctrl-c)
process.on('SIGINT', function() {
flint.debug('stoppping...');
framework.debug('stoppping...');
server.close();
flint.stop().then(function() {
framework.stop().then(function() {
process.exit();
});
});
Expand Down
24 changes: 12 additions & 12 deletions docs/example3.md
@@ -1,24 +1,24 @@
## Example #3 Using Socket2me (experimental and under development)
An inbound, internet reachable port, is required for the Spark API to notify
Flint of webhook events. This is not always easy or possible.
An inbound, internet reachable port, is required for the Webex API to notify
Framework of webhook events. This is not always easy or possible.

Flint utilize a remote socket client through a
Framework utilize a remote socket client through a
[socket2me](https://github.com/nmarus/socket2me) server in the event you want to
stand up a bot where forwarding a port is not possible.

The remote socket2me server allows you to run Flint behind a NAT without adding
The remote socket2me server allows you to run Framework behind a NAT without adding
a port forward configuration to your firewall. To make use of a socket2me
server, you can either stand up your own socket2me server or make use of a
public/shared socket2me server. A single socket2me server can support many
clients/bots simultaneously.

```js
var Flint = require('node-flint');
var webhook = require('node-flint/webhook');
var Framework = require('webex-node-bot-framework');
var webhook = require('webex-node-bot-framework/webhook');
var Socket2meClient = require('socket2me-client');
var server = new Socket2meClient('https://socket.bothub.io');

// flint options
// framework options
var config = {
token: 'Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u'
};
Expand All @@ -27,16 +27,16 @@ var config = {
server.on('connected', function(webhookUrl) {
config.webhookUrl = webhookUrl;

var flint = new Flint(config);
flint.start();
var framework = new Framework(config);
framework.start();

// say hello
flint.hears('/hello', function(bot, trigger) {
bot.say('Hello %s!', trigger.personDisplayName);
framework.hears('/hello', function(bot, trigger) {
bot.say('Hello %s!', trigger.person.displayName);
});

server.requestHandler(function(request, respond) {
webhook(flint)(request);
webhook(framework)(request);
respond(200, 'OK');
});
});
Expand Down

0 comments on commit a6f3121

Please sign in to comment.