-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatbot.js
130 lines (85 loc) · 5.75 KB
/
chatbot.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
124
125
126
127
128
129
130
// leitor de qr code
const qrcode = require('qrcode-terminal');
const { Client, Buttons, List, MessageMedia } = require('whatsapp-web.js'); // Mudança Buttons
const client = new Client();
// serviço de leitura do qr code
client.on('qr', qr => {
qrcode.generate(qr, {small: true});
});
// apos isso ele diz que foi tudo certo
client.on('ready', () => {
console.log('Tudo certo! WhatsApp conectado.');
});
// E inicializa tudo
client.initialize();
const delay = ms => new Promise(res => setTimeout(res, ms)); // Função que usamos para criar o delay entre uma ação e outra
// Funil
client.on('message', async msg => {
if (msg.body.match(/(menu|Menu|dia|tarde|noite|oi|Oi|Olá|olá|ola|Ola)/i) && msg.from.endsWith('@c.us')) {
const chat = await msg.getChat();
await delay(3000); //delay de 3 segundos
await chat.sendStateTyping(); // Simulando Digitação
await delay(3000); //Delay de 3000 milisegundos mais conhecido como 3 segundos
const contact = await msg.getContact(); //Pegando o contato
const name = contact.pushname; //Pegando o nome do contato
await client.sendMessage(msg.from,'Olá! '+ name.split(" ")[0] + 'Sou o assistente virtual da empresa tal. Como posso ajudá-lo hoje? Por favor, digite uma das opções abaixo:\n\n1 - Como funciona\n2 - Valores dos planos\n3 - Benefícios\n4 - Como aderir\n5 - Outras perguntas'); //Primeira mensagem de texto
await delay(3000); //delay de 3 segundos
await chat.sendStateTyping(); // Simulando Digitação
await delay(5000); //Delay de 5 segundos
}
if (msg.body !== null && msg.body === '1' && msg.from.endsWith('@c.us')) {
const chat = await msg.getChat();
await delay(3000); //delay de 3 segundos
await chat.sendStateTyping(); // Simulando Digitação
await delay(3000);
await client.sendMessage(msg.from, 'Nosso serviço oferece consultas médicas 24 horas por dia, 7 dias por semana, diretamente pelo WhatsApp.\n\nNão há carência, o que significa que você pode começar a usar nossos serviços imediatamente após a adesão.\n\nOferecemos atendimento médico ilimitado, receitas\n\nAlém disso, temos uma ampla gama de benefícios, incluindo acesso a cursos gratuitos');
await delay(3000); //delay de 3 segundos
await chat.sendStateTyping(); // Simulando Digitação
await delay(3000);
await client.sendMessage(msg.from, 'COMO FUNCIONA?\nÉ muito simples.\n\n1º Passo\nFaça seu cadastro e escolha o plano que desejar.\n\n2º Passo\nApós efetuar o pagamento do plano escolhido você já terá acesso a nossa área exclusiva para começar seu atendimento na mesma hora.\n\n3º Passo\nSempre que precisar');
await delay(3000); //delay de 3 segundos
await chat.sendStateTyping(); // Simulando Digitação
await delay(3000);
await client.sendMessage(msg.from, 'Link para cadastro: https://site.com');
}
if (msg.body !== null && msg.body === '2' && msg.from.endsWith('@c.us')) {
const chat = await msg.getChat();
await delay(3000); //Delay de 3000 milisegundos mais conhecido como 3 segundos
await chat.sendStateTyping(); // Simulando Digitação
await delay(3000);
await client.sendMessage(msg.from, '*Plano Individual:* R$22,50 por mês.\n\n*Plano Família:* R$39,90 por mês, inclui você mais 3 dependentes.\n\n*Plano TOP Individual:* R$42,50 por mês, com benefícios adicionais como\n\n*Plano TOP Família:* R$79,90 por mês, inclui você mais 3 dependentes');
await delay(3000); //delay de 3 segundos
await chat.sendStateTyping(); // Simulando Digitação
await delay(3000);
await client.sendMessage(msg.from, 'Link para cadastro: https://site.com');
}
if (msg.body !== null && msg.body === '3' && msg.from.endsWith('@c.us')) {
const chat = await msg.getChat();
await delay(3000); //Delay de 3000 milisegundos mais conhecido como 3 segundos
await chat.sendStateTyping(); // Simulando Digitação
await delay(3000);
await client.sendMessage(msg.from, 'Sorteio de em prêmios todo ano.\n\nAtendimento médico ilimitado 24h por dia.\n\nReceitas de medicamentos');
await delay(3000); //delay de 3 segundos
await chat.sendStateTyping(); // Simulando Digitação
await delay(3000);
await client.sendMessage(msg.from, 'Link para cadastro: https://site.com');
}
if (msg.body !== null && msg.body === '4' && msg.from.endsWith('@c.us')) {
const chat = await msg.getChat();
await delay(3000); //Delay de 3000 milisegundos mais conhecido como 3 segundos
await chat.sendStateTyping(); // Simulando Digitação
await delay(3000);
await client.sendMessage(msg.from, 'Você pode aderir aos nossos planos diretamente pelo nosso site ou pelo WhatsApp.\n\nApós a adesão, você terá acesso imediato');
await delay(3000); //delay de 3 segundos
await chat.sendStateTyping(); // Simulando Digitação
await delay(3000);
await client.sendMessage(msg.from, 'Link para cadastro: https://site.com');
}
if (msg.body !== null && msg.body === '5' && msg.from.endsWith('@c.us')) {
const chat = await msg.getChat();
await delay(3000); //Delay de 3000 milisegundos mais conhecido como 3 segundos
await chat.sendStateTyping(); // Simulando Digitação
await delay(3000);
await client.sendMessage(msg.from, 'Se você tiver outras dúvidas ou precisar de mais informações, por favor, fale aqui nesse whatsapp ou visite nosso site: https://site.com ');
}
});