-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (35 loc) · 812 Bytes
/
main.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
package main
import (
"io/ioutil"
"log"
"net/http"
"vkBot/cache"
"vkBot/cache/domain"
)
func messageRouterHandler(w http.ResponseWriter, r *http.Request) {
b, readErr := ioutil.ReadAll(r.Body)
if readErr != nil {
log.Panic("Error while reading response: ", readErr)
}
msg := &domain.Message{}
unmarshalErr := msg.UnmarshalJSON(b)
if unmarshalErr != nil {
log.Panic("Error while unmarshal response: ", unmarshalErr)
}
if msg.Type == domain.MessageNew {
state := cache.GetDialogState(msg.AuthorId)
ctx := cache.DialogContext{
InputMessage: msg,
CurrentState: state,
}
ctx.Reply()
}
_, _ = w.Write([]byte("ok"))
}
func main() {
http.HandleFunc("/", messageRouterHandler)
err := http.ListenAndServe(":4444", nil)
if err != nil {
log.Fatal("Listen and Serve: ", err)
}
}