MCPcopy Create free account
hub / github.com/chanify/chanify / handlePostWebhook

Method handlePostWebhook

core/webhook.go:17–39  ·  view source on GitHub ↗
(ctx *gin.Context)

Source from the content-addressed store, hash-verified

15const coreKey = "_chanify/http/core"
16
17func (c *Core) handlePostWebhook(ctx *gin.Context) {
18 name := strings.ToLower(ctx.Param("name"))
19 webhook, err := c.logic.GetWebhook(name)
20 if err != nil {
21 ctx.JSON(http.StatusNotFound, gin.H{"res": http.StatusNotFound, "msg": "no webhook found"})
22 return
23 }
24 ctx.Set(coreKey, c)
25 if ctx.Request.Body != nil {
26 if body, err := io.ReadAll(ctx.Request.Body); err == nil {
27 ctx.Set(gin.BodyBytesKey, body)
28 }
29 }
30 l := lua.NewState()
31 defer l.Close()
32 initHttpLua(l, ctx)
33 if err := webhook.DoCall(l); err != nil {
34 ctx.JSON(http.StatusBadRequest, gin.H{"res": http.StatusBadRequest, "msg": err.Error()})
35 return
36 }
37 code, ctype, data := getHttpLuaReturn(l)
38 ctx.DataFromReader(code, int64(len(data)), ctype, strings.NewReader(data), map[string]string{})
39}
40
41func initHttpLua(l *lua.LState, ctx *gin.Context) {
42 l.SetField(l.NewTypeMetatable("Request"), "__index", l.SetFuncs(l.NewTable(), luaRequestMethods))

Callers 1

TestWebHookNotFoundFunction · 0.80

Calls 7

initHttpLuaFunction · 0.85
getHttpLuaReturnFunction · 0.85
DoCallMethod · 0.80
JSONMethod · 0.65
CloseMethod · 0.65
DataFromReaderMethod · 0.65
GetWebhookMethod · 0.45

Tested by 1

TestWebHookNotFoundFunction · 0.64