mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-19 20:19:15 +00:00
mongo adapter:next step, continue conversation from db
This commit is contained in:
25
docker-compose.yml
Normal file
25
docker-compose.yml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
version: '3.3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
mongo:
|
||||||
|
image: mongo
|
||||||
|
container_name: app_enviroment
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- "27019:27017"
|
||||||
|
environment:
|
||||||
|
MONGO_INITDB_DATABASE: bot
|
||||||
|
expose:
|
||||||
|
- 27019
|
||||||
|
mysql:
|
||||||
|
image: mysql
|
||||||
|
command: --default-authentication-plugin=mysql_native_password
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: example
|
||||||
|
MYSQL_DATABASE: bot
|
||||||
|
container_name: app_mysql
|
||||||
|
ports:
|
||||||
|
- "3306:3306"
|
||||||
|
expose:
|
||||||
|
- 3306
|
||||||
4043
package-lock.json
generated
Normal file
4043
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,7 @@
|
|||||||
"cli:rollup": "rollup --config ./packages/cli/rollup-cli.config.js ",
|
"cli:rollup": "rollup --config ./packages/cli/rollup-cli.config.js ",
|
||||||
"bot:rollup": "rollup --config ./packages/bot/rollup-bot.config.js",
|
"bot:rollup": "rollup --config ./packages/bot/rollup-bot.config.js",
|
||||||
"provider:rollup": "rollup --config ./packages/provider/rollup-provider.config.js ",
|
"provider:rollup": "rollup --config ./packages/provider/rollup-provider.config.js ",
|
||||||
"database:rollup": "rollup ./packages/database/index.js --config ./packages/database/rollup-cli.config.js",
|
"database:rollup": "rollup --config ./packages/database/rollup-database.config.js",
|
||||||
"format:check": "prettier --check ./packages",
|
"format:check": "prettier --check ./packages",
|
||||||
"format:write": "prettier --write ./packages",
|
"format:write": "prettier --write ./packages",
|
||||||
"lint:check": "eslint ./packages",
|
"lint:check": "eslint ./packages",
|
||||||
|
|||||||
@@ -23,7 +23,11 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@bot-whatsapp/cli": "*",
|
"@bot-whatsapp/cli": "*",
|
||||||
|
"@bot-whatsapp/database": "*",
|
||||||
"@bot-whatsapp/provider": "*",
|
"@bot-whatsapp/provider": "*",
|
||||||
"kleur": "^4.1.5"
|
"kleur": "^4.1.5"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"dotenv": "^16.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
37
packages/database/mongo/index.js
Normal file
37
packages/database/mongo/index.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
require('dotenv').config()
|
||||||
|
const { MongoClient } = require('mongodb')
|
||||||
|
|
||||||
|
const DB_URI = process.env.DB_URI || 'mongodb://0.0.0.0:27017'
|
||||||
|
const DB_NAME = process.env.DB_NAME || 'db_bot'
|
||||||
|
|
||||||
|
class MongoAdapter {
|
||||||
|
db
|
||||||
|
listHistory = []
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
console.log({ DB_URI })
|
||||||
|
this.init().then()
|
||||||
|
}
|
||||||
|
|
||||||
|
init = async () => {
|
||||||
|
try {
|
||||||
|
const client = new MongoClient(DB_URI, {})
|
||||||
|
await client.connect()
|
||||||
|
console.log('Connected successfully to server')
|
||||||
|
const db = client.db(DB_NAME)
|
||||||
|
this.db = db
|
||||||
|
return true
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Error', e)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
save = async (ctx) => {
|
||||||
|
await this.db.collection('history').insert(ctx)
|
||||||
|
console.log('Guardando DB...', ctx)
|
||||||
|
this.listHistory.push(ctx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = MongoAdapter
|
||||||
@@ -2,10 +2,17 @@
|
|||||||
"name": "@bot-whatsapp/database",
|
"name": "@bot-whatsapp/database",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "Esto es el conector a mysql, pg, mongo",
|
"description": "Esto es el conector a mysql, pg, mongo",
|
||||||
"main": "./lib/bundle.database.cjs",
|
"main": "./lib/mock/index.cjs",
|
||||||
"private": true,
|
"private": true,
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {}
|
"devDependencies": {},
|
||||||
|
"dependencies": {
|
||||||
|
"dotenv": "^16.0.3",
|
||||||
|
"mongodb": "^4.11.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"./lib/*"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
const commonjs = require('@rollup/plugin-commonjs')
|
|
||||||
const { nodeResolve } = require('@rollup/plugin-node-resolve')
|
|
||||||
const { join } = require('path')
|
|
||||||
|
|
||||||
const PATH = join(__dirname, 'lib', 'bundle.database.cjs')
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
input: join(__dirname, 'index.js'),
|
|
||||||
output: {
|
|
||||||
file: PATH,
|
|
||||||
format: 'cjs',
|
|
||||||
},
|
|
||||||
plugins: [commonjs(), nodeResolve()],
|
|
||||||
}
|
|
||||||
21
packages/database/rollup-database.config.js
Normal file
21
packages/database/rollup-database.config.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
const commonjs = require('@rollup/plugin-commonjs')
|
||||||
|
const { join } = require('path')
|
||||||
|
|
||||||
|
module.exports = [
|
||||||
|
{
|
||||||
|
input: join(__dirname, 'mock', 'index.js'),
|
||||||
|
output: {
|
||||||
|
file: join(__dirname, 'lib', 'mock', 'index.cjs'),
|
||||||
|
format: 'cjs',
|
||||||
|
},
|
||||||
|
plugins: [commonjs()],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: join(__dirname, 'mongo', 'index.js'),
|
||||||
|
output: {
|
||||||
|
file: join(__dirname, 'lib', 'mongo', 'index.cjs'),
|
||||||
|
format: 'cjs',
|
||||||
|
},
|
||||||
|
plugins: [commonjs()],
|
||||||
|
},
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user