2024-01-10 18:23:02 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"vultras.su/core/bond"
|
2024-01-14 20:52:35 +03:00
|
|
|
//"vultras.su/core/bond/urlenc"
|
2024-01-10 22:42:50 +03:00
|
|
|
//"vultras.su/core/bond/methods"
|
|
|
|
"vultras.su/core/bond/statuses"
|
2024-01-14 20:52:35 +03:00
|
|
|
"vultras.su/core/bond/jsons"
|
2024-01-10 18:23:02 +03:00
|
|
|
"fmt"
|
2024-01-14 16:25:28 +03:00
|
|
|
//"io"
|
|
|
|
//"net/url"
|
2024-01-14 20:52:35 +03:00
|
|
|
//"strconv"
|
2024-01-10 18:23:02 +03:00
|
|
|
)
|
|
|
|
|
2024-01-14 16:25:28 +03:00
|
|
|
|
2024-01-10 18:23:02 +03:00
|
|
|
type GetNotesOptions struct {
|
|
|
|
Id int `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
}
|
2024-01-14 16:25:28 +03:00
|
|
|
type WebhookRequest struct {
|
|
|
|
Leads Leads `json:"leads"`
|
|
|
|
Account Account `json:"account"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Leads struct {
|
2024-01-14 20:52:35 +03:00
|
|
|
Status jsons.ArrayMap[Status]`json:"status"`
|
|
|
|
Add jsons.ArrayMap[Status] `json:"add"`
|
2024-01-14 16:25:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type Status struct {
|
2024-01-14 20:52:35 +03:00
|
|
|
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"`
|
2024-01-14 16:25:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type Account struct {
|
2024-01-14 20:52:35 +03:00
|
|
|
Id jsons.Int `json:"id"`
|
2024-01-14 16:25:28 +03:00
|
|
|
SubDomain string `json:"subdomain"`
|
|
|
|
}
|
2024-01-10 18:23:02 +03:00
|
|
|
|
2024-01-10 20:11:02 +03:00
|
|
|
var root = bond.Root(bond.Path().
|
2024-01-10 22:42:50 +03:00
|
|
|
Def(
|
2024-01-10 18:23:02 +03:00
|
|
|
"hook",
|
|
|
|
/*bond.Method().Def(
|
|
|
|
methods.Post,*/
|
|
|
|
bond.Func(func(c *bond.Context){
|
2024-01-14 16:25:28 +03:00
|
|
|
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
|
|
|
|
}
|
2024-01-10 22:42:50 +03:00
|
|
|
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{}
|
|
|
|
err = bond.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
|
|
|
|
}
|
2024-01-14 16:25:28 +03:00
|
|
|
fmt.Printf("\nparsed: %v\n", string(js))*/
|
2024-01-10 22:42:50 +03:00
|
|
|
c.SetStatus(statuses.OK)
|
2024-01-10 18:23:02 +03:00
|
|
|
}),
|
|
|
|
//),
|
2024-01-18 21:35:58 +03:00
|
|
|
).Def(
|
|
|
|
"auth",
|
|
|
|
bond.Func(func(c *bond.Context){
|
|
|
|
})
|
2024-01-10 20:11:02 +03:00
|
|
|
))
|
2024-01-10 18:23:02 +03:00
|
|
|
|
|
|
|
func main() {
|
2024-01-14 20:52:35 +03:00
|
|
|
/*requestString := "leads[status][0][id]=2050297&" +
|
2024-01-14 16:25:28 +03:00
|
|
|
"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)
|
2024-01-14 20:52:35 +03:00
|
|
|
}*/
|
|
|
|
//fmt.Printf("%#v\n", reciever)
|
|
|
|
srv := bond.Server{
|
2024-01-10 18:23:02 +03:00
|
|
|
Addr: ":15080",
|
|
|
|
Handler: root,
|
|
|
|
}
|
|
|
|
err := srv.ListenAndServe()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
2024-01-14 20:52:35 +03:00
|
|
|
}
|
2024-01-10 18:23:02 +03:00
|
|
|
}
|