Skip to content

Emit company created event #12404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2025

Conversation

thomtrp
Copy link
Contributor

@thomtrp thomtrp commented Jun 2, 2025

Fixes #12337

When importing emails, matched companies are added, but no event is triggered. Which means that workflows are not triggered. Adding the event.

To test:

  • create a workflow that listens to company creation
  • import emails
  • make sure workflow has been triggered

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

Added event emission for company creation during email import to properly trigger workflows when companies are created via email/calendar sync.

  • Added workspaceEventEmitter.emitDatabaseBatchEvent() in createCompanies() to emit events for newly created companies
  • Integrated ObjectMetadataEntity to properly identify company metadata for event emission
  • Structured event payload to include company record ID, metadata, and properties for workflow triggers
  • Maintains batch processing efficiency by emitting a single batch event for multiple companies

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

Copy link
Contributor

@martmull martmull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I would like to validate something with @Weiko before merge if ok for you

Comment on lines +57 to +62
const objectMetadata = await this.objectMetadataRepository.findOne({
where: {
standardId: STANDARD_OBJECT_IDS.company,
workspaceId,
},
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using the cache instead of calling the db? @Weiko could it be a new standard?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, we don't have a good framework today to make this choice, loading the whole objectMetadataMap from cache instead of querying a single record has some trade off as well. Let's keep it like this for now, the query should be fast anyway

Copy link
Contributor

github-actions bot commented Jun 2, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:14707

This environment will automatically shut down when the PR is closed or after 5 hours.

@thomtrp thomtrp force-pushed the tt-emit-company-created-event-on-email-import branch from 68e3f09 to 0e4aa36 Compare June 2, 2025 09:20
@charlesBochet charlesBochet merged commit 4e410db into main Jun 2, 2025
35 of 37 checks passed
@charlesBochet charlesBochet deleted the tt-emit-company-created-event-on-email-import branch June 2, 2025 10:16
abdulrahmancodes pushed a commit to abdulrahmancodes/twenty that referenced this pull request Jun 2, 2025
Fixes twentyhq#12337

When importing emails, matched companies are added, but no event is
triggered. Which means that workflows are not triggered. Adding the
event.

To test:
- create a workflow that listens to company creation
- import emails
- make sure workflow has been triggered
abdulrahmancodes pushed a commit to abdulrahmancodes/twenty that referenced this pull request Jun 3, 2025
Fixes twentyhq#12337

When importing emails, matched companies are added, but no event is
triggered. Which means that workflows are not triggered. Adding the
event.

To test:
- create a workflow that listens to company creation
- import emails
- make sure workflow has been triggered
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.

Workflow not triggering with email sync
4 participants