48 lines
1,010 B
Go
48 lines
1,010 B
Go
package webhooks
|
|
|
|
import (
|
|
"vultras.su/core/bond/urlenc"
|
|
"vultras.su/core/bond/jsons"
|
|
"log"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
type Request struct {
|
|
Leads Leads `schema:"leads"`
|
|
Account Account `schema:"account"`
|
|
}
|
|
|
|
type Leads struct {
|
|
Status jsons.ArrayMap[Status] `schema:"status"`
|
|
Add jsons.ArrayMap[Status] `schema:"add"`
|
|
}
|
|
|
|
type Status struct {
|
|
Id jsons.Int `schema:"id"`
|
|
StatusId jsons.Int `schema:"status_id"`
|
|
PipelineId jsons.Int `schema:"pipeline_id"`
|
|
OldStatusId jsons.Int `schema:"old_status_id"`
|
|
OldPipelineId jsons.Int `schema:"old_pipeline_id"`
|
|
}
|
|
|
|
type Account struct {
|
|
Id jsons.Int `schema:"id"`
|
|
SubDomain string `schema:"subdomain"`
|
|
}
|
|
|
|
func NewFromString(body string) (*WebhookRequest, error) {
|
|
ret := &WebhookRequest{}
|
|
err := urlenc.Unmarsal(ret)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ret, nil
|
|
}
|
|
|
|
func (hook *WebhookRequest) GetLeadId() string {
|
|
if hook.Leads.Status != nil {
|
|
return hook.Leads.Status[0].Id
|
|
}
|
|
return hook.Leads.Add[0].Id
|
|
}
|