-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
40 lines (38 loc) · 1.18 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
package webhook
import (
"encoding/json"
"fmt"
"github.com/aiteung/atapi"
"github.com/aiteung/atmessage"
"github.com/aiteung/module/model"
"github.com/whatsauth/wa"
"github.com/whatsauth/ws"
"net/http"
"os"
)
func Post(w http.ResponseWriter, r *http.Request) {
var WAKeyword = "wh4t5auth0"
var msg model.IteungMessage
var resp atmessage.Response
json.NewDecoder(r.Body).Decode(&msg)
if r.Header.Get("Secret") == os.Getenv("SECRET") {
if ws.IsLoginRequest(msg, WAKeyword) { //untuk whatsauth request login
dt := &ws.WhatsauthRequest{
Uuid: ws.GetUUID(msg, WAKeyword),
Phonenumber: msg.Phone_number,
Delay: msg.From_link_delay,
}
resp, _ = atapi.PostStructWithToken[atmessage.Response]("Token", os.Getenv("TOKEN"), dt, "https://api.wa.my.id/api/whatsauth/request")
} else { //untuk membalas pesan masuk
dt := &wa.TextMessage{
To: msg.Phone_number,
IsGroup: false,
Messages: "Hai hai hai kak " + msg.Alias_name,
}
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)
}