-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
patch.js
48 lines (45 loc) · 1.33 KB
/
patch.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
module.exports = function (client) {
/**
* Sends message to unknown number
* @param {string} id
* @param {string} message
*/
client.sendMessageToId = async function (id, message) {
return client.getPage().evaluate(
async ({ id, message }) => {
try {
var contact = await Store.WapQuery.queryExist(id)
if (contact.status === 404) {
return true
} else {
try {
var chat = await Store.Chat.find(contact.jid)
await chat.sendMessage(message)
return true
} catch (error) {
if (WAPI.sendMessage(id, message)) {
return true
} else {
return false
}
}
}
} catch (e) {
if (window.Store.Chat.length === 0) return false
var firstChat = Store.Chat.models[0]
var originalID = firstChat.id
firstChat.id =
typeof originalID === 'string'
? id
: new window.Store.UserConstructor(id, {
intentionallyUsePrivateConstructor: true
})
await firstChat.sendMessage(message)
firstChat.id = originalID
return true
}
},
{ id, message }
)
}
}