ss/cmd/hook/main.go

114 lines
2.4 KiB
Go
Raw Permalink Normal View History

2024-01-10 18:23:02 +03:00
package main
import (
2024-05-19 20:48:06 +03:00
"surdeus.su/core/ss"
//"surdeus.su/core/ss/urlenc"
//"surdeus.su/core/ss/methods"
"surdeus.su/core/ss/statuses"
"surdeus.su/core/ss/jsons"
2024-01-10 18:23:02 +03:00
"fmt"
//"io"
//"net/url"
//"strconv"
2024-01-10 18:23:02 +03:00
)
2024-01-10 18:23:02 +03:00
type GetNotesOptions struct {
Id int `json:"id"`
Name string `json:"name"`
}
type WebhookRequest struct {
Leads Leads `json:"leads"`
Account Account `json:"account"`
}
type Leads struct {
Status jsons.ArrayMap[Status]`json:"status"`
Add jsons.ArrayMap[Status] `json:"add"`
}
type Status struct {
Id jsons.Int `json:"id"`
StatusId jsons.Int`json:"status_id"`
PipelineId jsons.Int `json:"pipeline_id"`
OldStatusId jsons.Int `json:"old_status_id"`
OldPipelineId jsons.Int `json:"old_pipeline_id"`
}
type Account struct {
Id jsons.Int `json:"id"`
SubDomain string `json:"subdomain"`
}
2024-01-10 18:23:02 +03:00
2024-05-19 20:48:06 +03:00
var root = ss.Root(ss.Path(
nil,
).Case(
2024-01-10 18:23:02 +03:00
"hook",
2024-05-19 20:48:06 +03:00
/*ss.Method().Def(
2024-01-10 18:23:02 +03:00
methods.Post,*/
2024-05-19 20:48:06 +03:00
ss.Func(func(c *ss.Context){
reciever := WebhookRequest{}
c.Scan(&reciever)
if c.ScanErr() != nil {
fmt.Printf("err: %s\n", c.ScanErr())
}
fmt.Printf("%#v\n", reciever)
return
/*fmt.Printf("Content-Type: %q\n", c.ContentType())
2024-01-10 18:23:02 +03:00
body, err := io.ReadAll(c.R.Body)
if err != nil {
fmt.Printf("err:%s\n", err)
return
}
fmt.Printf("rawBody: %q\n", body)
unesc, err := url.QueryUnescape(string(body))
if err != nil {
fmt.Printf("err:%s\n", err)
return
}
fmt.Printf("unescapeBody: %q\n", unesc)
2024-01-10 23:42:39 +03:00
mp := map[string] any{}
2024-05-19 20:48:06 +03:00
err = ss.ParseStr(unesc, mp)
2024-01-10 18:23:02 +03:00
if err != nil {
fmt.Printf("err:%s\n", err)
return
}
2024-01-10 23:42:39 +03:00
js, err := json.MarshalIndent(mp, "", "\t")
if err != nil {
fmt.Printf("err:%s\n", err)
return
}
fmt.Printf("\nparsed: %v\n", string(js))*/
c.SetStatus(statuses.OK)
2024-01-10 18:23:02 +03:00
}),
//),
2024-05-19 20:48:06 +03:00
).Case(
2024-01-18 21:35:58 +03:00
"auth",
2024-05-19 20:48:06 +03:00
ss.Func(func(c *ss.Context){
}),
))
2024-01-10 18:23:02 +03:00
func main() {
/*requestString := "leads[status][0][id]=2050297&" +
"leads[status][0][status_id]=35573056&" +
"leads[status][0][pipeline_id]=3643927&" +
"leads[status][0][old_status_id]=35572897&" +
"leads[status][0][old_pipeline_id]=3643927&" +
"account[id]=29085955&" +
"account[subdomain]=domain"
reciever := WebhookRequest{}
err := urlenc.Unmarshal([]byte(requestString), &reciever)
if err != nil {
panic(err)
}*/
//fmt.Printf("%#v\n", reciever)
2024-05-19 20:48:06 +03:00
srv := ss.Server{
2024-01-10 18:23:02 +03:00
Addr: ":15080",
Handler: root,
}
err := srv.ListenAndServe()
if err != nil {
panic(err)
}
2024-01-10 18:23:02 +03:00
}