Skip to content

Commit

Permalink
chore: next-version
Browse files Browse the repository at this point in the history
chore: next-version
  • Loading branch information
leifermendez authored May 29, 2023
2 parents d05d1b1 + bc10b3e commit 3909bcd
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bot-whatsapp/root",
"version": "0.1.26",
"version": "0.1.27",
"description": "Bot de wahtsapp open source para MVP o pequeños negocios",
"main": "app.js",
"private": true,
Expand Down
2 changes: 2 additions & 0 deletions packages/docs/src/routes/docs/providers/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Los proveedores disponibles hasta el momento son los siguientes:

[whatsapp-web.js](https://github.com/pedroslopez/whatsapp-web.js) `require('@bot-whatsapp/provider/web-whatsapp')`

[WPPConnect](https://github.com/wppconnect-team/wppconnect) `require('@bot-whatsapp/provider/wppconnect')`

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

[Baileys](https://github.com/whiskeysockets/Baileys) `require('@bot-whatsapp/provider/baileys')`
Expand Down
2 changes: 1 addition & 1 deletion packages/portal/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default component$(() => {
<a
class={'btn-link '}
target="_blank"
href="https://www.youtube.com/watch?v=1u0TTbjK5bo&list=PL_WGMLcL4jzViIlmyDZPnhAdkc8RXGkFh"
href="https://www.youtube.com/playlist?list=PL_WGMLcL4jzWPhdhcUyhbFU6bC0oJd2BR"
>
Ver videos
</a>
Expand Down
5 changes: 3 additions & 2 deletions packages/provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
"dependencies": {
"@bot-whatsapp/bot": "*",
"@ffmpeg-installer/ffmpeg": "^1.1.0",
"axios": "^1.4.0",
"combine-image": "^1.0.3",
"fluent-ffmpeg": "^2.1.2",
"follow-redirects": "^1.15.2",
"qr-image": "^3.2.0",
"rimraf": "^3.0.2",
"sharp": "^0.30.5",
"follow-redirects": "^1.15.2"
"sharp": "^0.30.5"
},
"exports": {
"./mock": "./lib/mock/index.cjs",
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": "github:WhiskeySockets/Baileys",
"@adiwajshing/baileys": "4.4.0",
"wa-sticker-formatter": "4.3.2"
}
}
2 changes: 1 addition & 1 deletion packages/provider/src/meta/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MetaProvider extends ProviderClass {
this.jwtToken = jwtToken
this.numberId = numberId
this.version = version
this.metHook = new MetaWebHookServer(verifyToken, port)
this.metHook = new MetaWebHookServer(jwtToken, numberId, version, verifyToken, port)
this.metHook.start()

const listEvents = this.busEvents()
Expand Down
65 changes: 44 additions & 21 deletions packages/provider/src/meta/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ const { EventEmitter } = require('node:events')
const polka = require('polka')
const { urlencoded, json } = require('body-parser')
const { generateRefprovider } = require('../../common/hash')
const { getMediaUrl } = require('./utils')

class MetaWebHookServer extends EventEmitter {
constructor(token, metaPort = 3000) {
constructor(jwtToken, numberId, version, token, metaPort = 3000) {
super()
this.metaServer = polka()
this.metaPort = metaPort
this.token = token

this.jwtToken = jwtToken
this.numberId = numberId
this.version = version
this.buildHTTPServer()
}

Expand All @@ -18,7 +23,7 @@ class MetaWebHookServer extends EventEmitter {
* @param {*} req
* @param {*} res
*/
incomingMsg = (req, res) => {
incomingMsg = async (req, res) => {
const { body } = req
const messages = body?.entry?.[0]?.changes?.[0]?.value?.messages

Expand All @@ -32,53 +37,64 @@ class MetaWebHookServer extends EventEmitter {
const to = body.entry[0].changes[0].value?.metadata?.display_phone_number

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_')
}

if (message.type === 'image') {
const body = generateRefprovider('_event_image_')
const idUrl = message.image?.id
const resolvedUrl = await getMediaUrl(this.version, idUrl, this.numberId, this.jwtToken)
const responseObj = {
type: message.type,
from: message.from,
url: resolvedUrl,
to,
id: message.image.id,
body,
}

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

if (message.type === 'document') {
const body = generateRefprovider('_event_document_')
const idUrl = message.document?.id
const resolvedUrl = await getMediaUrl(this.version, idUrl, this.numberId, this.jwtToken)
const responseObj = {
type: message.type,
from: message.from,
url: resolvedUrl, // Utilizar el valor resuelto de la promesa
to,
id: message.document.id,
body,
}

this.emit('message', responseObj)
} else if (message.type === 'video') {
}

if (message.type === 'video') {
const body = generateRefprovider('_event_video_')
const idUrl = message.video?.id

const resolvedUrl = await getMediaUrl(this.version, idUrl, this.numberId, this.jwtToken)

const responseObj = {
type: message.type,
from: message.from,
url: resolvedUrl, // Utilizar el valor resuelto de la promesa
to,
id: message.video.id,
body,
}

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

if (message.type === 'location') {
const body = generateRefprovider('_event_location_')

const responseObj = {
Expand All @@ -91,19 +107,24 @@ class MetaWebHookServer extends EventEmitter {
}

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

if (message.type === 'audio') {
const body = generateRefprovider('_event_audio_')
const idUrl = message.audio?.id
const resolvedUrl = await getMediaUrl(this.version, idUrl, this.numberId, this.jwtToken)
const responseObj = {
type: message.type,
from: message.from,
url: resolvedUrl, // Utilizar el valor resuelto de la promesa
to,
id: message.audio.id,
body,
}

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

if (message.type === 'sticker') {
const body = generateRefprovider('_event_sticker_')

const responseObj = {
Expand All @@ -115,7 +136,9 @@ class MetaWebHookServer extends EventEmitter {
}

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

if (message.type === 'contacts') {
const body = generateRefprovider('_event_contacts_')

const responseObj = {
Expand Down Expand Up @@ -171,7 +194,7 @@ class MetaWebHookServer extends EventEmitter {
res.end('Invalid token!')
}

emptyCtrl = (req, res) => {
emptyCtrl = (_, res) => {
res.end('')
}

Expand All @@ -192,7 +215,7 @@ class MetaWebHookServer extends EventEmitter {
*/
start() {
this.metaServer.listen(this.metaPort, () => {
console.log(`[meta]: Agregar esta url "WHEN A MESSAGE COMES IN"`)
console.log(`[meta]: Agregar esta url "Webhook"`)
console.log(`[meta]: POST http://localhost:${this.metaPort}/webhook`)
console.log(`[meta]: Más información en la documentación`)
})
Expand Down
22 changes: 22 additions & 0 deletions packages/provider/src/meta/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const axios = require('axios')

async function getMediaUrl(version, IdMedia, numberId, Token) {
try {
const response = await axios.get(
`https://graph.facebook.com/${version}/${IdMedia}?phone_number_id=${numberId}`,
{
headers: {
Authorization: `Bearer ${Token}`,
},
maxBodyLength: Infinity,
}
)
return response.data?.url
} catch (error) {
console.log(error)
}
}

module.exports = {
getMediaUrl,
}
29 changes: 28 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion starters/apps/base-baileys-json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@bot-whatsapp/database": "latest",
"@bot-whatsapp/provider": "latest",
"@bot-whatsapp/portal": "latest",
"@adiwajshing/baileys": "github:WhiskeySockets/Baileys",
"@adiwajshing/baileys": "4.4.0",
"mime-types": "2.1.35",
"wa-sticker-formatter": "4.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion starters/apps/base-baileys-memory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@bot-whatsapp/database": "latest",
"@bot-whatsapp/provider": "latest",
"@bot-whatsapp/portal": "latest",
"@adiwajshing/baileys": "github:WhiskeySockets/Baileys",
"@adiwajshing/baileys": "4.4.0",
"mime-types": "2.1.35",
"wa-sticker-formatter": "4.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion starters/apps/base-baileys-mongo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@bot-whatsapp/database": "latest",
"@bot-whatsapp/provider": "latest",
"@bot-whatsapp/portal": "latest",
"@adiwajshing/baileys": "github:WhiskeySockets/Baileys",
"@adiwajshing/baileys": "4.4.0",
"mime-types": "2.1.35",
"mongodb": "^4.12.1",
"wa-sticker-formatter": "4.3.2"
Expand Down
2 changes: 1 addition & 1 deletion starters/apps/base-baileys-mysql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@bot-whatsapp/database": "latest",
"@bot-whatsapp/provider": "latest",
"@bot-whatsapp/portal": "latest",
"@adiwajshing/baileys": "github:WhiskeySockets/Baileys",
"@adiwajshing/baileys": "4.4.0",
"mime-types": "2.1.35",
"mysql2": "^2.3.3",
"wa-sticker-formatter": "4.3.2"
Expand Down

0 comments on commit 3909bcd

Please sign in to comment.