webhook.go 849 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package service
  2. import (
  3. "bytes"
  4. "github.com/gin-gonic/gin"
  5. "github.com/langgenius/dify-plugin-daemon/internal/core/plugin_manager"
  6. "github.com/langgenius/dify-plugin-daemon/internal/core/session_manager"
  7. "github.com/langgenius/dify-plugin-daemon/internal/types/models"
  8. )
  9. func Webhook(ctx *gin.Context, webhook *models.Webhook, path string) {
  10. req := ctx.Request
  11. var buffer bytes.Buffer
  12. err := req.Write(&buffer)
  13. if err != nil {
  14. ctx.JSON(500, gin.H{"error": err.Error()})
  15. }
  16. // fetch plugin
  17. manager := plugin_manager.GetGlobalPluginManager()
  18. runtime := manager.Get(webhook.PluginID)
  19. if runtime == nil {
  20. ctx.JSON(404, gin.H{"error": "plugin not found"})
  21. return
  22. }
  23. session := session_manager.NewSession(webhook.TenantID, "", webhook.PluginID)
  24. defer session.Close()
  25. session.BindRuntime(runtime)
  26. // TODO: handle webhook
  27. }