-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
7417 workflows i can send emails using the email account #7431
7417 workflows i can send emails using the email account #7431
Conversation
@@ -23,6 +23,7 @@ export class GoogleAPIsOauthCommonStrategy extends PassportStrategy( | |||
'email', | |||
'profile', | |||
'https://www.googleapis.com/auth/gmail.readonly', | |||
'https://www.googleapis.com/auth/gmail.send', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will need to put that behind a feature flag as we will need to go through the google approval process and it can take up to a month. We will be able to test with a short list of accounts in the meantime and will need the flag :)
Also it's likely that we will need to have a process to ask users to reconnect their account if we detect that the scope is missing (maybe when we try to send an email and get a 403 the first time) We already have similar mechanism for messaging sync
e5101a4
to
0409f15
Compare
0409f15
to
5bfb2ff
Compare
5b3428b
to
3b76753
Compare
3b76753
to
2a0829e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This pull request implements email sending functionality using connected Google accounts in the Twenty application's workflow system. Here's a concise summary of the major changes:
- Implemented email sending via Google SDK in
send-email.workflow-action.ts
- Added 'https://www.googleapis.com/auth/gmail.send' scope to Google API OAuth scopes
- Updated
WorkflowEditActionFormSendEmail
component to select connected accounts for email sending - Added 'scopes' field to
ConnectedAccountWorkspaceEntity
and related repository methods - Introduced
MailSenderException
for handling mail sender-related errors - Updated
WorkflowSendEmailStepSettings
to useconnectedAccountId
instead of template-based approach
21 file(s) reviewed, 8 comment(s)
Edit PR Review Bot Settings
packages/twenty-front/src/modules/workflow/components/WorkflowEditActionFormSendEmail.tsx
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/workflow/components/WorkflowEditActionFormSendEmail.tsx
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/workflow/components/WorkflowEditActionFormSendEmail.tsx
Outdated
Show resolved
Hide resolved
...nty-server/src/engine/core-modules/auth/strategies/google-apis-oauth-common.auth.strategy.ts
Show resolved
Hide resolved
packages/twenty-server/src/modules/mail-sender/exceptions/mail-sender.exception.ts
Show resolved
Hide resolved
packages/twenty-server/src/modules/mail-sender/workflow-actions/send-email.workflow-action.ts
Show resolved
Hide resolved
eq: action.settings.connectedAccountId, | ||
}, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we extract this logic, as long as the select component? I feel this kind of app connection will happen often. It should be re-usable and not specific to SendEmailAction
. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we should wait for the next action to be implemented to factorize this logic
packages/twenty-server/src/modules/mail-sender/workflow-actions/send-email.workflow-action.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! I left a few comments for things I think we should discuss 😄
@@ -32,6 +39,7 @@ export type SelectProps<Value extends string | number | null> = { | |||
options: SelectOption<Value>[]; | |||
value?: Value; | |||
withSearchInput?: boolean; | |||
callToActionButton?: CallToActionButton; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely convinced we should add specific use cases to the raw Select components. The Select component should allow composition: We should be able to add such a button quickly, but the Select component should not know about it.
One example I like is Headless UI components:
Another solution, if we want to add buttons in selects often, is to make it possible to inject buttons through the options
property:
options={[{ label: 'XX', value: "" }, { type: "divider" }, { type: "button", label: "Add one +", onClick: () => {}, icon: "" }]}
If we keep adding specific use cases like this to the Select component itself, it will quickly become bloated.
I don't think we should change something to your PR, this is more a discussion to start with the whole team.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I Allowed that to myself as there already is a SearchInput
option that can be displayed at the bottom of the select. @charlesBochet @thomtrp wdyt?
onChange={(connectedAccountId) => { | ||
field.onChange(connectedAccountId); | ||
handleSave(); | ||
checkConnectedAccountScopes(connectedAccountId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does happen if the user closes the Google tab we opened before completing the process? The account will be wired to the step – handleSave()
is called before checkConnectedAccountScopes()
– but the account wouldn't be set up correctly. Is it possible to recover from this error in the app currently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right. In fact I call handleSave() before because we don't have access to the handleSave() method after the google oAuth, so it is not possible to do it.
In fact it is possible, but it would be a lot of work for something "temporary" as the accounts will have the proper scopes after they have been updated
Also, I think this oAuth triggered at dropdown select is a little bit aggressive, a warning banner would be better in my opinion, will discuss that with @Bonapara
packages/twenty-server/src/modules/mail-sender/workflow-actions/send-email.workflow-action.ts
Show resolved
Hide resolved
82b9586
to
80e0d4a
Compare
- update `send-email.workflow-action.ts` so it send email via the google sdk - remove useless `workflow-action.email.ts` - add `send` authorization to google api scopes - update the front workflow email step form to provide a `connectedAccountId` from the available connected accounts - update the permissions of connected accounts: ask users to reconnect when selecting missing send permission ![image](https://github.com/user-attachments/assets/fe3c329d-fd67-4d0d-8450-099c35933645)
send-email.workflow-action.ts
so it send email via the google sdkworkflow-action.email.ts
send
authorization to google api scopesconnectedAccountId
from the available connected accounts