Skip to content

Commit e12da02

Browse files
tt
1 parent ba0ad54 commit e12da02

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/session/alerts.lua

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
-- Aceita o alerta (clica em "OK")
2+
PublicSession.accept_alert = function(public, private)
3+
local result = private.fetch({
4+
url = private.url .. "/session/" .. private.session_id .. "/alert/accept",
5+
method = "POST",
6+
http_version = "1.1"
7+
})
8+
if result.status_code ~= 200 then
9+
error("Failed to accept alert: " .. result.read_body())
10+
end
11+
end
12+
13+
-- Rejeita o alerta (clica em "Cancelar")
14+
PublicSession.dismiss_alert = function(public, private)
15+
local result = private.fetch({
16+
url = private.url .. "/session/" .. private.session_id .. "/alert/dismiss",
17+
method = "POST",
18+
http_version = "1.1"
19+
})
20+
if result.status_code ~= 200 then
21+
error("Failed to dismiss alert: " .. result.read_body())
22+
end
23+
end
24+
25+
-- Lê o texto do alerta
26+
PublicSession.get_alert_text = function(public, private)
27+
local result = private.fetch({
28+
url = private.url .. "/session/" .. private.session_id .. "/alert/text",
29+
method = "GET",
30+
http_version = "1.1"
31+
})
32+
if result.status_code ~= 200 then
33+
error("Failed to get alert text: " .. result.read_body())
34+
end
35+
return result.read_body_json()["value"]
36+
end
37+
38+
-- Envia texto para um prompt (somente se for um `prompt()`)
39+
PublicSession.send_alert_text = function(public, private, text)
40+
if type(text) ~= "string" then
41+
error("Text must be a string")
42+
end
43+
44+
local result = private.fetch({
45+
url = private.url .. "/session/" .. private.session_id .. "/alert/text",
46+
method = "POST",
47+
http_version = "1.1",
48+
body = {
49+
text = text
50+
}
51+
})
52+
if result.status_code ~= 200 then
53+
error("Failed to send alert text: " .. result.read_body())
54+
end
55+
end

0 commit comments

Comments
 (0)