The AREA (Action-REAction) system works in 3 steps:
- Action: Detects an event on a service
- Engine: Listens for triggered actions
- Reaction: Executes a response on another service
Create a file for your new action (e.g., githubIssue.go):
func GetNewAction(userID string) {
// 1. Retrieve the service token
// 2. Call the service API
// 3. If condition is met, trigger the action
_, err = initializers.DB.Actions.FindUnique(
db.Actions.ID.Equals(action.ID),
).Update(
db.Actions.Triggered.Set(true),
).Exec(ctx)
}Add your action to the polling system:
func LaunchRoutines() {
go func() {
ticker := time.NewTicker(5 * time.Second)
for range ticker.C {
users, _ := initializers.DB.Users.FindMany().Exec(context.Background())
for _, user := range users {
action.GetGithubWebHook(user.ID)
action.GetNewAction(user.ID) // ← Your new action
}
}
}()
}Create a file for your reaction (e.g., slackMsg.go):
func ReactWithSlackMsg(user db.UsersModel, message string) {
// 1. Configure the webhook/API
// 2. Prepare the payload
// 3. Send the HTTP request
}Connect action and reaction:
if area.Name == "Github_issue_to_slack" { // ← Your AREA name
for _, action := range actions {
if action.Triggered {
// Reset the trigger
initializers.DB.Actions.FindUnique(...).Update(
db.Actions.Triggered.Set(false),
).Exec(ctx)
// Execute the reaction
for _, user := range users {
reaction.ReactWithSlackMsg(user, "New issue!")
}
}
}
}If necessary, add your configuration structures:
type SlackConfig struct {
WebhookURL string `json:"webhook_url"`
}Action (githubPr.go): Detects closed PRs
↓
Routine: Checks every 5 seconds
↓
Engine: Listens for Github_pr_to_discord with Triggered = true
↓
Reaction (discordMsg.go): Sends a Discord message
- Polling: 5 seconds (configurable in
time.NewTicker) - Trigger: Boolean flag system
Triggeredon the action - Reset: The listener sets
Triggered = falseafter execution - User tokens: Retrieved via
UserServiceTokensfor each service
Use Prisma (schema.prisma) to define your tables:
Areas: AREA configurationsActions: Trigger eventsReactions: Automated responsesUserServiceTokens: User OAuth2 tokens