Skip to content

Feature/lead webhook #2

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 26 commits into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4059e6c
add: feature button for bulk lead entry retry for un-processed, leads
krushit-redsoft Feb 11, 2025
df91bd2
fix: add configuration for meta Ads and campaign auto creation on lea…
krushit-redsoft Feb 11, 2025
0b00275
fix: update ads doc to form doc type
krushit-redsoft Feb 11, 2025
9e3e267
fix: phone number parse function handle all phone numbers
krushit-redsoft Feb 11, 2025
33a6502
fix: handle existing country code without + in phone number
krushit-redsoft Feb 11, 2025
eaf6aa9
fix: prevent processed leads from execution
krushit-redsoft Feb 11, 2025
a1061f5
feat-fix: remove campaign or ads deps from Meta Lead Form, allow to t…
krushit-redsoft Feb 12, 2025
b9e4d7a
chore: more misc chagnes and comment for campaign to get removed in f…
krushit-redsoft Feb 12, 2025
c8ae250
fix: indentation issue
krushit-redsoft Feb 12, 2025
e593d1e
chore: set campaign for new ads as well
krushit-redsoft Feb 12, 2025
7745839
fix: campaign auto creation
krushit-redsoft Feb 12, 2025
3ce84d0
typo: campaign
krushit-redsoft Feb 12, 2025
b7a6083
fix: bring back the checks for config
krushit-redsoft Feb 14, 2025
da84cbb
fix: add lead_data and error-message reset for processed lead
krushit-redsoft Feb 15, 2025
fa94090
fix: form filters, remove already added forms
krushit-redsoft Feb 15, 2025
865fc0e
fix: db_value save and load json data
krushit-redsoft Feb 16, 2025
ce0d584
change signature failure to error log
krushit-redsoft Feb 17, 2025
e479bf7
chore: remove unused doctype
krushit-redsoft Feb 17, 2025
b79a605
fix: allow import for meta lead logs
krushit-redsoft Feb 18, 2025
3d268f2
fix: leads webhook, lead data initilize first in fuction
krushit-redsoft Mar 4, 2025
01214af
fix: load json lead data for use
krushit-redsoft Mar 4, 2025
c491d2c
fix: fetch config first
krushit-redsoft Mar 4, 2025
463e135
add: organic and platform tracking
krushit-redsoft Mar 5, 2025
359d9ab
add: support for drop down aof form mapping
krushit-redsoft Mar 7, 2025
54fe141
add: take user from meta config
krushit-redsoft Mar 7, 2025
22f5747
typo: meta_payload
krushit-redsoft Mar 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion onelead/meta_lead/doctype/meta_ads/meta_ads.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-11-19 22:52:01.322993",
"modified": "2025-02-18 13:33:48.990232",
"modified_by": "Administrator",
"module": "Meta Lead",
"name": "Meta Ads",
Expand All @@ -80,6 +80,7 @@
"write": 1
}
],
"search_fields": "ads_name, campaign",
"show_title_field_in_link": 1,
"sort_field": "modified",
"sort_order": "DESC",
Expand Down
539 changes: 296 additions & 243 deletions onelead/meta_lead/doctype/meta_ads_page_config/meta_ads_page_config.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"fetch_from": "meta_lead_form.form_name",
"fieldname": "form_name",
"fieldtype": "Read Only",
"in_list_view": 1,
"in_preview": 1,
"label": "Form Name"
},
Expand All @@ -52,8 +53,6 @@
"fieldname": "campaign",
"fieldtype": "Link",
"in_filter": 1,
"in_list_view": 1,
"in_preview": 1,
"in_standard_filter": 1,
"label": "Campaign",
"options": "Meta Campaign",
Expand All @@ -63,7 +62,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-11-20 00:34:32.273912",
"modified": "2025-03-06 00:50:29.294400",
"modified_by": "Administrator",
"module": "Meta Lead",
"name": "Meta Campaign Form List",
Expand Down
66 changes: 65 additions & 1 deletion onelead/meta_lead/doctype/meta_lead_form/meta_lead_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,71 @@ frappe.ui.form.on("Meta Lead Form", {
}
}
});
});
})
.attr('title', __('Create a new Campaign document using fields from this form, If not, this will be created automatically when leads are received.'));

}

if (!frm.doc.ads) {
// ----- NEW BUTTON: Create Ads -----
frm.add_custom_button(__('Create Ads'), function () {
// 1. Generate an Ads ID and Ads Name
const adsId = (frm.doc.form_name || "Ad") + "_" + (frm.doc.form_id || "");
const adsName = frm.doc.form_name || `Ads for ${frm.doc.form_id}`;

// 2. Validate necessary fields
if (!frm.doc.campaign) {
frappe.msgprint(__('Please link a Campaign first before creating Ads'));
return;
}

// 3. Check if a Meta Ads doc with the derived Ads ID already exists
frappe.call({
method: "frappe.client.get_list",
args: {
doctype: "Meta Ads",
filters: { ads_id: adsId },
fields: ["name", "ads_name"]
},
callback: function (r) {
if (r.message && r.message.length > 0) {
// Found an existing Ads doc
const existingAds = r.message[0];
frappe.msgprint(__("Ads already exists: ") + existingAds.ads_name);

// Link that Ads doc to this form (assuming you have a 'meta_ads' link field or similar)
frm.set_value("meta_ads", existingAds.name);
frm.save();
} else {
// 4. Insert a new Meta Ads record
frappe.call({
method: "frappe.client.insert",
args: {
doc: {
doctype: "Meta Ads",
ads_id: adsId,
ads_name: adsName,
status: frm.doc.status,
campaign: frm.doc.campaign,
has_lead_form: 1 // or whatever your checkbox field is named
}
},
callback: function (res) {
if (!res.exc) {
const adsDoc = res.message;
frappe.msgprint(__("New Ads created: ") + adsDoc.ads_name);

// Link the newly created Ads to this form
frm.set_value("meta_ads", adsDoc.name);
frm.save();
}
}
});
}
}
});
})
.attr('title', __('Create a new Meta Ads document using fields from this form, If not, this will be created automatically when leads are received.'));
}
}
});
3 changes: 2 additions & 1 deletion onelead/meta_lead/doctype/meta_lead_form/meta_lead_form.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
{
"fieldname": "ads",
"fieldtype": "Link",
"hidden": 1,
"label": "Ads",
"options": "Meta Ads"
},
Expand Down Expand Up @@ -157,7 +158,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-12-28 18:42:11.538615",
"modified": "2025-02-12 23:34:35.747040",
"modified_by": "Administrator",
"module": "Meta Lead",
"name": "Meta Lead Form",
Expand Down
1 change: 1 addition & 0 deletions onelead/meta_lead/doctype/meta_lead_form/meta_lead_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def on_update(self):
After insert, if `assign_to` or `assignee_doctype` are changed and a campaign is linked,
update the linked campaign with the new values.
"""
# TODO: 1a - 1c: Remove the logic in light of the new M:M relationship between `Meta Lead Form` and `Meta Campaign`
if self.campaign:
# Fetch the linked campaign
campaign = frappe.get_doc("Meta Campaign", self.campaign)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"meta_field",
"lead_doctype_field",
"default_value",
"formatting_function"
"formatting_function",
"function_parameters"
],
"fields": [
{
Expand Down Expand Up @@ -41,14 +42,19 @@
"allow_in_quick_entry": 1,
"description": "Add custom python function to process and format meta field value for Lead DOCTYPE entry.",
"fieldname": "formatting_function",
"fieldtype": "Code",
"fieldtype": "Select",
"label": "Formatting function"
},
{
"fieldname": "function_parameters",
"fieldtype": "Code",
"label": "Function Parameters"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-11-13 01:56:28.812630",
"modified": "2025-03-06 01:21:19.404169",
"modified_by": "Administrator",
"module": "Meta Lead",
"name": "Meta Lead Form Mapping",
Expand Down
Empty file.
8 changes: 0 additions & 8 deletions onelead/meta_lead/doctype/meta_lead_logs/meta_lead_logs.js

This file was deleted.

128 changes: 0 additions & 128 deletions onelead/meta_lead/doctype/meta_lead_logs/meta_lead_logs.json

This file was deleted.

9 changes: 0 additions & 9 deletions onelead/meta_lead/doctype/meta_lead_logs/meta_lead_logs.py

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
"app_name",
"is_enabled",
"page_flow",
"lead_creator",
"column_break_blmf",
"user_access_token",
"user_id",
"token_expiry",
"is_token_valid",
"connect_facebook"
"connect_facebook",
"enable_polling",
"polling_interval",
"last_polling_time"
],
"fields": [
{
Expand Down Expand Up @@ -98,6 +102,33 @@
"fieldtype": "Check",
"label": "Is Token Valid",
"read_only": 1
},
{
"default": "0",
"fieldname": "enable_polling",
"fieldtype": "Check",
"label": "Enable Polling"
},
{
"depends_on": "eval:doc.enable_polling",
"description": "Input time in Hours. e.g. 3",
"fieldname": "polling_interval",
"fieldtype": "Int",
"label": "Polling Interval"
},
{
"fieldname": "last_polling_time",
"fieldtype": "Datetime",
"label": "Last Polling Time",
"read_only": 1
},
{
"default": "Administrator",
"description": "All leads will be created via this user, ensure user has lead access.",
"fieldname": "lead_creator",
"fieldtype": "Link",
"label": "Lead creator",
"options": "User"
}
],
"index_web_pages_for_search": 1,
Expand All @@ -108,7 +139,7 @@
"link_fieldname": "page"
}
],
"modified": "2024-11-16 01:11:29.074410",
"modified": "2025-03-08 02:01:59.656838",
"modified_by": "Administrator",
"module": "Meta Lead",
"name": "Meta Webhook Config",
Expand Down
Loading
Loading