| 
 | 1 | +import app from "../../clevertap.app.mjs";  | 
 | 2 | +import utils from "../../common/utils.mjs";  | 
 | 3 | + | 
 | 4 | +export default {  | 
 | 5 | +  key: "clevertap-create-campaign",  | 
 | 6 | +  name: "Create Campaign",  | 
 | 7 | +  description: "Create a campaign. [See the documentation](https://developer.clevertap.com/docs/create-campaign-api)",  | 
 | 8 | +  version: "0.0.1",  | 
 | 9 | +  type: "action",  | 
 | 10 | +  props: {  | 
 | 11 | +    app,  | 
 | 12 | +    name: {  | 
 | 13 | +      type: "string",  | 
 | 14 | +      label: "Campaign Name",  | 
 | 15 | +      description: "The name of your campaign shown in the CleverTap dashboard.",  | 
 | 16 | +    },  | 
 | 17 | +    targetMode: {  | 
 | 18 | +      type: "string",  | 
 | 19 | +      label: "Target Mode",  | 
 | 20 | +      description: "The type of campaign to create",  | 
 | 21 | +      reloadProps: true,  | 
 | 22 | +      options: [  | 
 | 23 | +        {  | 
 | 24 | +          label: "Web Push Notification",  | 
 | 25 | +          value: "webpush",  | 
 | 26 | +        },  | 
 | 27 | +        {  | 
 | 28 | +          label: "Mobile Push Notification",  | 
 | 29 | +          value: "push",  | 
 | 30 | +        },  | 
 | 31 | +        {  | 
 | 32 | +          label: "Email",  | 
 | 33 | +          value: "email",  | 
 | 34 | +        },  | 
 | 35 | +        {  | 
 | 36 | +          label: "Webhooks",  | 
 | 37 | +          value: "webhook",  | 
 | 38 | +        },  | 
 | 39 | +      ],  | 
 | 40 | +    },  | 
 | 41 | +    where: {  | 
 | 42 | +      type: "object",  | 
 | 43 | +      label: "Where",  | 
 | 44 | +      optional: true,  | 
 | 45 | +      description: `Allows you to filter target base on the user events and profile properties. Omit this parameter to target your entire user base. **Example:**  | 
 | 46 | +\`\`\`  | 
 | 47 | +{  | 
 | 48 | +  "event_name": "Charged",  | 
 | 49 | +  "from": 20250101,  | 
 | 50 | +  "to": 20250402  | 
 | 51 | +}  | 
 | 52 | +\`\`\``,  | 
 | 53 | +    },  | 
 | 54 | +    content: {  | 
 | 55 | +      type: "object",  | 
 | 56 | +      label: "Content",  | 
 | 57 | +      description: `Object that defines the content for your message. **Web Push Notification Example:**  | 
 | 58 | +\`\`\`  | 
 | 59 | +{  | 
 | 60 | +  "title": "Hi!",  | 
 | 61 | +  "body": "How are you doing today?",  | 
 | 62 | +  "platform_specific": {  | 
 | 63 | +    "safari": {  | 
 | 64 | +      "deep_link": "https://www.google.com",  | 
 | 65 | +      "ttl": 10  | 
 | 66 | +    },  | 
 | 67 | +    "chrome": {  | 
 | 68 | +      "image": "https://www.exampleImage.com",  | 
 | 69 | +      "icon": "https://www.exampleIcon.com",  | 
 | 70 | +      "deep_link": "http://www.example.com",  | 
 | 71 | +      "ttl": 10,  | 
 | 72 | +      "require_interaction": true,  | 
 | 73 | +      "cta_title1": "title",  | 
 | 74 | +      "cta_link1": "http://www.example2.com",  | 
 | 75 | +      "cta_iconlink1": "https://www.exampleIcon2.com"  | 
 | 76 | +    },  | 
 | 77 | +    "firefox": {  | 
 | 78 | +      "icon": "https://www.exampleIcon.com",  | 
 | 79 | +      "deep_link": "https://www.google.com",  | 
 | 80 | +      "ttl": 10  | 
 | 81 | +    },  | 
 | 82 | +    "kaios": {  | 
 | 83 | +      "icon": "https://www.exampleIcon.com",  | 
 | 84 | +      "ttl": 10,  | 
 | 85 | +      "kaiosKV": {  | 
 | 86 | +        "key1": "value1",  | 
 | 87 | +        "key2": "value2"  | 
 | 88 | +      }  | 
 | 89 | +    }  | 
 | 90 | +  }  | 
 | 91 | +}  | 
 | 92 | +\`\`\`\n\n**Mobile Push Notification Example:**  | 
 | 93 | +\`\`\`  | 
 | 94 | +{  | 
 | 95 | +  "title": "Hi!",  | 
 | 96 | +  "body": "How are you doing today?",  | 
 | 97 | +  "platform_specific": {  | 
 | 98 | +    "ios": {  | 
 | 99 | +      "mutable-content": "true",   | 
 | 100 | +      "deep_link": "example.com",  | 
 | 101 | +      "sound_file": "example.caf",  | 
 | 102 | +      "category": "application category//Books",  | 
 | 103 | +      "badge_count": 1,  | 
 | 104 | +      "Key": "Value_ios"  | 
 | 105 | +    },  | 
 | 106 | +    "android": {  | 
 | 107 | +      "enable_rendermax": true,  | 
 | 108 | +      "wzrk_cid": "Marketing",  | 
 | 109 | +      "background_image": "http://example.jpg",  | 
 | 110 | +      "default_sound": true,  | 
 | 111 | +      "deep_link": "example.com",  | 
 | 112 | +      "large_icon": "http://example.png",  | 
 | 113 | +      "Key": "Value_android",  | 
 | 114 | +    }  | 
 | 115 | +  }  | 
 | 116 | +}  | 
 | 117 | +\`\`\`\n\n **Email Example:**  | 
 | 118 | +\`\`\`  | 
 | 119 | +{  | 
 | 120 | +  "subject": "Welcome",  | 
 | 121 | +  "body": "<div>Your HTML content for the email</div>",  | 
 | 122 | +  "sender_name": "CleverTap"  | 
 | 123 | +}  | 
 | 124 | +\`\`\``,  | 
 | 125 | +      optional: true,  | 
 | 126 | +    },  | 
 | 127 | +    respectFrequencyCaps: {  | 
 | 128 | +      type: "boolean",  | 
 | 129 | +      label: "Respect Frequency Caps",  | 
 | 130 | +      description: "Set to `false` if you want to override frequency caps and dwell time. Defaults to `true`.",  | 
 | 131 | +      optional: true,  | 
 | 132 | +    },  | 
 | 133 | +    estimateOnly: {  | 
 | 134 | +      type: "boolean",  | 
 | 135 | +      label: "Estimate Only",  | 
 | 136 | +      description: "If this parameter is set to `true`, the request returns an estimated reach of the campaign, which is the number of users who receive the notification when you send it out. Setting this parameter to `true` does not create the campaign. Defaults to `false`.",  | 
 | 137 | +      optional: true,  | 
 | 138 | +    },  | 
 | 139 | +    conversionGoal: {  | 
 | 140 | +      type: "object",  | 
 | 141 | +      label: "Conversion Goal",  | 
 | 142 | +      optional: true,  | 
 | 143 | +      description: `Checks the end goal of the campaign for conversion tracking. **Example:**  | 
 | 144 | +\`\`\`  | 
 | 145 | +{  | 
 | 146 | +  "event_name": "Charged",  | 
 | 147 | +  "filter_type": {  | 
 | 148 | +    "event_property": [  | 
 | 149 | +      {  | 
 | 150 | +        "property_name": "Items|Book name",  | 
 | 151 | +        "operator": "equals",  | 
 | 152 | +        "property_value": "book name"  | 
 | 153 | +      },  | 
 | 154 | +      {  | 
 | 155 | +        "property_name": "Amount",  | 
 | 156 | +        "operator": "equals",  | 
 | 157 | +        "property_value": 3456  | 
 | 158 | +      },  | 
 | 159 | +      {  | 
 | 160 | +        "property_name": "Currency",  | 
 | 161 | +        "operator": "equals",  | 
 | 162 | +        "property_value": "USD"  | 
 | 163 | +      }  | 
 | 164 | +    ],  | 
 | 165 | +    "first_time": "yes",  | 
 | 166 | +    "last_time": "yes",  | 
 | 167 | +    "time_of_day": [["21:00","23:00"],["11:34","12:44"],["13:01","13:40"]],  | 
 | 168 | +    "day_of_week": [1,7],  | 
 | 169 | +    "day_of_month": [1,3,16,31]  | 
 | 170 | +  },  | 
 | 171 | +  "conversion_time": "1D",  | 
 | 172 | +  "revenue_property": "Amount"  | 
 | 173 | +}  | 
 | 174 | +\`\`\``,  | 
 | 175 | +    },  | 
 | 176 | +    ttlType: {  | 
 | 177 | +      type: "string",  | 
 | 178 | +      label: "Time To Live Type",  | 
 | 179 | +      description: "This allows setting of time to live for push notifications for android and iOS. The type of time to live. Can be `absolute` or `relative`. Defaults to `absolute`.",  | 
 | 180 | +      options: [  | 
 | 181 | +        {  | 
 | 182 | +          label: "Absolute",  | 
 | 183 | +          value: "absolute",  | 
 | 184 | +        },  | 
 | 185 | +        {  | 
 | 186 | +          label: "Relative",  | 
 | 187 | +          value: "relative",  | 
 | 188 | +        },  | 
 | 189 | +      ],  | 
 | 190 | +      optional: true,  | 
 | 191 | +    },  | 
 | 192 | +    ttlValue: {  | 
 | 193 | +      type: "integer",  | 
 | 194 | +      label: "Time To Live Value",  | 
 | 195 | +      description: "This allows setting of time to live for push notifications for android and iOS. The value of the time to live. Can be a number of days, hours, minutes, or seconds.\n- For `relative` ttl, the input is an integer in minutes\n- For `absolute` ttl, the input should be an integer in the `yyyyMMddHHmm` format. Example: `202207200000`",  | 
 | 196 | +      optional: true,  | 
 | 197 | +    },  | 
 | 198 | +    webhookEndpointName: {  | 
 | 199 | +      type: "string",  | 
 | 200 | +      label: "Webhook Endpoint Name",  | 
 | 201 | +      description: "The name of the webhook endpoint to use for the campaign.",  | 
 | 202 | +      optional: true,  | 
 | 203 | +    },  | 
 | 204 | +    webhookFields: {  | 
 | 205 | +      type: "string[]",  | 
 | 206 | +      label: "Webhook Fields",  | 
 | 207 | +      description: "The fields to include in the webhook payload. Can be `profile-attributes`, `tokens`, or `identities`.",  | 
 | 208 | +      optional: true,  | 
 | 209 | +    },  | 
 | 210 | +    webhookKeyValue: {  | 
 | 211 | +      type: "object",  | 
 | 212 | +      label: "Webhook Key Value",  | 
 | 213 | +      description: "The key-value pairs to include in the webhook payload.",  | 
 | 214 | +      optional: true,  | 
 | 215 | +    },  | 
 | 216 | +  },  | 
 | 217 | +  additionalProps() {  | 
 | 218 | +    if (this.targetMode === "push") {  | 
 | 219 | +      return {  | 
 | 220 | +        when: {  | 
 | 221 | +          type: "object",  | 
 | 222 | +          label: "When",  | 
 | 223 | +          description: `Allows you to set Date, time and Delivery preferences of the message. **Example:**  | 
 | 224 | +\`\`\`  | 
 | 225 | +{  | 
 | 226 | +  "type": "later",  | 
 | 227 | +  "delivery_date_time": ["20230503 15:20"],  | 
 | 228 | +  "delivery_timezone": "user",  | 
 | 229 | +  "user_timezone_wrap_around": true,  | 
 | 230 | +  "dnd": {  | 
 | 231 | +    "message_state": "delay",  | 
 | 232 | +    "dnd_timezone": "user"  | 
 | 233 | +  },  | 
 | 234 | +  "campaign_cutoff": "14:20"  | 
 | 235 | +}  | 
 | 236 | +\`\`\``,  | 
 | 237 | +        },  | 
 | 238 | +      };  | 
 | 239 | +    }  | 
 | 240 | + | 
 | 241 | +    return {  | 
 | 242 | +      when: {  | 
 | 243 | +        type: "string",  | 
 | 244 | +        label: "When",  | 
 | 245 | +        description: "When you want to send out the messages. Valid inputs are `now` (to send the notification right away) or in the format **YYYYMMDD HH:MM** to schedule the messages for a specific date and time in the future. **Example:** `20250717 15:20`",  | 
 | 246 | +      },  | 
 | 247 | +    };  | 
 | 248 | +  },  | 
 | 249 | +  async run({ $ }) {  | 
 | 250 | +    const {  | 
 | 251 | +      app,  | 
 | 252 | +      name,  | 
 | 253 | +      targetMode,  | 
 | 254 | +      when,  | 
 | 255 | +      where,  | 
 | 256 | +      content,  | 
 | 257 | +      respectFrequencyCaps,  | 
 | 258 | +      estimateOnly,  | 
 | 259 | +      conversionGoal,  | 
 | 260 | +      ttlType,  | 
 | 261 | +      ttlValue,  | 
 | 262 | +      webhookEndpointName,  | 
 | 263 | +      webhookFields,  | 
 | 264 | +      webhookKeyValue,  | 
 | 265 | +    } = this;  | 
 | 266 | + | 
 | 267 | +    const response = await app.createCampaign({  | 
 | 268 | +      $,  | 
 | 269 | +      data: {  | 
 | 270 | +        name,  | 
 | 271 | +        target_mode: targetMode,  | 
 | 272 | +        respect_frequency_caps: respectFrequencyCaps,  | 
 | 273 | +        estimate_only: estimateOnly,  | 
 | 274 | +        when: utils.parseJson(when) || {},  | 
 | 275 | +        where: utils.parseJson(where) || {},  | 
 | 276 | +        content: utils.parseJson(content) || {},  | 
 | 277 | +        ...(conversionGoal  | 
 | 278 | +          ? {  | 
 | 279 | +            conversion_goal: utils.parseJson(conversionGoal),  | 
 | 280 | +          }  | 
 | 281 | +          : {}  | 
 | 282 | +        ),  | 
 | 283 | +        ...(ttlType && ttlValue  | 
 | 284 | +          ? {  | 
 | 285 | +            ttl: {  | 
 | 286 | +              ttl_type: ttlType,  | 
 | 287 | +              value: ttlValue,  | 
 | 288 | +            },  | 
 | 289 | +          }  | 
 | 290 | +          : {}  | 
 | 291 | +        ),  | 
 | 292 | +        ...(webhookEndpointName  | 
 | 293 | +          ? {  | 
 | 294 | +            webhook_endpoint_name: webhookEndpointName,  | 
 | 295 | +          }  | 
 | 296 | +          : {}  | 
 | 297 | +        ),  | 
 | 298 | +        ...(webhookFields  | 
 | 299 | +          ? {  | 
 | 300 | +            webhook_fields: utils.parseJson(webhookFields),  | 
 | 301 | +          }  | 
 | 302 | +          : {}  | 
 | 303 | +        ),  | 
 | 304 | +        ...(webhookKeyValue  | 
 | 305 | +          ? {  | 
 | 306 | +            webhook_key_value: utils.parseJson(webhookKeyValue),  | 
 | 307 | +          }  | 
 | 308 | +          : {}  | 
 | 309 | +        ),  | 
 | 310 | +      },  | 
 | 311 | +    });  | 
 | 312 | + | 
 | 313 | +    $.export("$summary", "Successfully created campaign");  | 
 | 314 | + | 
 | 315 | +    return response;  | 
 | 316 | +  },  | 
 | 317 | +};  | 
0 commit comments