get-trigger.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * @node get-trigger
  3. * @name GET Trigger
  4. * @category triggers
  5. * @version 1.0.0
  6. * @description Triggers workflow on HTTP GET request to webhook endpoint
  7. * @trigger
  8. * @icon globe
  9. */
  10. const configSchema = {
  11. type: 'object',
  12. properties: {
  13. path: {
  14. type: 'string',
  15. title: 'Path Filter',
  16. description: 'Optional path suffix to match (e.g., /status). Leave empty to match any path.',
  17. default: ''
  18. },
  19. requireAuth: {
  20. type: 'boolean',
  21. title: 'Require Authentication',
  22. description: 'Require API key in request header',
  23. default: false
  24. },
  25. apiKeyHeader: {
  26. type: 'string',
  27. title: 'API Key Header',
  28. description: 'Header name containing the API key',
  29. default: 'X-API-Key',
  30. 'x-if': 'requireAuth'
  31. },
  32. apiKey: {
  33. type: 'string',
  34. title: 'API Key',
  35. description: 'Expected API key value',
  36. format: 'password',
  37. 'x-if': 'requireAuth'
  38. }
  39. }
  40. };
  41. const inputSchema = {
  42. type: 'object',
  43. properties: {}
  44. };
  45. const outputSchema = {
  46. type: 'object',
  47. properties: {
  48. method: {
  49. type: 'string',
  50. description: 'HTTP method (GET)'
  51. },
  52. path: {
  53. type: 'string',
  54. description: 'Request path after /webhook/{workflow_id}'
  55. },
  56. query: {
  57. type: 'object',
  58. description: 'Query parameters as key-value pairs'
  59. },
  60. headers: {
  61. type: 'object',
  62. description: 'Request headers as key-value pairs'
  63. },
  64. timestamp: {
  65. type: 'number',
  66. description: 'Unix timestamp when request was received'
  67. },
  68. clientIp: {
  69. type: 'string',
  70. description: 'Client IP address'
  71. }
  72. }
  73. };
  74. async function execute(config, input, context) {
  75. smartbotic.log.info('GET trigger activated');
  76. // The trigger data comes from the webhook controller
  77. const triggerData = context.triggerData || {};
  78. return {
  79. method: triggerData.method || 'GET',
  80. path: triggerData.path || '',
  81. query: triggerData.query || {},
  82. headers: triggerData.headers || {},
  83. timestamp: Date.now(),
  84. clientIp: triggerData.clientIp || ''
  85. };
  86. }
  87. module.exports = { configSchema, inputSchema, outputSchema, execute };