-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.js
More file actions
76 lines (69 loc) · 2.88 KB
/
Copy pathapi.js
File metadata and controls
76 lines (69 loc) · 2.88 KB
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
const targetDom = document.querySelector('.text');
const getSettingsButton = document.querySelector('#get-settings');
getSettingsButton.addEventListener('click', () => {
const idInstance = document.querySelector('#instance').value;
const token = document.querySelector('#token').value;
const xhr = new XMLHttpRequest();
xhr.open("GET", `https://api.green-api.com/waInstance${idInstance}/getSettings/${token}`);
xhr.send();
xhr.responseType = "json";
xhr.onload = () => {
const data = xhr.response;
console.log(data);
targetDom.innerText = JSON.stringify(data, null, 2);
};
});
const getStateInstanceButton = document.querySelector('#get-state-instance');
getStateInstanceButton.addEventListener('click', () => {
const idInstance = document.querySelector('#instance').value;
const token = document.querySelector('#token').value;
const xhr = new XMLHttpRequest();
xhr.open("GET", `https://api.green-api.com/waInstance${idInstance}/getStateInstance/${token}`);
xhr.send();
xhr.responseType = "json";
xhr.onload = () => {
const data = xhr.response;
console.log(data);
targetDom.innerText = JSON.stringify(data, null, 2);
};
})
const sendMessageButton = document.querySelector('#send-message');
sendMessageButton.addEventListener('click', () => {
const idInstance = document.querySelector('#instance').value;
const token = document.querySelector('#token').value;
const number = document.querySelector('#number_1').value;
const message = document.querySelector('#message').value;
const xhr = new XMLHttpRequest();
xhr.open("POST", `https://api.green-api.com/waInstance${idInstance}/sendMessage/${token}`);
xhr.send(JSON.stringify({
"chatId": `${number}@c.us`,
"message": `${message}`
}));
xhr.responseType = "json";
xhr.onload = () => {
const data = xhr.response;
console.log(data);
targetDom.innerText = JSON.stringify(data, null, 2);
};
});
const sendFileByURLButton = document.querySelector('#send-file-by-url');
sendFileByURLButton.addEventListener('click', () => {
const idInstance = document.querySelector('#instance').value;
const token = document.querySelector('#token').value;
const number = document.querySelector('#number_2').value;
const URL = document.querySelector('#URL').value;
const fileName = document.querySelector('#file-name').value;
const xhr = new XMLHttpRequest();
xhr.open("POST", `https://api.green-api.com/waInstance${idInstance}/sendFileByUrl/${token}`);
xhr.send(JSON.stringify({
"chatId": `${number}@c.us`,
"urlFile": `${URL}`,
"fileName": `${fileName}`
}));
xhr.responseType = "json";
xhr.onload = () => {
const data = xhr.response;
console.log(data);
targetDom.innerText = JSON.stringify(data, null, 2);
};
});