webhook.go 773 B

123456789101112131415161718192021222324252627282930313233
  1. package server
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. )
  6. // DifyPlugin supports register and use webhook to improve the plugin's functionality
  7. // you can use it to do some magic things, look forward to your imagination Ciallo~(∠·ω< )⌒
  8. // - Yeuoly
  9. // WebhookHandler is a function type that can be used to handle webhook requests
  10. type WebhookHandler func(hook_id string, path string)
  11. func (app *App) Webhook() func(c *gin.Context) {
  12. return func(c *gin.Context) {
  13. hook_id := c.Param("hook_id")
  14. path := c.Param("path")
  15. if app.webhook_handler != nil {
  16. app.webhook_handler(hook_id, path)
  17. } else {
  18. app.WebhookHandler(hook_id, path)
  19. }
  20. }
  21. }
  22. func (app *App) WebhookHandler(hook_id string, path string) {
  23. fmt.Println(hook_id)
  24. fmt.Println(path)
  25. }