Skip to content

Conversation

@aadamgough
Copy link
Collaborator

Summary

Updated trigger to follow new webhook documentation

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Jan 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 3, 2026 0:35am

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 3, 2026

Greptile Summary

This PR migrates Grain webhook integration from manual configuration to automatic webhook management via the Grain API. The implementation follows the established pattern used by other providers like Calendly and Typeform.

Key Changes:

  • Replaced manual webhook URL/secret inputs with API key authentication
  • Added createGrainWebhookSubscription() function that programmatically creates webhooks in Grain using their Public API v2
  • Added deleteGrainWebhook() function for proper cleanup when triggers are removed
  • Integrated webhook creation/deletion into the main webhook lifecycle (after DB save, with rollback on failure)
  • Added configurable include options (highlights, participants, AI summary) that are passed to Grain API
  • Updated setup instructions to reflect automated webhook creation
  • Uses API version 2025-10-31 header for all Grain API requests

Implementation Quality:

  • Proper error handling with user-friendly messages for common failure scenarios (401, 403)
  • Transaction-like behavior: rolls back DB changes if external webhook creation fails
  • Non-fatal cleanup on deletion (won't fail if Grain API is unavailable)
  • Consistent logging throughout the flow
  • Follows existing codebase patterns for external webhook providers

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation closely follows the existing Calendly webhook pattern, includes proper error handling and rollback logic, maintains consistency across all 6 trigger files, and improves user experience by automating webhook setup
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/app/api/webhooks/route.ts Added Grain webhook creation logic with proper error handling and rollback, following the pattern of other providers like Calendly
apps/sim/lib/webhooks/provider-subscriptions.ts Added Grain webhook deletion handler with non-fatal error handling, consistent with other provider cleanup functions
apps/sim/triggers/grain/webhook.ts Updated generic webhook trigger to use API key instead of manual webhook URL, added include options

Sequence Diagram

sequenceDiagram
    participant User
    participant UI as Trigger UI
    participant API as Webhook API
    participant DB as Database
    participant Grain as Grain API
    
    User->>UI: Configure Grain trigger with API key
    UI->>API: POST /api/webhooks (with apiKey, include options)
    API->>DB: Save webhook record
    DB-->>API: Return savedWebhook
    
    alt provider === 'grain'
        API->>API: createGrainWebhookSubscription()
        API->>Grain: POST /v2/hooks/create
        Note over API,Grain: Authorization: Bearer {apiKey}<br/>Body: {hook_url, include: {...}}
        
        alt Success
            Grain-->>API: {id: grainHookId}
            API->>DB: Update webhook with externalId
            DB-->>API: Webhook updated
            API-->>UI: 201 Created {webhook}
        else API Error (401, 403, etc)
            Grain-->>API: Error response
            API->>DB: DELETE webhook (rollback)
            API-->>UI: 500 Error with user-friendly message
        end
    end
    
    UI-->>User: Show success or error
    
    Note over User,Grain: When user deletes trigger
    User->>API: DELETE /api/webhooks/{id}
    API->>API: cleanupExternalWebhook()
    API->>API: deleteGrainWebhook()
    API->>Grain: DELETE /v2/hooks/{externalId}
    Grain-->>API: 200 OK or 404 Not Found
    API->>DB: Delete webhook record
    API-->>User: Webhook deleted
Loading

@waleedlatif1 waleedlatif1 changed the title fix(grain): updated trigger fix(grain): updated grain trigger to auto-establish trigger Jan 3, 2026
@waleedlatif1 waleedlatif1 merged commit 7515809 into staging Jan 3, 2026
11 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/grain branch January 3, 2026 01:56
waleedlatif1 added a commit that referenced this pull request Jan 3, 2026
…ext menu (#2672)

* feat(logs-context-menu): consolidated logs utils and types, added logs record context menu (#2659)

* feat(email): welcome email; improvement(emails): ui/ux (#2658)

* feat(email): welcome email; improvement(emails): ui/ux

* improvement(emails): links, accounts, preview

* refactor(emails): file structure and wrapper components

* added envvar for personal emails sent, added isHosted gate

* fixed failing tests, added env mock

* fix: removed comment

---------

Co-authored-by: waleed <walif6@gmail.com>

* fix(logging): hitl + trigger dev crash protection (#2664)

* hitl gaps

* deal with trigger worker crashes

* cleanup import strcuture

* feat(imap): added support for imap trigger (#2663)

* feat(tools): added support for imap trigger

* feat(imap): added parity, tested

* ack PR comments

* final cleanup

* feat(i18n): update translations (#2665)

Co-authored-by: waleedlatif1 <waleedlatif1@users.noreply.github.com>

* fix(grain): updated grain trigger to auto-establish trigger (#2666)

Co-authored-by: aadamgough <adam@sim.ai>

* feat(admin): routes to manage deployments (#2667)

* feat(admin): routes to manage deployments

* fix naming fo deployed by

* feat(time-picker): added timepicker emcn component, added to playground, added searchable prop for dropdown, added more timezones for schedule, updated license and notice date (#2668)

* feat(time-picker): added timepicker emcn component, added to playground, added searchable prop for dropdown, added more timezones for schedule, updated license and notice date

* removed unused params, cleaned up redundant utils

* improvement(invite): aligned styling (#2669)

* improvement(invite): aligned with rest of app

* fix(invite): error handling

* fix: addressed comments

---------

Co-authored-by: Emir Karabeg <78010029+emir-karabeg@users.noreply.github.com>
Co-authored-by: Vikhyath Mondreti <vikhyathvikku@gmail.com>
Co-authored-by: waleedlatif1 <waleedlatif1@users.noreply.github.com>
Co-authored-by: Adam Gough <77861281+aadamgough@users.noreply.github.com>
Co-authored-by: aadamgough <adam@sim.ai>
waleedlatif1 pushed a commit that referenced this pull request Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants