[Due for payment 2026-11-19] Support better rule creation suggestions
We want to support the following new feature.
We've recently worked on this feature: https://github.com/Expensify/App/pull/99164. The feature detects when a user makes an update to a transaction, and shows a 'Do you want to create an expense default for this' banner. Some of the problems with this approach are:
- If the user signs out and signs back in, they can see the same popup on the same transaction they already dismissed it on
- Just because the user changes a transaction once, doesn't mean they always want to, so they could receive excess popups that are not helpful/are always ignored
The solutions of the problem is:
- Lets start storing the number of times that a user updates a transaction (based on a specific merchant) in the backend. For example, a user could consistently update a 'starbucks' purchase to the 'coffee' category. (already deployed)
- Instead of always showing the 'Create a rule' popup, once the user has made the same change a few times in a determined span of time
Implementation details
- In order to provide a better experience we will start by storing the changes for a specific field for 1 month
- The popup will be shown if the user makes the same change 2 times during that 1 month period
- The popup visibility will be mandated by a
suggestNewRuleCreationresponse field in theUpdateMoneyRequestorUpdateMoneyRequestVendorcommand - The fields that we will be monitoring at this moment are
category,tag,tax,comment,billable,reimbursableandvendor
Issue Owner
Current Issue Owner: @mallenexpensify
@Krishna2323 let me know if you need anything!
Please assign me too for review
situ reviewed the previous one too, so assigning them to review
I'll start working on this today.
@situchan Whoops! This issue is 2 days overdue. Let's get this updated quick!
@Valforte @JS00001 I logged the raw responses from UpdateMoneyRequestCategory and UpdateMoneyRequestTag across three identical Starbucks + Fees edits. suggestNewRuleCreation isn't in any of them, so the backend side doesn't look live yet.
A few questions before I start:
-
Is the backend part built and deployed? If not, I'll wait rather than guessing the response shape.
-
What exactly does the app get back? One yes/no for the whole edit, or one per field? This matters because a single expense can have a few edits, so one suggested rule could set category, tag, and tax together. If a user is over the threshold for category but not tag, a single yes/no leaves me guessing which fields belong in the rule.
-
When does it become a yes? On the 2nd edit or the 3rd? And does "the same change" mean the same merchant + field, or the same merchant + field + new value? For example, if someone sets
StarbuckstoCoffeeonce, then toMealsonce, is that two changes or one of each? -
Should edits count when we can't show a prompt anyway? There are two cases: editing from a list of expenses, where there is no expense open to show the prompt on, and a user without permission to create rules. If those still count, the count gets used up and no prompt ever appears. Can the backend skip those, or should the app send a flag?
-
Is it okay to lose the prompt offline? Today the prompt appears instantly, before the server responds, so it works without a connection. If the backend decides, there won't be a prompt until the user reconnects.
-
Vendor. You list it as monitored, but it's not part of the prompt today and is behind the
vendorMatchingbeta. Auto-matched vendors go through the same command and shouldn't count. Should we handle this in this PR or as a follow-up?
Ok that's on me! I missed the Web-E pass trough so the new response is never hitting the app. I'm getting that done super quick!
- One bool per Auth call, In practice it translate to one per field, because newdot sends one command per field. There's a case for multiedits, if any one of those hit the treshold it would return true, but we can skip it for multiedits at this moment.
- Fires on the 2nd identical edit, and only on the edit that reaches that number 2. 3rd+ will return false
- Identical means: same policyID + merchant + field + value.
- If the customer categorizes a Starbucks transaction as
Coffeeand a second one asMealsit wouldn't trigger the rule suggestion (both return$response['suggestNewRuleCreation'] = false). After they edit a third Starbucks transaction asCoffeeit would trigger the rule suggestion for that edit, returning$response['suggestNewRuleCreation'] = true - There's a 30-day window for the same edits
- If the user has no permission we would store it, I can change it later to not store it, it makes sense.
- For when there is no expense open to show, I believe the FE can store the flag it received for that specific transaction and then show the banner when the expense is opened
- I believe it's okay to lose it while offline, it would get the flag back from the BE when reconnecting and then show the banner.
- We can handle it in a follow up, no problem
@situchan Huh... This is 4 days overdue. Who can take care of this?
I'm looking for a BE contributor to take this over the finish line. I can try to take a look tomorrow if nobody volunteers
What's the current status of this issue and how can I help? 😄
@hungvu193 thanks!! We're following this issue: https://github.com/Expensify/Expensify/issues/678355
We've merged one auth PR here: https://github.com/Expensify/Auth/pull/24518, which stores a merchantRuleSuggestionEdits NVP when a user edits an expense. We currently return suggestNewRuleCreation from auth (which is a boolean), when a user has made a specific number of similar edits on expenses.
It looks like we need one more web-e PR to make sure that the suggestNewRuleCreation field is returned to e/app, which is where we currently are: https://github.com/Expensify/App/issues/101504#issuecomment-5802928037
Gabriel had started on a PR for this, so we can take a similar approach, but lets create a new PR for this
Thanks for the heads-up! I'll take a look today!
@hungvu193 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
https://github.com/Expensify/Web-Expensify/pull/56516 hit staging yesterday.
cc @Krishna2323 ^ The BE issues should be fixed now
@hungvu193 Whoops! This issue is 2 days overdue. Let's get this updated quick!
@hungvu193 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
Not overdue.
@Krishna2323 any updates on this one?
I'll have the PR up today.