Skip to content

Commit

Permalink
facebookbusiness (major update)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidDurman committed Oct 4, 2024
1 parent 3ec64e3 commit 9a9aec6
Show file tree
Hide file tree
Showing 11 changed files with 1,232 additions and 99 deletions.
13 changes: 9 additions & 4 deletions src/appmixer/facebookbusiness/bundle.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"name": "appmixer.facebookbusiness",
"version": "1.0.0",
"changelog": [
"Initial version"
]
"version": "2.0.0",
"changelog": {
"1.0.0": ["Initial version"],
"2.0.0": [
"Support for sessions to upload large number of users.",
"New: RemoveMembersInCSVFromAudience, ReplaceMembersFromCSVInAudience",
"Changed: schema configuration for AddMembersFromCSVToAudience."
]
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { createHash } = require('crypto');

module.exports = {

async receive(context) {
Expand All @@ -19,27 +21,47 @@ module.exports = {
'ST',
'ZIP',
'COUNTRY',
'MADID'
'MADID',
'EXTERN_ID'
];

const member = {};
const schema = {};
const member = [];
const schema = [];
fields.forEach(field => {
const value = context.messages.in.content[field];
if (value) {
member[field] = value;
schema[field] = field;
const normalizedValue = createHash('sha256').update(value).digest('hex');
member.push(normalizedValue);
schema.push(field);
}
});

const payload = {
schema: schema,
data: [member],
const body = {
payload: {
schema: schema,
data: [member]
},
access_token: accessToken
};

const url = `https://graph.facebook.com/v20.0/${audienceId}?access_token=${accessToken}`;
const response = await context.httpRequest.post(url, payload);
return context.sendJson({ accountId, audienceId, ...response.data }, 'out');
const url = `https://graph.facebook.com/v20.0/${audienceId}/users`;
const response = await context.httpRequest.post(url, body);

if (!response || !response.data || response.data.num_received !== 1) {
throw new Error(`Failed to add member to audience. Response: ${JSON.stringify({
status: response.status,
statusText: response.statusText,
headers: response.headers,
data: response.data,
requestBody: body
})}`);
}
return context.sendJson({
account_id: accountId,
audience_id: audienceId,
num_received: response.data.num_received,
num_invalid_entries: response.data.num_invalid_entries,
session_id: response.data.session_id
}, 'out');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"ST": { "type": "string" },
"ZIP": { "type": "string" },
"COUNTRY": { "type": "string" },
"MADID": { "type": "string" }
"MADID": { "type": "string" },
"EXTERN_ID": { "type": "string" }
},
"required": ["audienceId"]
},
Expand Down Expand Up @@ -73,17 +74,21 @@
"EMAIL": {
"type": "text",
"index": 3,
"label": "Email"
"label": "Email address"
},
"PHONE": {
"type": "text",
"index": 4,
"label": "Phone"
"label": "Phone number"
},
"GEN": {
"type": "text",
"type": "select",
"index": 5,
"label": "Gender"
"label": "Gender",
"options": [
{ "value": "f", "label": "f" },
{ "value": "m", "label": "m" }
]
},
"DOBY": {
"type": "text",
Expand Down Expand Up @@ -146,6 +151,12 @@
"index": 12,
"label": "Mobile Advertiser ID",
"tooltip": "Use all lowercase, and keep hyphens."
},
"EXTERN_ID": {
"type": "text",
"index": 13,
"label": "External ID",
"tooltip": "This can be any unique ID from the advertiser, such as loyalty membership IDs, user IDs, and external cookie IDs."
}
}
}
Expand All @@ -154,18 +165,23 @@
"outPorts": [
{
"name": "out",
"options": [
{
"value": "accountId",
"label": "Account ID",
"schema": { "type": "string" }
},
{
"value": "audienceId",
"options": [{
"value": "audience_id",
"label": "Audience ID",
"schema": { "type": "string" }
}
]
}, {
"value": "session_id",
"label": "Session ID",
"schema": { "type": "string" }
}, {
"value": "num_received",
"label": "Number of Received Users",
"schema": { "type": "integer" }
}, {
"value": "num_invalid_entries",
"label": "Number of Invalid Entries",
"schema": { "type": "integer" }
}]
}
],
"icon": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNTAwIiBoZWlnaHQ9IjI1MDAiIHZpZXdCb3g9IjAgMCAyNjYuODkzIDI2Ni44OTUiPjxwYXRoIGQ9Ik0yNTIuMTY0IDI2Ni44OTVjOC4xMzQgMCAxNC43MjktNi41OTYgMTQuNzI5LTE0LjczVjE0LjczYzAtOC4xMzctNi41OTYtMTQuNzMtMTQuNzI5LTE0LjczSDE0LjczQzYuNTkzIDAgMCA2LjU5NCAwIDE0LjczdjIzNy40MzRjMCA4LjEzNSA2LjU5MyAxNC43MyAxNC43MyAxNC43M2gyMzcuNDM0eiIgZmlsbD0iIzQ4NWE5NiIvPjxwYXRoIGQ9Ik0xODQuMTUyIDI2Ni44OTVWMTYzLjUzOWgzNC42OTJsNS4xOTQtNDAuMjhoLTM5Ljg4N1Y5Ny41NDJjMC0xMS42NjIgMy4yMzgtMTkuNjA5IDE5Ljk2Mi0xOS42MDlsMjEuMzI5LS4wMVY0MS44OTdjLTMuNjg5LS40OS0xNi4zNTEtMS41ODctMzEuMDgtMS41ODctMzAuNzUzIDAtNTEuODA3IDE4Ljc3MS01MS44MDcgNTMuMjQ0djI5LjcwNWgtMzQuNzgxdjQwLjI4aDM0Ljc4MXYxMDMuMzU1aDQxLjU5N3oiIGZpbGw9IiNmZmYiLz48L3N2Zz4="
Expand Down
Loading

0 comments on commit 9a9aec6

Please sign in to comment.