Skip to content

[Components] nextdoor - new action components #15306

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
202 changes: 202 additions & 0 deletions components/nextdoor/actions/create-ad-group/create-ad-group.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import app from "../../nextdoor.app.mjs";
import utils from "../../common/utils.mjs";

export default {
key: "nextdoor-create-ad-group",
name: "Create Ad Group",
description: "Creates an ad group based on the input payload for an existing campaign. [See the documentation](https://developer.nextdoor.com/reference/adgroup-create).",
version: "0.0.1",
type: "action",
props: {
app,
advertiserId: {
propDefinition: [
app,
"advertiserId",
],
},
campaignId: {
propDefinition: [
app,
"campaignId",
({ advertiserId }) => ({
advertiserId,
}),
],
},
name: {
description: "The name of the ad group.",
propDefinition: [
app,
"name",
],
},
placements: {
type: "string[]",
label: "Placements",
description: "The placements for the ad group.",
options: [
"RHR",
"FEED",
"FSF",
],
},
bidAmount: {
type: "string",
label: "Bid Amount",
description: "The bid amount for the ad group. The value must be a string in the format `USD 10` as an example.",
},
bidPricingType: {
type: "string",
label: "Bid Pricing Type",
description: "The bid pricing type for the ad group. The value must be one of `CPM`.",
options: [
"CPM",
],
},
budgetAmount: {
type: "string",
label: "Budget Amount",
description: "The budget amount for the ad group. The value must be a string in the format `USD 10` as an example.",
},
budgetType: {
type: "string",
label: "Budget Type",
description: "The budget type for the ad group.",
options: [
"DAILY_CAP_MONEY",
],
Comment on lines +66 to +68
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there really only one option? If so, it should probably be set in the code directly instead of being a prop

},
startTime: {
propDefinition: [
app,
"startTime",
],
},
endTime: {
propDefinition: [
app,
"endTime",
],
},
numberOfFrequencyCaps: {
type: "integer",
label: "Number Of Frequency Caps",
description: "The number of frequency caps to be collected. Defaults to `1`.",
default: 1,
reloadProps: true,
},
},
methods: {
frequencyCapsPropsMapper(prefix) {
const {
[`${prefix}maxImpressions`]: maxImpressions,
[`${prefix}numTimeunits`]: numTimeunits,
[`${prefix}timeunit`]: timeunit,
} = this;

return {
max_impressions: maxImpressions,
num_timeunits: numTimeunits,
timeunit,
};
},
getFrequencyCapsPropDefinitions({
prefix,
label,
} = {}) {
return {
[`${prefix}maxImpressions`]: {
type: "integer",
label: `${label} - Max Impressions`,
description: "The maximum number of impressions.",
},
[`${prefix}numTimeunits`]: {
type: "integer",
label: `${label} - Number of Time Units`,
description: "The number of time units for frequency caps.",
},
[`${prefix}timeunit`]: {
type: "string",
label: `${label} - Time Unit`,
description: "The time unit for frequency caps.",
options: [
"MINUTE",
"MINUTES",
"HOUR",
"HOURS",
"DAY",
"DAYS",
"WEEK",
"WEEKS",
"MONTH",
"MONTHS",
],
},
};
},
createAdGroup(args = {}) {
return this.app.post({
path: "/adgroup/create",
...args,
});
},
},
async additionalProps() {
const {
numberOfFrequencyCaps,
getFrequencyCapsPropDefinitions,
} = this;

return utils.getAdditionalProps({
numberOfFields: numberOfFrequencyCaps,
fieldName: "frequency cap",
getPropDefinitions: getFrequencyCapsPropDefinitions,
});
},
async run({ $ }) {
const {
createAdGroup,
advertiserId,
campaignId,
name,
placements,
bidAmount,
bidPricingType,
budgetAmount,
budgetType,
startTime,
endTime,
numberOfFrequencyCaps,
frequencyCapsPropsMapper,
} = this;

const response = await createAdGroup({
$,
data: {
advertiser_id: advertiserId,
campaign_id: campaignId,
name,
placements: utils.parseArray(placements),
bid: {
amount: bidAmount,
pricing_type: bidPricingType,
},
budget: {
amount: budgetAmount,
budget_type: budgetType,
},
start_time: startTime,
end_time: endTime,
frequency_caps: utils.getFieldsProps({
numberOfFields: numberOfFrequencyCaps,
fieldName: "frequency cap",
propsMapper: frequencyCapsPropsMapper,
}),
},
});

$.export("$summary", `Successfully created ad group with ID \`${response.id}\`.`);
return response;
},
};
86 changes: 86 additions & 0 deletions components/nextdoor/actions/create-ad/create-ad.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import app from "../../nextdoor.app.mjs";

export default {
key: "nextdoor-create-ad",
name: "Create Ad",
description: "Creates an ad based on the input payload for an existing NAM ad group. [See the documentation](https://developer.nextdoor.com/reference/ad-create).",
version: "0.0.1",
type: "action",
props: {
app,
advertiserId: {
propDefinition: [
app,
"advertiserId",
],
},
campaignId: {
propDefinition: [
app,
"campaignId",
({ advertiserId }) => ({
advertiserId,
}),
],
},
adGroupId: {
propDefinition: [
app,
"adGroupId",
({
advertiserId,
campaignId,
}) => ({
advertiserId,
campaignId,
}),
],
},
creativeId: {
propDefinition: [
app,
"creativeId",
({ advertiserId }) => ({
advertiserId,
}),
],
},
name: {
description: "The name of the ad.",
propDefinition: [
app,
"name",
],
},
},
methods: {
createAd(args = {}) {
return this.app.post({
path: "/ad/create",
...args,
});
},
},
async run({ $ }) {
const {
createAd,
advertiserId,
adGroupId,
creativeId,
name,
} = this;

const response = await createAd({
$,
data: {
advertiser_id: advertiserId,
adgroup_id: adGroupId,
creative_id: creativeId,
name,
},
});

$.export("$summary", `Successfully created ad with ID \`${response.id}\`.`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import app from "../../nextdoor.app.mjs";

export default {
key: "nextdoor-create-advertiser",
name: "Create Advertiser",
description: "Creates an advertiser that is tied to the NAM profile the API credentials are tied to. [See the documentation](https://developer.nextdoor.com/reference/advertiser-create).",
version: "0.0.1",
type: "action",
props: {
app,
name: {
description: "The name of the advertiser.",
propDefinition: [
app,
"name",
],
},
websiteUrl: {
propDefinition: [
app,
"websiteUrl",
],
},
categoryId: {
propDefinition: [
app,
"categoryId",
],
},
},
methods: {
createAdvertiser(args = {}) {
return this.app.post({
path: "/advertiser/create",
...args,
});
},
},
async run({ $ }) {
const {
createAdvertiser,
name,
websiteUrl,
categoryId,
} = this;

const response = await createAdvertiser({
$,
data: {
name,
website_url: websiteUrl,
category_id: categoryId,
},
});

$.export("$summary", `Successfully created advertiser with ID \`${response.id}\`.`);
return response;
},
};
Loading
Loading