MCPcopy
hub / github.com/the-open-agent/openagent / ChatWebhookVerify

Method ChatWebhookVerify

controllers/pipe_webhook.go:55–95  ·  view source on GitHub ↗

ChatWebhookVerify handles the HTTP GET challenge that some platforms (e.g. WhatsApp Cloud API) send to verify webhook ownership before they start delivering events. The URL format is: /api/chat-webhook/:pipeType/:pipeName This endpoint does not require authentication. @router /api/chat-webhook/:pipe

()

Source from the content-addressed store, hash-verified

53// This endpoint does not require authentication.
54// @router /api/chat-webhook/:pipeType/:pipeName [get]
55func (c *ApiController) ChatWebhookVerify() {
56 pipeType := c.Ctx.Input.Param(":pipeType")
57 pipeName := c.Ctx.Input.Param(":pipeName")
58
59 pipeObj, err := object.GetPipeByName("admin", pipeName)
60 if err != nil {
61 c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
62 return
63 }
64 if pipeObj == nil || pipepkg.NormalizeType(pipeObj.Type) != pipeType {
65 c.Ctx.ResponseWriter.WriteHeader(http.StatusNotFound)
66 return
67 }
68
69 provider, err := pipeObj.GetProvider(c.GetAcceptLanguage())
70 if err != nil {
71 c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
72 return
73 }
74
75 verifier, ok := provider.(pipepkg.WebhookVerifier)
76 if !ok {
77 c.Ctx.ResponseWriter.WriteHeader(http.StatusMethodNotAllowed)
78 return
79 }
80
81 params := map[string]string{}
82 for key, values := range c.Ctx.Request.URL.Query() {
83 if len(values) > 0 {
84 params[key] = values[0]
85 }
86 }
87
88 response, err := verifier.VerifyWebhook(params)
89 if err != nil {
90 c.Ctx.ResponseWriter.WriteHeader(http.StatusBadRequest)
91 return
92 }
93
94 writePipeWebhookResponse(c, response)
95}
96
97// ChatWebhook receives incoming updates from a chat pipe.
98// The URL format is: /api/chat-webhook/:pipeType/:pipeName

Callers

nothing calls this directly

Calls 7

GetAcceptLanguageMethod · 0.95
GetPipeByNameFunction · 0.92
writePipeWebhookResponseFunction · 0.85
QueryMethod · 0.65
VerifyWebhookMethod · 0.65
WriteHeaderMethod · 0.45
GetProviderMethod · 0.45

Tested by

no test coverage detected