Skip to content
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

Fix: Fix alias api when email receiver is first created #1411

Merged
merged 3 commits into from
Jan 29, 2025

Conversation

StrongMonkey
Copy link
Contributor

@StrongMonkey StrongMonkey commented Jan 23, 2025

When email receiver is first created in ui, the emailAddress will always return with random string at the start even if alias is set. This is problematic as it will change to use alias email on refresh once controller has set the alias.

#1412

Copy link
Contributor

@thedadams thedadams left a comment

Choose a reason for hiding this comment

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

I think this is actually a UI issue. The UI polls for aliases for agents. It should do the same thing for email aliases.

// We should use the alias if the following is true
// 1. Alias is assigned and set to true
// 2. Alias is not assigned but Alias is set at the initial creation.
if (er.AliasAssigned != nil && *er.AliasAssigned) || (er.AliasAssigned == nil && er.Alias != "") {
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't want to do it this way because if er.AliasAssigned == nil then we may be sending back bad data.

The way this works for agent, for example, is the UI polls to make sure it gets back a value for AliasAssigned (which should remain a pointer. If that value is not set, then the UI knows it should keep polling until it gets true or false.

Copy link
Contributor Author

@StrongMonkey StrongMonkey Jan 23, 2025

Choose a reason for hiding this comment

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

Ok. I think the UI only poll once when receiver is created. The problem is that the current logic returns undetermistic result from API when AliasAssigned is set, like the address will change from name@address.com to alias@address.com when controller is settled. I think we should return empty email address when er.AliasAssigned == nil and have UI poll until the alias is set. what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep. That sounds good to me!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the code so that when webhook/email receiver's alias is set, it will return empty address until alias is being set. Otherwise it will return the right address depends on whether alias has been set successfully or not.

The change UI will need to make is that it should start polling for alias if alias is set until AliasAssigned is either false or true.

@StrongMonkey StrongMonkey reopened this Jan 24, 2025
@StrongMonkey StrongMonkey force-pushed the fix-email-trigger-alias branch from 4affd02 to 4b25f81 Compare January 25, 2025 00:31
@StrongMonkey StrongMonkey force-pushed the fix-email-trigger-alias branch from 4b25f81 to c8a3a96 Compare January 27, 2025 15:53
@StrongMonkey StrongMonkey force-pushed the fix-email-trigger-alias branch 2 times, most recently from 67ef3d4 to e820d47 Compare January 28, 2025 20:41
Signed-off-by: Daishan Peng <daishan@acorn.io>
@StrongMonkey
Copy link
Contributor Author

@ryanhopperlowe @ivyjeong13 would appreciate you taking a look at the frontend code piece.

Copy link
Contributor

@ryanhopperlowe ryanhopperlowe left a comment

Choose a reason for hiding this comment

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

Sorry had this review started, but never submitted

Comment on lines 33 to 42
useEffect(() => {
if (
emailReceivers &&
emailReceivers.some(
(receiver) => receiver.aliasAssigned == null && receiver.alias
)
) {
mutateEmailReceivers();
}
}, [emailReceivers, mutateEmailReceivers]);
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems like it would be better handled with polling

Copy link
Contributor

Choose a reason for hiding this comment

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

see how that is handled in ~/lib/hooks/knowledge/useKnowledgeFiles.ts as an example

Comment on lines 57 to 65
useEffect(() => {
if (webhookData?.alias && webhookData.aliasAssigned === undefined) {
const interval = setInterval(async () => {
await getWebhookData.mutate();
}, 1000);

return () => clearInterval(interval);
}
}, [webhookData?.alias, webhookData?.aliasAssigned]);
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, let's use the polling capability built into useSWR

Signed-off-by: Daishan Peng <daishan@acorn.io>
@StrongMonkey StrongMonkey merged commit cfee52b into obot-platform:main Jan 29, 2025
3 checks passed
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.

4 participants