Skip to content
This repository has been archived by the owner on Mar 18, 2020. It is now read-only.

Full example #6

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ $ npm i --save @broid/skype @broid/slack @broid/messenger @broid/discord
$ npm i --save @broid/kit-botpress
```

6. Copy past the basic code and play with it!
6. Copy paste the basic code and play with it!

```javascript

Expand Down
89 changes: 89 additions & 0 deletions example/botpress/botfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
module.exports = {

/*
Where the content is stored
You can access this property from `bp.dataLocation`
*/
dataDir: process.env.BOTPRESS_DATA_DIR || './data',

/*
The port on which the API and UI will be available
*/
port: process.env.BOTPRESS_PORT || process.env.PORT || 3000,

/*
Some modules might generate static configuration files
*/
modulesConfigDir: process.env.BOTPRESS_CONFIG_DIR || './modules_config',

/*
By default logs are enabled and available in `dataDir`
*/
disableFileLogs: false,
log: {
file: 'bot.log',
maxSize: 1e6 // 1mb
},

/*
Botpress collects some anonymous usage statistics to help us put our efforts at the right place
*/
optOutStats: false,

/*
Where the notifications are stored.
TODO: These should be stored in the database
*/
notification: {
file: 'notifications.json',
maxLength: 50
},

/*
Access control of admin panel
*/
login: {
enabled: process.env.NODE_ENV === 'production',
tokenExpiry: '6 hours',
password: process.env.BOTPRESS_PASSWORD || 'password',
maxAttempts: 3,
resetAfter: 10 * 60 * 1000 // 10 minutes
},

/*
Postgres configuration
If Postgres is not enabled, Botpress uses SQLite 3 (file-based database)
*/
postgres: {
enabled: process.env.DATABASE === 'postgres',
connection: process.env.DATABASE_URL,
host: process.env.PG_HOST || '127.0.0.1',
port: process.env.PG_PORT || 5432,
user: process.env.PG_USER || '',
password: process.env.PG_PASSWORD || '',
database: process.env.PG_DB || '',
ssl: process.env.PG_SSL || false
},

umm: {
/*
The file containing the UMM Content (Universal Message Markdown)
Can be an absolute or relative path (to your bot location)
*/
contentPath: 'content.yml'
},

middleware: {
/*
By default Botpress will automatically load all the middlewares before starting your bot
If this is set to false, you should call `bp.middlewares.load` manually
*/
autoLoading: true
},

// **** Update this if you bought a Botpress license ****
license: {
// customerId: process.env.BOTPRESS_CUSTOMER_ID || 'your_customer_id_here',
// licenseKey: process.env.BOTPRESS_LICENSE_KEY || 'your_key_here'
}
}
18 changes: 18 additions & 0 deletions example/botpress/content.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
welcome: # this is the #welcome bloc referenced in index.js
- typing: true
text: # Picks one randomly
- Hey there!
- Hello {{user.first_name}}
- Good day :)
- text: This is just a regular Hello World, I don't do anything ;)
typing: 2s
- text: Make sure to check out the 'index.js' file to see how I work
typing: true
- wait: 5s
- text: You can say goodbye now
typing: 1s

goodbye:
- text: You are leaving because of reason {{reason}}
typing: true
- Hope to see you back again soon! # if no other properties, you can just send a strings
1 change: 1 addition & 0 deletions example/botpress/data/middlewares.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions example/botpress/data/notification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
13 changes: 13 additions & 0 deletions example/botpress/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = function(bp) {
bp.middlewares.load();

//Catch 'hello world' from 'facebook'
bp.hear({
platform: 'slack',
type: 'message',
text: 'hello world'
}, (event, next) => {
console.log("HERE RECEUVED");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhere here I want to see reply function call (or something like that), which will pass data back to broid-kit

console.log(event.text);
})
}
16 changes: 16 additions & 0 deletions example/botpress/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "botpress",
"version": "0.0.1",
"description": "",
"main": "index.js",
"dependencies": {
"botpress": "1.x",
"botpress-web": "1.x"
},
"scripts": {
"start": "botpress start",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "Botpress Proprietary License"
}
157 changes: 157 additions & 0 deletions example/botpress/theme.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*
IMPORTANT!
This file needs to be compiles to theme.css and be put at your bot's root
*/

#app {
/* LOGO */
.bp-sidebar-header {
.bp-logo {}
}


/* SIDEBAR */

.bp-react-sidebar {}

.bp-sidebar {
.bp-sidebar-active {}
}

.bp-sidebar-footer {
.bp-inner-footer {}
.bp-name {}
.bp-production {}
.bp-edition-license {}
.bp-buy {}

.bp-status {
.bp-dot {
.bp-reached {}
}
}

.bp-progress {
.bp-used {}
.bp-warning {}
.bp-urgent {}
.bp-reached {}
}
.bp-about {}
}


/* HEADER */
.bp-page-header {}
.bp-navbar {
.bp-slack {}
}


/* NOTIFICATIONS */
.bp-notifications-dropdown {
.bp-hub-message {}
.bp-top-menu {
.bp-item {}
.bp-level-success {}
.bp-level-info {}
.bp-level-error {}
.bp-item-unread {}
}
}


/* CONTENT */
.bp-content-wrapper {}


/* MIDDLEWARE */
.bp-middleware-list {
.bp-header {
.bp-help {}
}
.bp-middleware {
.bp-circle {}
.bp-help-icon {}
}

.bp-disabled {
.bp-circle {}
}
}


/* MODULES */
.bp-module-panel {
.bp-module-title {}
.bp-module-description {}
.bp-module-author {}
.bp-module-license {}
}


/* LOGIN */
.bp-login {
.bp-loading {}
.bp-header {}
}


/* DASHBOARD */
.bp-dashboard {
.bp-info {
.bp-name {}
.bp-description {}
.bp-author {}
.bp-version {}
.bp-license {}
.bp-where-from {}
}

.bp-hero {
.bp-info {}

.bp-contribution {
.bp-rays-anim {}
.bp-rays {}
.bp-content {
.bp-username {}
}
}
}
}


/* ADMIN */
.bp-admin {
.bp-user {
.bp-table {}
}
.bp-token {
.bp-table {}
}
}


/* PROFILE */
.bp-profile {}


/* ROLES */
.bp-roles {}


/* GENERAL ELEMENTS */
.panel {
.panel-heading {}
}

.form-control:focus {}
.bp-button {}
.bp-button-uninstall {}
.bp-button-danger {}

/* STYLES APPLY DIRECTLY TO APP */

height: 100%;
}
28 changes: 28 additions & 0 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const path = require("path");
const express = require("express");
const Bot = require("@broid/kit");
const BroidSLack = require("@broid/slack");
const BroidKitBotpress = require("@broid/kit-botpress");
const bodyParser= require("body-parser");

const app = express();
const bot = new Bot({ logLevel: "info" });
const slack = new BroidSLack({ token: "<token>" });

bot.use(slack);
bot.use(new BroidKitBotpress({ botpressPath: path.join(__dirname, 'botpress') }));

app.use("/", bot.getRouter());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.listen(8080);

let sent = false;
bot.hear('.*', 'Person')
.subscribe((data) => {
console.log("hear message", data.message);
if (!sent) {
sent = true;
bot.sendText("Hi, How are you?", data.message);
}
});
13 changes: 13 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "broid-kit-botpress-example",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"@broid/kit": "^1.0.2",
"@broid/kit-botpress": "^0.1.0",
"@broid/messenger": "^2.0.4",
"@broid/slack": "^2.1.1",
"body-parser": "^1.17.2",
"express": "^4.15.3"
}
}
Loading