-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendMessage.js
36 lines (33 loc) · 1.01 KB
/
sendMessage.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
import 'dotenv/config'
async function sendMessage(codprod, vlrvenda, contact) {
try {
const response = await fetch('https://graph.facebook.com/v18.0/183582418183115/messages', {
method: 'POST',
headers: {
'Authorization': process.env.TOKEN,
'Content-Type': 'application/json',
'Cookie': 'ps_l=0; ps_n=0'
},
body: JSON.stringify({
"messaging_product": "whatsapp",
"to": contact,
"type": "template",
"template": {
"name": "atualizacao_de_preco",
"language": { "code": "pt_BR" },
"components": [{
"type": "body",
"parameters": [{ "type": "text", "text": codprod }, { "type": "text", "text": vlrvenda }]
}]
}
})
});
if (!response.ok) {
throw new Error('Erro ao executar a solicitação');
}
const data = await response.json();
console.log(data); // Faz algo com os dados recebidos
} catch (error) {
console.error('Houve um erro:', error);
}
}