Skip to content

feat(variables): add lead ad campaign fields, reel input type and picker entries - #1700

Merged
sung17 merged 2 commits into
mainfrom
feat/system-fields-lead-ads
Nov 12, 2026
Merged

sung17 merged 2 commits into
mainfrom
feat/system-fields-lead-ads

Conversation

@sung17

@sung17 sung17 commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Completes the system field list for message and AI prompt variables. Most keys already resolved; this adds the missing ones, fixes one label bug and puts the rest in the variable picker.

  • New Lead Ads fields {{last_ad_name}}, {{last_adset_id}}, {{last_adset_name}}, {{last_campaign_id}}, {{last_campaign_name}}, from the contact's latest lead.
    • Six nullable columns on FacebookLeadAdsLead (adId, adName, adsetId, adsetName, campaignId, campaignName).
    • processLeadgen reads them with a separate Graph call, getLeadAdAttribution. It is best-effort: names need ad-account access the page token may lack, so a failed read only leaves these fields empty and never fails the lead. adId falls back to the webhook's adgroup_id.
  • {{last_ad}} falls back to the latest lead's ad when the contact inbox has no referral.
  • {{last_user_input_type}} is an alias of {{last_input_type}}, like last_btt_title / last_btn_title.
  • reel input type: an Instagram message with an ig_reel / reel attachment is marked contentAttributes.type = "reel_share", the same way story mentions are. ContactInbox.lastUserInputType and {{last_input_type}} then return reel instead of video. The contact filter gets a "Reel" option (21 locales).
  • Fix {{chat_history_details}}: lines were labelled senderType === "user" ? "User" : "Admin", but inbound messages are saved as contact, so the contact showed as "Admin" and agents as "User". Now contact → User, user → Admin, bot/api/system → Bot.
  • Variable picker: adds total_tagged (Messenger only). The other fields in this PR still resolve when typed but are not offered in the picker.

Migrations

  • 20261111070112_facebook_lead_ad_attribution: ADD COLUMN ×6, all nullable.
  • 20261111072812_last_user_input_type_reel: ALTER TYPE "lastUserInputType" ADD VALUE 'reel'.

Notes

  • Leads and reels received before deploy keep empty ad/campaign fields and video. There is no backfill.
  • {{last_ad_body}} is still WhatsApp-only: Messenger/Instagram referrals carry no ad body.
  • Translations other than en/vi were written without a native speaker review.

Testing

  • packages/variables: lead fields, last_ad fallback, alias, reel input type, new chat-history.test.ts for sender labels
  • packages/business: reel in last-user-input.test.ts; lead service columns
  • apps/worker: lead-ads.test.ts stores attribution and survives a failed Graph read; full worker suite passes (5063). lead-ads.chain.test.ts was extended but not run (needs E2E_THROWAWAY_DATABASE).
  • integrations/instagram, instagram-facebook: reel share marking
  • apps/builder: reserved-custom-fields.test.ts; i18n:check clean
  • check-types across affected packages (pre-commit typecheck), ultracite
  • Not yet tried against a real Facebook lead or Instagram reel.

🤖 Generated with Claude Code

@github-actions github-actions Bot added the feature New feature or request label Nov 11, 2026
@sung17
sung17 force-pushed the feat/system-fields-lead-ads branch from 26f57f0 to 3f62a1c Compare November 12, 2026 04:00
Deathgiver and others added 2 commits November 12, 2026 11:07
…ker entries

- Add {{last_ad_name}}, {{last_adset_id}}, {{last_adset_name}},
  {{last_campaign_id}} and {{last_campaign_name}}, read from the contact's
  latest Facebook lead. The worker reads them from the Graph lead object in
  a separate best-effort call, so missing ad-account access never fails a lead.
- {{last_ad}} falls back to the latest lead's ad when there is no referral.
- Add {{last_user_input_type}} as an alias of {{last_input_type}}; both return
  "reel" for a reel shared on Instagram.
- Fix {{chat_history_details}} sender labels: the contact was labelled "Admin".
- Offer the system fields that already resolved but were missing from the
  variable picker.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… entries

Drop the other system fields this branch added to the variable picker and
the labels only they used. The fields still resolve when typed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sung17
sung17 force-pushed the feat/system-fields-lead-ads branch from 3f62a1c to ce1a9fa Compare November 12, 2026 04:21
@sung17
sung17 merged commit f26af7b into main Nov 12, 2026
14 checks passed
hello-jackytruong referenced this pull request in hello-jackytruong/ChatWorkAI Nov 22, 2026
…ker entries (#1700)

* feat(variables): add lead ad campaign fields, reel input type and picker entries

- Add {{last_ad_name}}, {{last_adset_id}}, {{last_adset_name}},
  {{last_campaign_id}} and {{last_campaign_name}}, read from the contact's
  latest Facebook lead. The worker reads them from the Graph lead object in
  a separate best-effort call, so missing ad-account access never fails a lead.
- {{last_ad}} falls back to the latest lead's ad when there is no referral.
- Add {{last_user_input_type}} as an alias of {{last_input_type}}; both return
  "reel" for a reel shared on Instagram.
- Fix {{chat_history_details}} sender labels: the contact was labelled "Admin".
- Offer the system fields that already resolved but were missing from the
  variable picker.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(custom-fields): offer only total_tagged among the new picker entries

Drop the other system fields this branch added to the variable picker and
the labels only they used. The fields still resolve when typed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Deathgiver <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant