Skip to content

Commit

Permalink
add python recipe, add fb/line/slack bot, clean the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
guesswho461 committed Apr 22, 2020
1 parent 27e26d0 commit 18e2988
Show file tree
Hide file tree
Showing 125 changed files with 3,755 additions and 536 deletions.
17 changes: 17 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// https://jwt.io/#debugger-io?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJjYWtlVmVuZGluZyIsIm5hbWUiOiJKYXNoIEhzdSJ9.DSYy7W5a6iLSre1cmRaWBEdxYGu81jzdwdWnbnqRr4c

module.exports = {
fbMesChatBotToken:
"EAAHGWe0Bo1IBABMq7O3G0ZCpZCwjCyzFpVXRNShYUqeDjJzrrkRWSCgcKvEehoYYizuBbaZCmx0bndc3YGVbHq0tvrmewq81qRkS5YFf5kbBc16jtawQTsUj9a5jazDAF35fLoGy1jBTnyxgMsACP7e0hLlZC75rZBWxGORqb98ozy9cq6UynV6px2YOX088ZD",
token:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJjYWtlVmVuZGluZyIsIm5hbWUiOiJKYXNoIEhzdSJ9.DSYy7W5a6iLSre1cmRaWBEdxYGu81jzdwdWnbnqRr4c",
subject: "cakeVending",
name: "Jash Hsu",
secret: "0919304983",
backendVersion: "cakeVendingBackend v1.0",
backendPort: 8081,
mqttBrokerPort: 1883,
mqttBrokerWSPort: 8000, //websockets
serverPort: 10010,
serverVersion: "cakeVendingServer v1.0",
};
19 changes: 19 additions & 0 deletions fbbot/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
MESSENGER_PAGE_ID=
MESSENGER_ACCESS_TOKEN=
MESSENGER_APP_ID=
MESSENGER_APP_SECRET=
MESSENGER_VERIFY_TOKEN=

WHATSAPP_ACCOUNT_SID=
WHATSAPP_AUTH_TOKEN=
WHATSAPP_PHONE_NUMBER=

LINE_ACCESS_TOKEN=
LINE_CHANNEL_SECRET=

TELEGRAM_ACCESS_TOKEN=

SLACK_ACCESS_TOKEN=
SLACK_SIGNING_SECRET=

VIBER_ACCESS_TOKEN=
2 changes: 2 additions & 0 deletions fbbot/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
27 changes: 27 additions & 0 deletions fbbot/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
parserOptions: {
ecmaVersion: 2018,
},
extends: ['eslint:recommended', 'prettier'],
env: {
node: true,
},
rules: {
'prettier/prettier': [
'error',
{
trailingComma: 'es5',
singleQuote: true,
},
],
},
plugins: ['prettier'],
overrides: [
{
files: ['**/*.test.js'],
env: {
jest: true,
},
},
],
};
63 changes: 63 additions & 0 deletions fbbot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Taken from https://github.com/github/gitignore/blob/master/Node.gitignore

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# jest-junit
junit.xml

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
62 changes: 62 additions & 0 deletions fbbot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
This project was bootstrapped with
[Bottender](https://github.com/Yoctol/bottender) init script.

## Sending Feedback

Always feel free to open an issue to
[Bottender](https://github.com/Yoctol/bottender/issues) repository.

## Configuration

### The `bottender.config.js` File

Bottender configuration file. You can use this file to provide settings for the session store and channels.

### The `.env` File

Bottender utilizes the [dotenv](https://www.npmjs.com/package/dotenv) package to load your environment variables when developing your app.

To make the bot work, you must put required environment variables into your `.env` file.

## Available Scripts

In the project directory, you can run:

### `npm run dev`

Runs the app in development mode.<br>
The bot will automatically reload if you make changes to the code.<br>
By default, server runs on [http://localhost:5000](http://localhost:5000) and ngrok runs on [http://localhost:4040](http://localhost:4040).

To run in [Console Mode](https://bottender.js.org/docs/en/the-basics-console-mode), provide the `--console` option:

```sh
npm run dev -- --console
yarn dev --console
```

### `npm start`

Runs the app in production mode.<br>
By default, server runs on [http://localhost:5000](http://localhost:5000).

To run in [Console Mode](https://bottender.js.org/docs/en/the-basics-console-mode), provide the `--console` option:

```sh
npm start -- --console
yarn start --console
```

### `npm run lint`

Runs the linter rules using [Eslint](https://eslint.org/).

### `npm test`

Runs the test cases using [Jest](https://jestjs.io/).

## Learn More

To learn Bottender, check out the [Bottender documentation](https://bottender.js.org/docs/en/getting-started).

For more examples, see [Bottender examples](https://github.com/Yoctol/bottender/tree/master/examples).
67 changes: 67 additions & 0 deletions fbbot/bottender.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
module.exports = {
session: {
driver: "memory",
stores: {
memory: {
maxSize: 500,
},
file: {
dirname: ".sessions",
},
redis: {
port: 6379,
host: "127.0.0.1",
password: "auth",
db: 0,
},
mongo: {
url: "mongodb://localhost:27017",
collectionName: "sessions",
},
},
},
initialState: {},
channels: {
messenger: {
enabled: true,
path: "/webhooks/messenger",
pageId: process.env.MESSENGER_PAGE_ID,
accessToken: process.env.MESSENGER_ACCESS_TOKEN,
appId: process.env.MESSENGER_APP_ID,
appSecret: process.env.MESSENGER_APP_SECRET,
verifyToken: process.env.MESSENGER_VERIFY_TOKEN,
},
whatsapp: {
enabled: false,
path: "/webhooks/whatsapp",
accountSid: process.env.WHATSAPP_ACCOUNT_SID,
authToken: process.env.WHATSAPP_AUTH_TOKEN,
phoneNumber: process.env.WHATSAPP_PHONE_NUMBER,
},
line: {
enabled: false,
path: "/webhooks/line",
accessToken: process.env.LINE_ACCESS_TOKEN,
channelSecret: process.env.LINE_CHANNEL_SECRET,
},
telegram: {
enabled: false,
path: "/webhooks/telegram",
accessToken: process.env.TELEGRAM_ACCESS_TOKEN,
},
slack: {
enabled: false,
path: "/webhooks/slack",
accessToken: process.env.SLACK_ACCESS_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
},
viber: {
enabled: false,
path: "/webhooks/viber",
accessToken: process.env.VIBER_ACCESS_TOKEN,
sender: {
name: "xxxx",
},
},
},
};
1 change: 1 addition & 0 deletions fbbot/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./src');
9 changes: 9 additions & 0 deletions fbbot/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
testEnvironment: 'node',
moduleFileExtensions: ['js'],
transformIgnorePatterns: ['/node_modules/'],
testMatch: [
'<rootDir>/**/__tests__/**/*.js',
'<rootDir>/**/*.{spec,test}.js',
],
};
24 changes: 24 additions & 0 deletions fbbot/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "fbbot",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "bottender dev",
"lint": "eslint . ",
"start": "bottender start",
"test": "jest"
},
"dependencies": {
"bottender": "1.4.1",
"eslint": "6.8.0",
"eslint-config-prettier": "6.11.0",
"eslint-plugin-prettier": "3.1.3",
"jest": "25.4.0",
"prettier": "2.0.5",
"axios": "^0.19.2",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"morgan": "^1.9.1"
}
}
40 changes: 40 additions & 0 deletions fbbot/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const express = require("express");
const app = express();
const http = require("http");
const https = require("https");
const fs = require("fs");
const bodyParser = require("body-parser");
const cors = require("cors");
const morgan = require("morgan");
const axios = require("axios");
const config = require("../../config");

app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.text());
app.use(morgan("dev"));

app.get("/version", (req, res) => {
res.send(config.serverVersion);
});

let lastText = "initial";

app.post("/module/offline", (req, res) => {
lastText = req.body;
res.sendStatus(200);
});

http.createServer(app).listen(config.serverPort, () => {
console.log("cake vending server listening on port " + config.serverPort);
});

module.exports = async function App(context) {
if (context.event.isText) {
if (context.event.text === "show offline") {
await context.sendText(lastText);
} else {
await context.sendText("welcome to cake vending fb bot");
}
}
};
7 changes: 7 additions & 0 deletions fbbot/src/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const App = require('.');

describe('index.js', () => {
it('should be defined', () => {
expect(App).toBeDefined();
});
});
19 changes: 19 additions & 0 deletions linebot/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
MESSENGER_PAGE_ID=
MESSENGER_ACCESS_TOKEN=
MESSENGER_APP_ID=
MESSENGER_APP_SECRET=
MESSENGER_VERIFY_TOKEN=

WHATSAPP_ACCOUNT_SID=
WHATSAPP_AUTH_TOKEN=
WHATSAPP_PHONE_NUMBER=

LINE_ACCESS_TOKEN=
LINE_CHANNEL_SECRET=

TELEGRAM_ACCESS_TOKEN=

SLACK_ACCESS_TOKEN=
SLACK_SIGNING_SECRET=

VIBER_ACCESS_TOKEN=
2 changes: 2 additions & 0 deletions linebot/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
Loading

0 comments on commit 18e2988

Please sign in to comment.