-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathvgram.v
38 lines (34 loc) · 986 Bytes
/
vgram.v
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
module vgram
import net.http
import time
import json
pub struct Bot {
pub:
token string
endpoint string = "https://api.telegram.org/bot"
}
pub fn new_bot(utoken string) Bot {
return Bot{
token: utoken
}
}
fn (d Bot) http_request(method string, _data string) string {
result := http.post_json("${d.endpoint}${d.token}/${method}", _data) or {
println("Unable to do request")
return ""
}
if result.status_code == 200 {
xtgresp := json.decode(ResponserOK, result.body) or {
println("Failed to decode json")
return ""
}
return xtgresp.result
} else {
xtgresp := json.decode(ResponserNotOK, result.body) or {
println("Failed to decode json")
return ""
}
println("\n\nError!\nMethod: ${method}\nTime: " + time.now().str() + "\nError code: " + xtgresp.error_code.str() + "\nDescription: " + xtgresp.description)
return ""
}
}