Skip to content

Commit

Permalink
chore(release): 0.1.27
Browse files Browse the repository at this point in the history
chore(release): 0.1.27
  • Loading branch information
leifermendez committed May 28, 2023
2 parents b2ae3d2 + d05d1b1 commit 43f4ed8
Show file tree
Hide file tree
Showing 26 changed files with 2,867 additions and 2,958 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.1.27](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.25...v0.1.27) (2023-05-28)


### Features

* **adapter:** :zap: added that it automatically generates the date when the data is added to the db ([889cbfa](https://github.com/leifermendez/bot-whatsapp/commit/889cbfab8abfb76ed8e111e702bdad93483ae611))
* **provider:** :sparkles: the image, video, document, stickers, location and vcard events are added ([0705aeb](https://github.com/leifermendez/bot-whatsapp/commit/0705aeb6077fd151ccf7a37582f7afe64e089b36))


### Bug Fixes

* **bot:** :zap: hot fix `fotoFlow` and download ([dced080](https://github.com/leifermendez/bot-whatsapp/commit/dced08017c823791131a29ef4a5e81090800794c))
* **provider:** :zap: version is added ([d4818f2](https://github.com/leifermendez/bot-whatsapp/commit/d4818f289d7e559fa46076c34c6ddfb1deaf427d))
* **provider:** meta improved 馃敟 ([2f21dfd](https://github.com/leifermendez/bot-whatsapp/commit/2f21dfd2b9092736a190a0a1ce4a4fa3762999e0))

### [0.1.25](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.23...v0.1.25) (2023-04-07)


Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bot-whatsapp/root",
"version": "0.1.25",
"version": "0.1.26",
"description": "Bot de wahtsapp open source para MVP o peque帽os negocios",
"main": "app.js",
"private": true,
Expand Down Expand Up @@ -84,12 +84,12 @@
"standard-version": "^9.5.0",
"uvu": "^0.5.6"
},
"packageManager": "pnpm@7.25.1",
"packageManager": "pnpm@8.5.0",
"engines": {
"node": ">=16",
"npm": "please-use-pnpm",
"yarn": "please-use-pnpm",
"pnpm": ">=7.18.0"
"pnpm": ">=8.5.0"
},
"author": "Leifer Mendez <[email protected]>"
}
4 changes: 3 additions & 1 deletion packages/bot/core/core.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ class CoreClass {
const parseListMsg = await this.flowClass.find(flowParentId?.ref, true, flowTree)
if (endFlowFlag) return
for (const msg of parseListMsg) {
await this.sendProviderAndSave(from, msg)
const msgParse = this.flowClass.findSerializeByRef(msg?.ref)
const ctxMessage = { ...msgParse, ...msg }
await this.sendProviderAndSave(from, ctxMessage).then(() => resolveCbEveryCtx(ctxMessage))
}
await endFlow(flag)()
return
Expand Down
10 changes: 7 additions & 3 deletions packages/bot/io/flow.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ class FlowClass {

const mapSensitive = (str, mapOptions = { sensitive: false, regex: false }) => {
if (mapOptions.regex) return new RegExp(str)
const regexSensitive = mapOptions.sensitive ? 'g' : 'i'
const regexSensitive = mapOptions.sensitive ? 'g' : 'gi'
if (Array.isArray(str)) {
return new RegExp(str.join('|'), regexSensitive)
const patterns = mapOptions.sensitive ? str.map((item) => `\\b${item}\\b`) : str
return new RegExp(patterns.join('|'), regexSensitive)
}
return new RegExp(str, regexSensitive)
const pattern = mapOptions.sensitive ? `\\b${str}\\b` : str
return new RegExp(pattern, regexSensitive)
}

const findIn = (keyOrWord, symbol = false, flow = overFlow) => {
Expand Down Expand Up @@ -60,6 +62,8 @@ class FlowClass {

findIndexByRef = (ref) => this.flowSerialize.findIndex((r) => r.ref === ref)

findSerializeByRef = (ref) => this.flowSerialize.find((r) => r.ref === ref)

getRefToContinueChild = (keyword) => {
try {
const flowChilds = this.flowSerialize
Expand Down
7 changes: 6 additions & 1 deletion packages/database/src/mongo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ class MongoAdapter {
}

save = async (ctx) => {
await this.db.collection('history').insert(ctx)
const ctxWithDate = {
...ctx,
date: new Date(),
}
await this.db.collection('history').insertOne(ctxWithDate)

this.listHistory.push(ctx)
}
}
Expand Down
10 changes: 6 additions & 4 deletions packages/database/src/mysql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ class MyslAdapter {
})

save = (ctx) => {
const values = [[ctx.ref, ctx.keyword, ctx.answer, ctx.refSerialize, ctx.from, JSON.stringify(ctx.options)]]
const sql = 'INSERT INTO history (ref, keyword, answer, refSerialize, phone, options ) values ?'
const values = [
[ctx.ref, ctx.keyword, ctx.answer, ctx.refSerialize, ctx.from, JSON.stringify(ctx.options), null],
]
const sql = 'INSERT INTO history (ref, keyword, answer, refSerialize, phone, options, created_at) values ?'

this.db.query(sql, [values], (err) => {
if (err) throw err
console.log('Guardado en DB...', values)
})
this.listHistory.push(ctx)
}

createTable = () =>
Expand All @@ -67,7 +68,8 @@ class MyslAdapter {
answer longtext NOT NULL,
refSerialize varchar(255) NOT NULL,
phone varchar(255) NOT NULL,
options longtext NOT NULL)
options longtext NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)
CHARACTER SET utf8mb4 COLLATE utf8mb4_General_ci`

this.db.query(sql, (err) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/routes/docs/essential/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Los proveedores disponibles hasta el momento son los siguientes:

[Venom](https://github.com/orkestral/venom) `require('@bot-whatsapp/provider/venom')`

[Baileys](https://github.com/adiwajshing/Baileys) `require('@bot-whatsapp/provider/baileys')`
[Baileys](https://github.com/whiskeysockets/Baileys) `require('@bot-whatsapp/provider/baileys')`

[Meta Official](https://developers.facebook.com/docs/whatsapp/cloud-api/reference/messages) `require('@bot-whatsapp/provider/meta')`

Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/routes/docs/install/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Cada plantilla tiene sus dependencias necesarias basadas en tu previa selecci贸n
"@bot-whatsapp/cli": "latest",
"@bot-whatsapp/database": "latest",
"@bot-whatsapp/provider": "latest",
"@adiwajshing/baileys": "4.4.0",
"@adiwajshing/baileys": "github:WhiskeySockets/Baileys",
"mysql2": "^2.3.3", 馃憟
},
```
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/src/routes/docs/layout!.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default component$(() => {
<div class={'max-w-8xl'}>
<div
class={
'hidden lg:block fixed z-20 inset-0 top-[4rem] left-[max(0px,calc(50%-48rem))] right-auto w-[14.5rem] py-5 px-8 overflow-y-auto'
'hidden lg:block fixed z-20 inset-0 top-[4rem] right-auto w-[14.5rem] py-5 px-8 overflow-y-auto'
}
>
<NavBar options={store} />
Expand All @@ -33,7 +33,7 @@ export default component$(() => {
</div>
<div
class={
'hidden lg:block fixed z-20 inset-0 top-[4rem] right-[max(0px,calc(50%-48rem))] left-auto w-[14.5rem] py-5 px-8 overflow-y-auto'
'hidden lg:block fixed z-20 inset-0 top-[4rem] left-auto w-[14.5rem] py-5 px-8 overflow-y-auto'
}
>
<ExtraBar />
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/routes/docs/providers/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Los proveedores disponibles hasta el momento son los siguientes:

[Venom](https://github.com/orkestral/venom) `require('@bot-whatsapp/provider/venom')`

[Baileys](https://github.com/adiwajshing/Baileys) `require('@bot-whatsapp/provider/baileys')`
[Baileys](https://github.com/whiskeysockets/Baileys) `require('@bot-whatsapp/provider/baileys')`

[Meta Official](https://developers.facebook.com/docs/whatsapp/cloud-api/reference/messages) `require('@bot-whatsapp/provider/meta')`

Expand Down
3 changes: 2 additions & 1 deletion packages/docs/src/routes/docs/providers/meta/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ const main = async () => {
const adapterProvider = createProvider(MetaProvider, {
jwtToken: process.env.JWTOKEN, //EAARBW3ZBGU0UBAACDjtQIzI8JuEa.............
numberId: process.env.NUMBER_ID, //103975305758520
verifyToken: process.env.VERIFY_TOKEN, //LO_QUE_SEA
verifyToken: process.env.VERIFY_TOKEN, //LO_QUE_SEA,
version:'v16.0'
})

createBot({
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/routes/docs/requirements/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ v18.12.1

- **Windows**: [Ver video](https://youtu.be/xRXHQlqA3Ak?t=376). Si necesitas ayuda para instalar Node en Windows. A continuaci贸n te comparto un video en el minuto exacto donde explico como instalar.
- **Ubuntu**: Te comparto un recurso de **[Digital Ocean](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-20-04-es)** donde explica como instalar node en Ubuntu.
- **Mac-Os**: Te comparto un recurso de **[Digital Ocean] (https://www.digitalocean.com/community/tutorials/how-to-install-node-js-and-create-a-local-development-environment-on-macos)** donde explica como instalar node en Mac-Os.
- **Mac-Os**: Te comparto un recurso de **[Digital Ocean](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-and-create-a-local-development-environment-on-macos)** donde explica como instalar node en Mac-Os.

---

Expand Down
2 changes: 1 addition & 1 deletion packages/provider/common/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const generalDownload = async (url) => {

const handleFile = (pathInput, ext) =>
new Promise((resolve, reject) => {
const fullPath = `${pathInput}.${ext}`
const fullPath = checkIsLocal ? `${pathInput}` : `${pathInput}.${ext}`
rename(pathInput, fullPath, (err) => {
if (err) reject(null)
resolve(fullPath)
Expand Down
2 changes: 1 addition & 1 deletion packages/provider/src/baileys/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const logger = new Console({
/**
* 鈿欙笍 BaileysProvider: Es una clase tipo adaptor
* que extiende clases de ProviderClass (la cual es como interfaz para sber que funciones rqueridas)
* https://github.com/adiwajshing/Baileys
* https://github.com/whiskeysockets/Baileys
*/
class BaileysProvider extends ProviderClass {
globalVendorArgs = { name: `bot`, gifPlayback: false }
Expand Down
2 changes: 1 addition & 1 deletion packages/provider/src/baileys/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"@adiwajshing/baileys": "4.4.0",
"@adiwajshing/baileys": "github:WhiskeySockets/Baileys",
"wa-sticker-formatter": "4.3.2"
}
}
47 changes: 47 additions & 0 deletions packages/provider/src/meta/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class MetaProvider extends ProviderClass {
sendtext = async (number, message) => {
const body = {
messaging_product: 'whatsapp',
recipient_type: 'individual',
to: number,
type: 'text',
text: {
Expand Down Expand Up @@ -120,6 +121,52 @@ class MetaProvider extends ProviderClass {
}
return this.sendMessageMeta(body)
}

/**
* Enviar listas alternativo
* @param {*} number
* @param {*} header
* @param {*} text
* @param {*} footer
* @param {*} button
* @param {*} list
* @returns
*/
sendList = async (number, header, text, footer, button, list) => {
const parseList = list.map((list) => ({
title: list.title,
rows: list.rows.map((row) => ({
id: row.id,
title: row.title,
description: row.description,
})),
}))

const body = {
messaging_product: 'whatsapp',
recipient_type: 'individual',
to: number,
type: 'interactive',
interactive: {
type: 'list',
header: {
type: 'text',
text: header,
},
body: {
text: text,
},
footer: {
text: footer,
},
action: {
button: button,
sections: parseList,
},
},
}
return this.sendMessageMeta(body)
}
/**
* Enviar buttons
* @param {*} number
Expand Down
103 changes: 98 additions & 5 deletions packages/provider/src/meta/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { EventEmitter } = require('node:events')
const polka = require('polka')
const { urlencoded, json } = require('body-parser')
const { generateRefprovider } = require('../../common/hash')

class MetaWebHookServer extends EventEmitter {
constructor(token, metaPort = 3000) {
Expand Down Expand Up @@ -30,11 +31,103 @@ class MetaWebHookServer extends EventEmitter {
const [message] = messages
const to = body.entry[0].changes[0].value?.metadata?.display_phone_number

this.emit('message', {
from: message.from,
to,
body: message.type === 'text' ? message.text?.body : message.interactive?.button_reply.title,
})
if (message.type === 'text') {
// Si es un mensaje de texto, extrae el cuerpo del mensaje
const body = message.text?.body
// Luego, crea un objeto con los datos que deseas enviar al cuerpo de la respuesta
const responseObj = {
type: message.type,
from: message.from,
to,
body,
}
// Finalmente, env铆a el objeto como respuesta utilizando el evento 'message'
this.emit('message', responseObj)
} else if (message.type === 'image') {
const body = generateRefprovider('_event_image_')

const responseObj = {
type: message.type,
from: message.from,
to,
id: message.image.id,
body,
}

this.emit('message', responseObj)
} else if (message.type === 'document') {
const body = generateRefprovider('_event_document_')

const responseObj = {
type: message.type,
from: message.from,
to,
id: message.document.id,
body,
}
this.emit('message', responseObj)
} else if (message.type === 'video') {
const body = generateRefprovider('_event_video_')

const responseObj = {
type: message.type,
from: message.from,
to,
id: message.video.id,
body,
}

this.emit('message', responseObj)
} else if (message.type === 'location') {
const body = generateRefprovider('_event_location_')

const responseObj = {
type: message.type,
from: message.from,
to,
latitude: message.location.latitude,
longitude: message.location.longitude,
body,
}

this.emit('message', responseObj)
} else if (message.type === 'audio') {
const body = generateRefprovider('_event_audio_')

const responseObj = {
type: message.type,
from: message.from,
to,
id: message.audio.id,
body,
}

this.emit('message', responseObj)
} else if (message.type === 'sticker') {
const body = generateRefprovider('_event_sticker_')

const responseObj = {
type: message.type,
from: message.from,
to,
id: message.sticker.id,
body,
}

this.emit('message', responseObj)
} else if (message.type === 'contacts') {
const body = generateRefprovider('_event_contacts_')

const responseObj = {
type: message.type,
from: message.from,
contacts: [{ name: message.contacts[0].name, phones: message.contacts[0].phones }],
to,
body,
}

this.emit('message', responseObj)
}

const json = JSON.stringify({ body })
res.end(json)
Expand Down

0 comments on commit 43f4ed8

Please sign in to comment.