func CreateWebhook(w http.ResponseWriter, req *http.Request) {
	var input inputWebhookType
	err := httputils.DecodeBody(w, req.Body, &input)
	if err != nil {
		httputils.ErrorOut(w, http.StatusBadRequest, errIncorrectBody.Error())
		return
	}

	// @TODO check webhook input, and configs

	h, err := hash.NewFromHash(mux.Vars(req)["addr"])
	if err != nil {
		httputils.ErrorOut(w, http.StatusNotFound, accountNotFound)
		return
	}

	logrus.Debug(input.Config)

	var cfg interface{}
	err = json.Unmarshal([]byte(input.Config), &cfg)
	if err != nil {
		httputils.ErrorOut(w, http.StatusBadRequest, errIncorrectBody.Error())
		return
	}

	logrus.Debug(cfg)

	wh, err := webhook.NewWebhook(*h, input.Event, input.Type, cfg)
	if err != nil {
		httputils.ErrorOut(w, http.StatusBadRequest, errIncorrectBody.Error())
		return
	}

	// Store webhook into persistent storage
	repo := container.Instance.GetWebhookRepo()
	err = repo.Store(*wh)
	if err != nil {
		msg := fmt.Sprintf("error while storing webhook: %s", err)
		httputils.ErrorOut(w, http.StatusInternalServerError, msg)
		return
	}

	_ = dispatcher.DispatchWebhookCreate(wh.Account, *wh)

	// Output webhook
	_ = httputils.JSONOut(w, http.StatusCreated, wh)
}
// CreateWebhook is a handler that will create a new webhook
CreateWebhook is a handler that will create a new webhook
// CreateWebhook is a handler that will create a new webhook
func CreateWebhook(w http.ResponseWriter, req *http.Request) {
	var input inputWebhookType
	err := httputils.DecodeBody(w, req.Body, &input)
	if err != nil {
		httputils.ErrorOut(w, http.StatusBadRequest, errIncorrectBody.Error())
		return
	}
	h, err := hash.NewFromHash(mux.Vars(req)["addr"])
	if err != nil {
		httputils.ErrorOut(w, http.StatusNotFound, accountNotFound)
		return
	}
	logrus.Debug(input.Config)
	var cfg interface{}
	err = json.Unmarshal([]byte(input.Config), &cfg)
	if err != nil {
		httputils.ErrorOut(w, http.StatusBadRequest, errIncorrectBody.Error())
		return
	}
	logrus.Debug(cfg)
	wh, err := webhook.NewWebhook(*h, input.Event, input.Type, cfg)
	if err != nil {
		httputils.ErrorOut(w, http.StatusBadRequest, errIncorrectBody.Error())
		return
	}
	repo := container.Instance.GetWebhookRepo()
	err = repo.Store(*wh)
	if err != nil {
		msg := fmt.Sprintf("error while storing webhook: %s", err)
		httputils.ErrorOut(w, http.StatusInternalServerError, msg)
		return
	}
	_ = dispatcher.DispatchWebhookCreate(wh.Account, *wh)
	_ = httputils.JSONOut(w, http.StatusCreated, wh)
}
func CreateWebhook ( w http . ResponseWriter , req * http . Request ) { var input inputWebhookType err := httputils . DecodeBody ( w , req . Body , & input ) if err != nil { httputils . ErrorOut ( w , http . StatusBadRequest , errIncorrectBody . Error ( ) ) return } h , err := hash . NewFromHash ( mux . Vars ( req ) [ " " ] ) if err != nil { httputils . ErrorOut ( w , http . StatusNotFound , accountNotFound ) return } logrus . Debug ( input . Config ) var cfg interface { } err = json . Unmarshal ( [ ] byte ( input . Config ) , & cfg ) if err != nil { httputils . ErrorOut ( w , http . StatusBadRequest , errIncorrectBody . Error ( ) ) return } logrus . Debug ( cfg ) wh , err := webhook . NewWebhook ( * h , input . Event , input . Type , cfg ) if err != nil { httputils . ErrorOut ( w , http . StatusBadRequest , errIncorrectBody . Error ( ) ) return } repo := container . Instance . GetWebhookRepo ( ) err = repo . Store ( * wh ) if err != nil { msg := fmt . Sprintf ( " " , err ) httputils . ErrorOut ( w , http . StatusInternalServerError , msg ) return } _ = dispatcher . DispatchWebhookCreate ( wh . Account , * wh ) _ = httputils . JSONOut ( w , http . StatusCreated , wh ) }
CreateWebhook is a handler that will create a new webhook
CreateWebhook is a handler that will create a new webhook
// @TODO check webhook input, and configs // Store webhook into persistent storage // Output webhook