Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
1,380 additions
and
1,139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,8 @@ node_modules | |
|
||
# Private environments | ||
.env | ||
ToDo.private | ||
ToDo.private | ||
|
||
# Test version of sample | ||
example1.js | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.