-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
105 lines (92 loc) · 3.37 KB
/
handler.go
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
package webhook
import (
"encoding/json"
"fmt"
"net/http"
"os"
"strconv"
"github.com/aiteung/atapi"
"github.com/aiteung/atmessage"
"github.com/aiteung/module/model"
"github.com/whatsauth/wa"
)
func PostBalasan(w http.ResponseWriter, r *http.Request) {
var msg model.IteungMessage
var resp atmessage.Response
json.NewDecoder(r.Body).Decode(&msg)
link := "https://medium.com/@adrianbimo43/whatsauth-free-2fa-otp-notif-whatsapp-gateway-api-gratis-9df4d66360d5" + " dan " + "#"
if r.Header.Get("Secret") == os.Getenv("SECRET") {
if msg.Message == "loc" || msg.Message == "Loc" || msg.Message == "lokasi" || msg.LiveLoc {
location, err := ReverseGeocode(msg.Latitude, msg.Longitude)
if err != nil {
// Handle the error (e.g., log it) and set a default location name
location = "Unknown Location"
}
reply := fmt.Sprintf("Hai hai haiii kamu pasti lagi di %s \n Koordinatenya : %s - %s\n Cara Penggunaan WhatsAuth Ada di link dibawah ini"+
"yaa kak %s\n", location,
strconv.Itoa(int(msg.Longitude)), strconv.Itoa(int(msg.Latitude)), link)
dt := &wa.TextMessage{
To: msg.Phone_number,
IsGroup: false,
Messages: reply,
}
resp, _ = atapi.PostStructWithToken[atmessage.Response]("Token", os.Getenv("TOKEN"), dt, "https://api.wa.my.id/api/send/message/text")
} else {
dt := &wa.TextMessage{
To: msg.Phone_number,
IsGroup: false,
Messages: "Hai Hai Haiii kamuuuui " + msg.Alias_name + "\nAdrian lagi gaadaa \n aku Adrian salam kenall yaaaa \n Cara penggunaan WhatsAuth ada di link berikut ini ya kak...\n" + link,
}
resp, _ = atapi.PostStructWithToken[atmessage.Response]("Token", os.Getenv("TOKEN"), dt, "https://api.wa.my.id/api/send/message/text")
}
} else {
resp.Response = "Secret Salah"
}
fmt.Fprintf(w, resp.Response)
}
func ReverseGeocode(latitude, longitude float64) (string, error) {
// OSM Nominatim API endpoint
apiURL := fmt.Sprintf("https://nominatim.openstreetmap.org/reverse?format=json&lat=%f&lon=%f", latitude, longitude)
// Make a GET request to the API
resp, err := http.Get(apiURL)
if err != nil {
return "", err
}
defer resp.Body.Close()
// Decode the response
var result map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&result)
if err != nil {
return "", err
}
// Extract the place name from the response
displayName, ok := result["display_name"].(string)
if !ok {
return "", fmt.Errorf("unable to extract display_name from the API response")
}
return displayName, nil
}
func Liveloc(w http.ResponseWriter, r *http.Request) {
var msg model.IteungMessage
var resp atmessage.Response
json.NewDecoder(r.Body).Decode(&msg)
// Reverse geocode to get the place name
location, err := ReverseGeocode(msg.Latitude, msg.Longitude)
if err != nil {
// Handle the error (e.g., log it) and set a default location name
location = "Unknown Location"
}
reply := fmt.Sprintf("Hai hai haiii kamu pasti lagi di %s \n Koordinatenya : %s - %s\n", location,
strconv.Itoa(int(msg.Longitude)), strconv.Itoa(int(msg.Latitude)))
if r.Header.Get("Secret") == os.Getenv("SECRET") {
dt := &wa.TextMessage{
To: msg.Phone_number,
IsGroup: false,
Messages: reply,
}
resp, _ = atapi.PostStructWithToken[atmessage.Response]("Token", os.Getenv("TOKEN"), dt, "https://cloud.wa.my.id/api/send/message/text")
} else {
resp.Response = "Secret Salah"
}
fmt.Fprintf(w, resp.Response)
}