-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhatsapp.js
123 lines (106 loc) · 3.54 KB
/
whatsapp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
const WhatsAppWeb = require('baileys')
const fs = require('fs')
// const request = require('request')
const { numberWhatsApp } = require('./modules/numberWhatsApp');
const image = require('./modules/image-download')
const client = new WhatsAppWeb()
client.autoReconnect = true // auto reconnect on disconnect
// const numero = JSON.parse(fs.readFileSync("numero.json"))
// const cellphone = numberWhatsApp(numero.phone)
module.exports.phoneStatus = async (req, res) => {
console.log("Verificando numero en WhatsApp\n")
client.getStatus(cellphone)
.then(
([a, b]) => {
console.log("\neste es su estado: ", a.status)
})
.catch(err => console.log(err))
client.getProfilePicture(cellphone)
.then(
([a, b]) => {
if (a.eurl != null) {
const fileUrl = a.eurl
image.imageDownload(fileUrl)
}
else {
console.log("\nel contacto de whatsapp no tiene foto: ", a)
}
})
.catch(err => console.log(err))
client.requestPresenceUpdate(cellphone)
.then(
() => {
}
)
return res
}
const createCsWriter = require('csv-writer').createObjectCsvWriter;
// const { startKeepAliveRequest } = require('baileys/WhatsAppWeb.Session');
const datosWhats = []
module.exports.createCSV = async () => {
const csvWriter = createCsWriter({
path: 'tieneWhats.csv',
header: [
{ id: 'phone', title: 'Celular' },
{ id: 'isonWhats', title: 'Tiene Whatsapp' }
]
})
csvWriter.writeRecords(datosWhats)
.then(() => console.log("Csv creado"))
}
module.exports.findPhone = async (req, res) => {
cellphone = req
const datosWhats = []
res = await client.isOnWhatsApp(cellphone)
.then(
([status, phone]) => {
datosWhats.push({ phone: phone, isonWhats: status })
return datosWhats
}
)
.catch(
err =>
console.log('No se puede encontrar el telefono: ',err)
)
return res
}
module.exports.connectAPI = async (req, res) => {
const AUTH = req
res = {}
a = await client.connectSlim(AUTH, null)
.then(
b => {
console.log('Hola : ', b.name)
return b
}
)
.catch(err => console.log("Desconectado Inesperadamente: " + err))
if (req == null) {
b = client.base64EncodedAuthInfo()
res['KEY'] = b
}
res['ID'] = a
return res
}
module.exports.enviarMensaje = async (req, res) => {
cellphone = req.phone
text = req.text
client.sendTextMessage(cellphone, text)
.then(a => console.log(a))
.catch(err => console.log("error con el numero para enviar: " + err))
}
const buffer = fs.readFileSync("media/2.mp4")
module.exports.enviarImagen = async (req, res) => {
const cellphone = req.phone
// const buffer = req.buffMedia
const options = { gif: false, caption: "*Video 1:*\nNombre del video que hace tal cosa" }
// mediaType=req.media
client.sendMediaMessage(cellphone, buffer, WhatsAppWeb.MessageType.video, options)
.then(([a, b]) => {
console.log("\nnum: ", b[2][0][2].key.remoteJid, " Estado: ", a.status)
}
// ,(rejected)=>console.log("rechazada : ",rejected)
)
.catch(err => console.log("error en el envio del video: " + err))
// .then ( res.jsonp({mensaje:"enviado"}))
}