stakwork / sphinx-tribes

Backend for sphinx tribes and bounties. The bounty platform pays out in bitcoin. Sign up with Sphinx Chat, complete a bounty, and earn bitcoin! Go to our website for available bounties.
https://community.sphinx.chat/bounties
33 stars 60 forks source link

Mapping of "action" string to next function #1931

Closed humansinstitute closed 1 week ago

humansinstitute commented 2 weeks ago

Context

After receiving responses from Stakwork workflows, the system needs to execute different actions based on the workflow type and response. We need a flexible, maintainable system to map workflow responses to their corresponding handler functions.

Design

@tobi-bams can you map out a design for this.

e.g:

Action Registry - defines all actions strings that map to default to "log and exit" Action Context - typed objects for Action Handlers - e.g. update user stories, output ticket plan, log and exit

e.g. context

type ActionContext struct {
    RequestUUID  string    // A unique ID for this request
    WorkflowID   string    // Which workflow it came from
    Source       string    // Where it came from
    ActionString string    // What needs to be done
    ResponseData []byte    // The actual data to process
}

Assignment Criteria

Acceptance Criteria

Usage Example

To add a new workflow action:

  1. Define a new handler:
    
    type NewFeatureHandler struct {
    db     *sqlx.DB
    logger *zap.Logger
    }

func (h *NewFeatureHandler) Handle(ctx context.Context, actionCtx ActionContext) error { // Implementation return nil }

func (h *NewFeatureHandler) ValidateInput(actionCtx ActionContext) error { // Validation return nil }


2. Register the handler:
```go
registry.Register("new_feature_workflow", &NewFeatureHandler{db: db, logger: logger})
  1. Use in workflow:
    // In your workflow response
    {
    "action_string": "new_feature_workflow",
    "request_uuid": "...",
    "response_data": {...}
    }
Shoaibdev7 commented 2 weeks ago

@humansinstitute.Please assign me?

sophieturner0 commented 2 weeks ago

@humansinstitute Could you please assign me?

MahtabBukhari commented 2 weeks ago

@humansinstitute Could you please assign me?

humansinstitute commented 1 week ago

Now defunct with https://github.com/stakwork/sphinx-tribes/issues/1926 & https://github.com/stakwork/sphinx-tribes/issues/1927