forked from canove/whaileys
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinteractive.ts
More file actions
140 lines (129 loc) · 3.67 KB
/
interactive.ts
File metadata and controls
140 lines (129 loc) · 3.67 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
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
131
132
133
134
135
136
137
138
139
140
import {
makeWASocket,
DisconnectReason,
useMultiFileAuthState,
proto
} from "../src";
const startSock = async () => {
const { state, saveCreds } = await useMultiFileAuthState("baileys_auth_info");
const sock = makeWASocket({
auth: state,
printQRInTerminal: true
});
sock.ev.on("connection.update", async (update) => {
const { connection, lastDisconnect } = update;
if (connection === "close") {
const shouldReconnect =
(lastDisconnect?.error as any)?.output?.statusCode !==
DisconnectReason.loggedOut;
console.log(
"connection closed due to ",
lastDisconnect?.error,
", reconnecting ",
shouldReconnect
);
// reconnect if not logged out
if (shouldReconnect) {
startSock();
}
} else if (connection === "open") {
console.log("opened connection");
const jid = "1234567890@s.whatsapp.net"; // Substitua pelo JID de destino
// 1. Botões Simples
await sock.sendMessage(jid, {
text: "Escolha uma opção:",
footer: "Whaileys",
buttons: [
{ buttonId: "btn1", buttonText: { displayText: "Opção 1" } },
{ buttonId: "btn2", buttonText: { displayText: "Opção 2" } }
],
headerType: 1
});
// 2. Botões de Template
await sock.sendMessage(jid, {
text: "Template Buttons:",
footer: "Whaileys",
templateButtons: [
{
index: 1,
urlButton: {
displayText: "Visite o site",
url: "https://github.com/alltomatos/whaileys"
}
},
{
index: 2,
callButton: {
displayText: "Ligar",
phoneNumber: "+5511999999999"
}
},
{
index: 3,
quickReplyButton: {
displayText: "Resposta Rápida",
id: "quick_reply_1"
}
}
]
});
// 3. List Message
await sock.sendMessage(jid, {
text: "Selecione um item da lista:",
footer: "Whaileys",
title: "Menu Principal",
buttonText: "Ver Menu",
sections: [
{
title: "Seção 1",
rows: [
{ title: "Opção A", rowId: "opt_a", description: "Descrição A" },
{ title: "Opção B", rowId: "opt_b", description: "Descrição B" }
]
},
{
title: "Seção 2",
rows: [
{ title: "Opção C", rowId: "opt_c" }
]
}
]
});
// 4. Interactive Message (Native Flow)
// Este formato é mais complexo e requer construção manual do proto
const msg: proto.Message.IInteractiveMessage = {
body: { text: "Mensagem Interativa Nativa" },
footer: { text: "Whaileys" },
header: {
title: "Cabeçalho",
subtitle: "Subtítulo",
hasMediaAttachment: false
},
nativeFlowMessage: {
buttons: [
{
name: "quick_reply",
buttonParamsJson: JSON.stringify({
display_text: "Botão Nativo 1",
id: "native_btn_1"
})
},
{
name: "cta_url",
buttonParamsJson: JSON.stringify({
display_text: "Abrir Link",
url: "https://google.com",
merchant_url: "https://google.com"
})
}
]
}
};
await sock.sendMessage(jid, {
interactiveMessage: msg
});
}
});
sock.ev.on("creds.update", saveCreds);
};
startSock();