mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-17 19:26:23 +00:00
Merge branch 'codigoencasa:main' into main
This commit is contained in:
4
.github/workflows/contributors.yml
vendored
4
.github/workflows/contributors.yml
vendored
@@ -3,10 +3,6 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- dev
|
||||
types: [closed]
|
||||
|
||||
jobs:
|
||||
contrib-readme-job:
|
||||
|
||||
39
.github/workflows/releases.yml
vendored
39
.github/workflows/releases.yml
vendored
@@ -1,10 +1,8 @@
|
||||
name: 🚀⚡ Liberando versiones
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*.*.*'
|
||||
|
||||
release:
|
||||
types: [created]
|
||||
jobs:
|
||||
############ RELEASE ############
|
||||
release:
|
||||
@@ -27,35 +25,42 @@ jobs:
|
||||
|
||||
- run: corepack enable
|
||||
|
||||
- name: Set User
|
||||
run: git config --global user.email "leifer.contacto@gmail.com" && git config --global user.name "Leifer Mendez"
|
||||
|
||||
- name: Install NPM Dependencies
|
||||
run: yarn install --immutable --network-timeout 300000
|
||||
|
||||
- name: Set CHANGELOG
|
||||
run: yarn release
|
||||
|
||||
- name: get-npm-version
|
||||
id: package-version
|
||||
uses: martinbeentjes/npm-get-version-action@main
|
||||
|
||||
- name: Build Package
|
||||
run: yarn build:full
|
||||
|
||||
- name: Release @bot-whatsapp/bot
|
||||
run: yarn node ./scripts/release.js --name=bot --version="${{ steps.vars.outputs.tag }}" --token="${{ secrets.NPM_TOKEN }}"
|
||||
run: yarn node ./scripts/release.js --name=bot --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"
|
||||
|
||||
- name: Release @bot-whatsapp/cli
|
||||
run: yarn node ./scripts/release.js --name=cli --version="${{ steps.vars.outputs.tag }}" --token="${{ secrets.NPM_TOKEN }}"
|
||||
run: yarn node ./scripts/release.js --name=cli --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"
|
||||
|
||||
- name: Release @bot-whatsapp/create-bot-whatsapp
|
||||
run: yarn node ./scripts/release.js --name=create-bot-whatsapp --version="${{ steps.vars.outputs.tag }}" --token="${{ secrets.NPM_TOKEN }}"
|
||||
run: yarn node ./scripts/release.js --name=create-bot-whatsapp --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"
|
||||
|
||||
- name: Release @bot-whatsapp/database
|
||||
run: yarn node ./scripts/release.js --name=database --version="${{ steps.vars.outputs.tag }}" --token="${{ secrets.NPM_TOKEN }}"
|
||||
run: yarn node ./scripts/release.js --name=database --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"
|
||||
|
||||
- name: Release @bot-whatsapp/provider
|
||||
run: yarn node ./scripts/release.js --name=provider --version="${{ steps.vars.outputs.tag }}" --token="${{ secrets.NPM_TOKEN }}"
|
||||
run: yarn node ./scripts/release.js --name=provider --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"
|
||||
|
||||
- name: Release @bot-whatsapp/portal
|
||||
run: yarn node ./scripts/release.js --name=portal --version="${{ steps.vars.outputs.tag }}" --token="${{ secrets.NPM_TOKEN }}"
|
||||
run: yarn node ./scripts/release.js --name=portal --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"
|
||||
|
||||
- name: Set CHANGELOG
|
||||
run: yarn release
|
||||
|
||||
- name: Commit Versioning & Push changes
|
||||
uses: stefanzweifel/git-auto-commit-action@v4
|
||||
- name: Commit and push changes
|
||||
uses: devops-infra/action-commit-push@master
|
||||
with:
|
||||
commit_message: 'release(version): 🚀 - "${{ steps.vars.outputs.tag }}" release'
|
||||
branch: dev
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
commit_message: 'release(version): 🚀 - "${{ steps.package-version.outputs.current-version}}" release'
|
||||
|
||||
56
CHANGELOG.md
56
CHANGELOG.md
@@ -2,6 +2,62 @@
|
||||
|
||||
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.8](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.7-pre...v0.1.8) (2023-01-10)
|
||||
|
||||
### [0.1.7](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.7-pre...v0.1.7) (2023-01-10)
|
||||
|
||||
### [0.1.6](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.5...v0.1.6) (2023-01-10)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* :zap: new portal web for qr scan ([cb2e869](https://github.com/leifermendez/bot-whatsapp/commit/cb2e8692a3f94c8b24993cd11dd564f094b0e4ef))
|
||||
* :zap: new portal web for qr scan ([9e93795](https://github.com/leifermendez/bot-whatsapp/commit/9e93795e6fce38890045389da95184fef1fbe0da))
|
||||
* :zap: new portal web for qr scan ([3c178ea](https://github.com/leifermendez/bot-whatsapp/commit/3c178ea113b140535a51f5dcd521dbb66251670e))
|
||||
* :zap: new portal web for qr scan ([1f1f564](https://github.com/leifermendez/bot-whatsapp/commit/1f1f564f4e2e3aa13b84de500fe215e0c45c2770))
|
||||
* :zap: new portal web for qr scan ([3de5f4b](https://github.com/leifermendez/bot-whatsapp/commit/3de5f4b77a10e30632ff7555f5af5d8e93cb2019))
|
||||
* :zap: qr code filename ([d794f60](https://github.com/leifermendez/bot-whatsapp/commit/d794f604ac8a835e523709dbf18c9b1609bbd00e))
|
||||
* :zap: qr portal ([246ecdc](https://github.com/leifermendez/bot-whatsapp/commit/246ecdc11a8c4e652867c842b612dc4ce73f9828))
|
||||
* :zap: qr portal ([af8b401](https://github.com/leifermendez/bot-whatsapp/commit/af8b401d075e1c35065589ede61476461ce86b4d))
|
||||
* agregamos dockerfile y webserver a starters ([f9e3bbc](https://github.com/leifermendez/bot-whatsapp/commit/f9e3bbc6655060408e4fdbe1d7e920c2ed4fca53))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* :zap: add Dockerfile, starter ([4e0d33c](https://github.com/leifermendez/bot-whatsapp/commit/4e0d33c6bb46ad259774f6d0c38c6c0b5f8ca4a9))
|
||||
* :zap: fix inject port args ([20f752e](https://github.com/leifermendez/bot-whatsapp/commit/20f752e6c1b1f7d11948fc4f2f8950f7834df7d9))
|
||||
* :zap: fix inject port args ([7a23eb0](https://github.com/leifermendez/bot-whatsapp/commit/7a23eb0cc6f93ec21c5ab34e46981ae7a93f42ff))
|
||||
* **provider:** :zap: fix send image baileys ([2ddea54](https://github.com/leifermendez/bot-whatsapp/commit/2ddea5468d235035478d4e91e63c821da19da179))
|
||||
* **provider:** :zap: fix send image baileys ([391e11c](https://github.com/leifermendez/bot-whatsapp/commit/391e11ce738cd64792b5237d69f3739b0263c198))
|
||||
* **provider:** :zap: fix send image baileys ([5d10cb9](https://github.com/leifermendez/bot-whatsapp/commit/5d10cb9026da60043e9a2f86117ebb04d0631a3f))
|
||||
* **provider:** fix error docker as root user ([5a033da](https://github.com/leifermendez/bot-whatsapp/commit/5a033da83aee1f614120bccf27c9f330500cc7b0))
|
||||
|
||||
### [0.1.4](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.5...v0.1.4) (2023-01-10)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* :zap: new portal web for qr scan ([cb2e869](https://github.com/leifermendez/bot-whatsapp/commit/cb2e8692a3f94c8b24993cd11dd564f094b0e4ef))
|
||||
* :zap: new portal web for qr scan ([9e93795](https://github.com/leifermendez/bot-whatsapp/commit/9e93795e6fce38890045389da95184fef1fbe0da))
|
||||
* :zap: new portal web for qr scan ([3c178ea](https://github.com/leifermendez/bot-whatsapp/commit/3c178ea113b140535a51f5dcd521dbb66251670e))
|
||||
* :zap: new portal web for qr scan ([1f1f564](https://github.com/leifermendez/bot-whatsapp/commit/1f1f564f4e2e3aa13b84de500fe215e0c45c2770))
|
||||
* :zap: new portal web for qr scan ([3de5f4b](https://github.com/leifermendez/bot-whatsapp/commit/3de5f4b77a10e30632ff7555f5af5d8e93cb2019))
|
||||
* :zap: qr code filename ([d794f60](https://github.com/leifermendez/bot-whatsapp/commit/d794f604ac8a835e523709dbf18c9b1609bbd00e))
|
||||
* :zap: qr portal ([246ecdc](https://github.com/leifermendez/bot-whatsapp/commit/246ecdc11a8c4e652867c842b612dc4ce73f9828))
|
||||
* :zap: qr portal ([af8b401](https://github.com/leifermendez/bot-whatsapp/commit/af8b401d075e1c35065589ede61476461ce86b4d))
|
||||
* agregamos dockerfile y webserver a starters ([f9e3bbc](https://github.com/leifermendez/bot-whatsapp/commit/f9e3bbc6655060408e4fdbe1d7e920c2ed4fca53))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* :zap: add Dockerfile, starter ([4e0d33c](https://github.com/leifermendez/bot-whatsapp/commit/4e0d33c6bb46ad259774f6d0c38c6c0b5f8ca4a9))
|
||||
* :zap: fix inject port args ([20f752e](https://github.com/leifermendez/bot-whatsapp/commit/20f752e6c1b1f7d11948fc4f2f8950f7834df7d9))
|
||||
* :zap: fix inject port args ([7a23eb0](https://github.com/leifermendez/bot-whatsapp/commit/7a23eb0cc6f93ec21c5ab34e46981ae7a93f42ff))
|
||||
* **provider:** :zap: fix send image baileys ([2ddea54](https://github.com/leifermendez/bot-whatsapp/commit/2ddea5468d235035478d4e91e63c821da19da179))
|
||||
* **provider:** :zap: fix send image baileys ([391e11c](https://github.com/leifermendez/bot-whatsapp/commit/391e11ce738cd64792b5237d69f3739b0263c198))
|
||||
* **provider:** :zap: fix send image baileys ([5d10cb9](https://github.com/leifermendez/bot-whatsapp/commit/5d10cb9026da60043e9a2f86117ebb04d0631a3f))
|
||||
* **provider:** fix error docker as root user ([5a033da](https://github.com/leifermendez/bot-whatsapp/commit/5a033da83aee1f614120bccf27c9f330500cc7b0))
|
||||
|
||||
### [0.1.3](https://github.com/leifermendez/bot-whatsapp/compare/v0.1.2...v0.1.3) (2023-01-04)
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bot-whatsapp/root",
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.8",
|
||||
"description": "Bot de wahtsapp open source para MVP o pequeños negocios",
|
||||
"main": "app.js",
|
||||
"private": true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bot-whatsapp/bot",
|
||||
"version": "0.0.45-alpha.0",
|
||||
"version": "0.0.52-alpha.0",
|
||||
"description": "",
|
||||
"main": "./lib/bundle.bot.cjs",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bot-whatsapp/cli",
|
||||
"version": "0.0.52-alpha.0",
|
||||
"version": "0.0.59-alpha.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "create-bot-whatsapp",
|
||||
"version": "0.0.63-alpha.0",
|
||||
"version": "0.0.70-alpha.0",
|
||||
"description": "",
|
||||
"main": "./lib/bundle.create-bot-whatsapp.cjs",
|
||||
"files": [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bot-whatsapp/database",
|
||||
"version": "0.0.44-alpha.0",
|
||||
"version": "0.0.51-alpha.0",
|
||||
"description": "Esto es el conector a mysql, pg, mongo",
|
||||
"main": "./lib/mock/index.cjs",
|
||||
"keywords": [],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Alert from '../../../components/widgets/Alert'
|
||||
import Navigation from '../../../components/widgets/Navigation'
|
||||
|
||||
# Provider (Proveedor)
|
||||
# Proveedores
|
||||
|
||||
<Alert>
|
||||
⚡ Dependiendo del tipo de proveedor que utlices puede que necesites pasar
|
||||
@@ -33,9 +33,15 @@ Los proveedores disponibles hasta el momento son los siguientes:
|
||||
|
||||
---
|
||||
|
||||
### Twilio: Configuración
|
||||
|
||||
Estamos trabajando en el apartado de la documentación lo más claro posible. Puedes encontrar los [detalles aquí](/docs/providers/twilio)
|
||||
|
||||
---
|
||||
|
||||
<Navigation
|
||||
pages={[
|
||||
{ name: 'Conversaciones', link: '/docs/flows' },
|
||||
{ name: 'Conversaciones', link: '/docs/providers' },
|
||||
{ name: 'Base de datos', link: '/docs/database' },
|
||||
]}
|
||||
/>
|
||||
|
||||
3
packages/docs/src/routes/docs/providers/meta/index.mdx
Normal file
3
packages/docs/src/routes/docs/providers/meta/index.mdx
Normal file
@@ -0,0 +1,3 @@
|
||||
# Meta
|
||||
|
||||
...
|
||||
152
packages/docs/src/routes/docs/providers/twilio/index.mdx
Normal file
152
packages/docs/src/routes/docs/providers/twilio/index.mdx
Normal file
@@ -0,0 +1,152 @@
|
||||
import Alert from '../../../../components/widgets/Alert'
|
||||
import Navigation from '../../../../components/widgets/Navigation'
|
||||
|
||||
# Twilio
|
||||
|
||||
Twilio es una plataforma de desarrollo que permite a los desarrolladores construir aplicaciones de comunicación en la nube y sistemas web. Las API de comunicaciones de Twilio permiten a las empresas proporcionar la experiencia de comunicación adecuada para sus clientes dentro de la web y las aplicaciones móviles. Al usar las API de Twilio, los desarrolladores pueden agregar rápidamente esta funcionalidad a una aplicación, como mensajes de voz, videollamadas, mensajes de texto y más.
|
||||
|
||||
<Alert>
|
||||
Twilio te proporciona una cuenta **Sandbox** para que puedas probar
|
||||
gratuitamente el servicio
|
||||
</Alert>
|
||||
|
||||
### Requerimientos
|
||||
|
||||
- Registrar una cuenta de [twilio](https://www.twilio.com/try-twilio)
|
||||
|
||||
---
|
||||
|
||||
### Requerimientos
|
||||
|
||||
Debemos aceptar los términos y condiciones y luego activar la cuenta sandbox
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
Observamos que ahora tenemos un número de WhatsApp y una frase. El número proporcionado es un **número de pruebas** que te ofrece Twilio, luego que actives un plan de pago puedes comprar un número para tu uso.
|
||||
Guarda ese número como un contacto de WhatsApp en tu móvil y después envíale el mensaje que te asignan. En el ejemplo de la pantalla sale **join score-state**
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
Luego Twilio te responde con un mensaje confirmando la verificación de la conexión. **Este paso solo es necesario cuando estás en modo Sandbox.**
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
Ahora dirígete a la sección de Ajustes de WhatsApp ubicada en la consola de Twilio.
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
En esta sección puedes configurar los **Webhook** que conectaran con el chatbot.
|
||||
|
||||
**¿No sabes cuál es tu link?** continúa leyendo esta guía más adelante entenderás
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
También necesitarás el **Account SID y Auth Token** estos datos los consigues [console.twilio.com](https://console.twilio.com).
|
||||
|
||||
**¿Que hago con estos datos?** guardalos o tenlos ubicados porque los necesitaremos en las siguientes pantallas
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
En el **archivo principal** del bot donde estás implementando la función del adaptador de twilio vas a colocar los siguientes datos:
|
||||
|
||||
- **ACC_SID:** Lo encontraras en console.twilio puedes ver la pantalla anterior
|
||||
- **ACC_TOKEN:** Lo encontraras en console.twilio puedes ver la pantalla anterior
|
||||
- **ACC_VENDOR:** Es el numero de whatsapp (si ya tienes el plan de pago de Twilio usa el numero que compraste), si aun estas en modo
|
||||
sandbox utliza el numero proporcionado en el paso numero 2
|
||||
|
||||
<Alert>
|
||||
En el ejemplo de abajo puedes ver como una sugerencia de como puede ser
|
||||
utilizando variables de entorno
|
||||
</Alert>
|
||||
|
||||
```js
|
||||
const main = async () => {
|
||||
const adapterDB = new MockAdapter()
|
||||
const adapterFlow = createFlow([flowPrincipal])
|
||||
|
||||
const adapterProvider = createProvider(TwilioProvider, {
|
||||
accountSid: process.env.ACC_SID, //AC4695aa720b4d700a***************
|
||||
authToken: process.env.ACC_TOKEN, //3f6fae09f7a1c3534***************
|
||||
vendorNumber: process.env.ACC_VENDOR, //+14155238886
|
||||
})
|
||||
|
||||
createBot({
|
||||
flow: adapterFlow,
|
||||
provider: adapterProvider,
|
||||
database: adapterDB,
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Luego de ejecutar el bot encontraras un mensaje en la consola similar al siguiente.
|
||||
Donde podrás encontrar la URL para tu **webhook**
|
||||
|
||||
```shell
|
||||
$ npm start
|
||||
|
||||
> bot-whatsapp-base-twilio-memory@1.0.0 start
|
||||
> node app.js
|
||||
|
||||
|
||||
[Twilio]: Agregar esta url "WHEN A MESSAGE COMES IN"
|
||||
[Twilio]: POST http://localhost:3000/twilio-hook
|
||||
[Twilio]: Más información en la documentacion
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ¿Ahora que hago?
|
||||
|
||||
Podrás observar que el bot inicia un servicio HTTP (endpoint) que debe estar en un servidor en linea para que puedas conectarlo con Twilio.
|
||||
|
||||
---
|
||||
|
||||
### Opción 1:
|
||||
|
||||
Puedes hacer pruebas en local atrevés de un servidor proxy tunnel.
|
||||
Descarga **[ngork](https://ngrok.com/download)** es una herramienta gratuita que nos ayudara con esto.
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
Esto genera una URL en línea que podemos usar en la parte de **WebHook** de Twilio
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
### Opción 2:
|
||||
|
||||
Si ya tienes desplegado tu bot en un servidor tienes que obtener la IP publica o subdominio que te proporcionaron. **Ejemplo** si estas usando
|
||||
[Railway](https://railway.app/) puedes ir a la seccion de ajustes y generar un subdominio. Ya tendriamos el **WebHook**
|
||||
`https://base-twilio-memory-production.up.railway.app/twilio-hook`
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
<Navigation
|
||||
pages={[
|
||||
{ name: 'Proveedores', link: '/docs/providers' },
|
||||
{ name: 'Meta', link: '/docs/providers/meta' },
|
||||
]}
|
||||
/>
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bot-whatsapp/portal",
|
||||
"version": "0.0.3-alpha.0",
|
||||
"version": "0.0.9-alpha.0",
|
||||
"description": "Portal WEB para escanear QR",
|
||||
"main": "./lib/portal.http.cjs",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
const { join } = require('path')
|
||||
const { createReadStream, existsSync } = require('fs')
|
||||
const { bgYellow, cyan } = require('kleur')
|
||||
const { bgYellow, cyan, yellow } = require('kleur')
|
||||
const polka = require('polka')
|
||||
|
||||
const HTTP_PORT = process.env.PORT || 3000
|
||||
const QR_FILE = process.env.QR_FILE ?? 'qr.png'
|
||||
const QR_FILE = process.env.QR_FILE ?? 'bot'
|
||||
const PUBLIC_URL =
|
||||
process.env.PUBLIC_URL ??
|
||||
process.env.RAILWAY_STATIC_URL ??
|
||||
@@ -23,18 +23,33 @@ const start = (args) => {
|
||||
const injectArgs = {
|
||||
port: HTTP_PORT,
|
||||
publicSite: PUBLIC_URL,
|
||||
qrFile: QR_FILE,
|
||||
name: QR_FILE,
|
||||
...args,
|
||||
}
|
||||
const { port, publicSite, qrFile } = injectArgs
|
||||
const { port, publicSite, name } = injectArgs
|
||||
|
||||
const banner = () => {
|
||||
console.log(``)
|
||||
console.log(bgYellow(`🚩 ESCANEAR QR 🚩`))
|
||||
console.log(cyan(`Existen varias maneras de escanear el QR code`))
|
||||
console.log(
|
||||
cyan(`- Tambien puedes visitar `),
|
||||
yellow(`${publicSite}:${port}`)
|
||||
)
|
||||
console.log(
|
||||
cyan(`- Se ha creado un archivo que finaliza `),
|
||||
yellow('qr.png')
|
||||
)
|
||||
console.log(``)
|
||||
}
|
||||
|
||||
polka()
|
||||
.use(serve)
|
||||
.get(qrFile, (_, res) => {
|
||||
.get('qr.png', (_, res) => {
|
||||
const qrSource = [
|
||||
join(process.cwd(), qrFile),
|
||||
join(__dirname, '..', qrFile),
|
||||
join(__dirname, qrFile),
|
||||
join(process.cwd(), `${name}.qr.png`),
|
||||
join(__dirname, '..', `${name}.qr.png`),
|
||||
join(__dirname, `${name}.qr.png`),
|
||||
].find((i) => existsSync(i))
|
||||
|
||||
const qrMark = [
|
||||
@@ -42,17 +57,11 @@ const start = (args) => {
|
||||
join(__dirname, '..', 'dist', 'water-mark.png'),
|
||||
].find((i) => existsSync(i))
|
||||
const fileStream = createReadStream(qrSource ?? qrMark)
|
||||
|
||||
res.writeHead(200, { 'Content-Type': 'image/png' })
|
||||
fileStream.pipe(res)
|
||||
})
|
||||
.listen(port, () => {
|
||||
console.log(``)
|
||||
console.log(bgYellow(`🚩 ESCANEAR QR 🚩`))
|
||||
console.log(cyan(`Existen varias maneras de escanear el QR code`))
|
||||
console.log(cyan(`- Se ha creado un archivo /qr.png`))
|
||||
console.log(cyan(`- Tambien puedes visitar ${publicSite}:${port}`))
|
||||
console.log(``)
|
||||
})
|
||||
.listen(port, () => banner())
|
||||
}
|
||||
|
||||
module.exports = start
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
useStore,
|
||||
useStylesScoped$,
|
||||
} from '@builder.io/qwik'
|
||||
import { useLocation } from '@builder.io/qwik-city'
|
||||
import style from './qr.css?inline'
|
||||
|
||||
export const QR = component$(() => {
|
||||
@@ -19,15 +18,12 @@ export const QR = component$(() => {
|
||||
}, 800)
|
||||
})
|
||||
|
||||
const location = useLocation()
|
||||
const qrImage = location.query?.qr ?? 'qr.png'
|
||||
|
||||
return (
|
||||
<div>
|
||||
<img
|
||||
width={350}
|
||||
height={350}
|
||||
src={qrImage + '?time=' + state.count}
|
||||
src={'qr.png?time=' + state.count}
|
||||
alt="QR"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bot-whatsapp/provider",
|
||||
"version": "0.0.50-alpha.0",
|
||||
"version": "0.0.57-alpha.0",
|
||||
"description": "Esto es el conector a Twilio, Meta, etc...",
|
||||
"main": "./lib/mock/index.cjs",
|
||||
"keywords": [],
|
||||
|
||||
@@ -24,16 +24,13 @@ const logger = new Console({
|
||||
stdout: createWriteStream(`${process.cwd()}/baileys.log`),
|
||||
})
|
||||
|
||||
const NAME_DIR_SESSION = `sessions`
|
||||
const PATH_BASE = join(process.cwd(), NAME_DIR_SESSION)
|
||||
|
||||
/**
|
||||
* ⚙️ 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
|
||||
*/
|
||||
class BaileysProvider extends ProviderClass {
|
||||
globalVendorArgs = { qrFile: 'qr.png' }
|
||||
globalVendorArgs = { name: `bot` }
|
||||
vendor
|
||||
saveCredsGlobal = null
|
||||
constructor(args) {
|
||||
@@ -46,6 +43,7 @@ class BaileysProvider extends ProviderClass {
|
||||
* Iniciar todo Bailey
|
||||
*/
|
||||
initBailey = async () => {
|
||||
const NAME_DIR_SESSION = `${this.globalVendorArgs.name}_sessions`
|
||||
const { state, saveCreds } = await useMultiFileAuthState(
|
||||
NAME_DIR_SESSION
|
||||
)
|
||||
@@ -72,6 +70,7 @@ class BaileysProvider extends ProviderClass {
|
||||
}
|
||||
|
||||
if (statusCode === DisconnectReason.loggedOut) {
|
||||
const PATH_BASE = join(process.cwd(), NAME_DIR_SESSION)
|
||||
rimraf(PATH_BASE, (err) => {
|
||||
if (err) return
|
||||
})
|
||||
@@ -90,12 +89,15 @@ class BaileysProvider extends ProviderClass {
|
||||
if (qr) {
|
||||
this.emit('require_action', {
|
||||
instructions: [
|
||||
`Debes escanear el QR Code para iniciar session reivsa qr.png`,
|
||||
`Debes escanear el QR Code para iniciar ${this.globalVendorArgs.name}.qr.png`,
|
||||
`Recuerda que el QR se actualiza cada minuto `,
|
||||
`Necesitas ayuda: https://link.codigoencasa.com/DISCORD`,
|
||||
],
|
||||
})
|
||||
await baileyGenerateImage(qr, this.globalVendorArgs.qrFile)
|
||||
await baileyGenerateImage(
|
||||
qr,
|
||||
`${this.globalVendorArgs.name}.qr.png`
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ const logger = new Console({
|
||||
* https://github.com/orkestral/venom
|
||||
*/
|
||||
class VenomProvider extends ProviderClass {
|
||||
globalVendorArgs = { qrFile: 'qr.png' }
|
||||
globalVendorArgs = { name: `bot` }
|
||||
vendor
|
||||
constructor(args) {
|
||||
super()
|
||||
@@ -32,15 +32,19 @@ class VenomProvider extends ProviderClass {
|
||||
* Iniciamos el Proveedor Venom
|
||||
*/
|
||||
init = async () => {
|
||||
const NAME_DIR_SESSION = `${this.globalVendorArgs.name}_sessions`
|
||||
try {
|
||||
const client = await venom.create(
|
||||
{
|
||||
session: 'session-base',
|
||||
session: NAME_DIR_SESSION,
|
||||
multidevice: true,
|
||||
disableSpins: true,
|
||||
disableWelcome: true,
|
||||
logger,
|
||||
logQR: false,
|
||||
},
|
||||
(base) => this.generateQr(base),
|
||||
undefined,
|
||||
{ logQR: false }
|
||||
undefined
|
||||
)
|
||||
this.vendor = client
|
||||
} catch (e) {
|
||||
@@ -63,12 +67,12 @@ class VenomProvider extends ProviderClass {
|
||||
console.clear()
|
||||
this.emit('require_action', {
|
||||
instructions: [
|
||||
`Debes escanear el QR Code para iniciar session reivsa qr.png`,
|
||||
`Debes escanear el QR Code para iniciar ${this.globalVendorArgs.name}.qr.png`,
|
||||
`Recuerda que el QR se actualiza cada minuto `,
|
||||
`Necesitas ayuda: https://link.codigoencasa.com/DISCORD`,
|
||||
],
|
||||
})
|
||||
await venomGenerateImage(qr)
|
||||
await venomGenerateImage(qr, `${this.globalVendorArgs.name}.qr.png`)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,13 +19,15 @@ const logger = new Console({
|
||||
* https://github.com/pedroslopez/whatsapp-web.js
|
||||
*/
|
||||
class WebWhatsappProvider extends ProviderClass {
|
||||
globalVendorArgs = { qrFile: 'qr.png' }
|
||||
globalVendorArgs = { name: `bot` }
|
||||
vendor
|
||||
constructor(args) {
|
||||
super()
|
||||
this.globalVendorArgs = { ...this.globalVendorArgs, ...args }
|
||||
this.vendor = new Client({
|
||||
authStrategy: new LocalAuth(),
|
||||
authStrategy: new LocalAuth({
|
||||
clientId: `${this.globalVendorArgs.name}_sessions`,
|
||||
}),
|
||||
puppeteer: {
|
||||
headless: true,
|
||||
args: [
|
||||
@@ -70,12 +72,15 @@ class WebWhatsappProvider extends ProviderClass {
|
||||
func: async (qr) => {
|
||||
this.emit('require_action', {
|
||||
instructions: [
|
||||
`Debes escanear el QR Code para iniciar session reivsa qr.png`,
|
||||
`Debes escanear el QR Code para iniciar ${this.globalVendorArgs.name}.qr.png`,
|
||||
`Recuerda que el QR se actualiza cada minuto `,
|
||||
`Necesitas ayuda: https://link.codigoencasa.com/DISCORD`,
|
||||
],
|
||||
})
|
||||
await wwebGenerateImage(qr)
|
||||
await wwebGenerateImage(
|
||||
qr,
|
||||
`${this.globalVendorArgs.name}.qr.png`
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user