|
| 1 | +import addToCalendarPro from "../../add_to_calendar_pro.app.mjs"; |
| 2 | +import { ConfigurationError } from "@pipedream/platform"; |
| 3 | + |
| 4 | +export default { |
| 5 | + key: "add_to_calendar_pro-create-event", |
| 6 | + name: "Create Event", |
| 7 | + description: "Create an event in a group. [See the documentation](https://docs.add-to-calendar-pro.com/api/events#add-an-event)", |
| 8 | + version: "0.0.1", |
| 9 | + type: "action", |
| 10 | + props: { |
| 11 | + addToCalendarPro, |
| 12 | + groupProKey: { |
| 13 | + propDefinition: [ |
| 14 | + addToCalendarPro, |
| 15 | + "groupProKey", |
| 16 | + ], |
| 17 | + description: "The pro key of the group to add the event to. Either this or newEventGroupName is required.", |
| 18 | + optional: true, |
| 19 | + }, |
| 20 | + newEventGroupName: { |
| 21 | + type: "string", |
| 22 | + label: "New Event Group Name", |
| 23 | + description: "Create a new group for the event with the name provided. Either this or groupProKey is required.", |
| 24 | + optional: true, |
| 25 | + }, |
| 26 | + titleEventSeries: { |
| 27 | + propDefinition: [ |
| 28 | + addToCalendarPro, |
| 29 | + "titleEventSeries", |
| 30 | + ], |
| 31 | + }, |
| 32 | + simplifiedRecurrence: { |
| 33 | + propDefinition: [ |
| 34 | + addToCalendarPro, |
| 35 | + "simplifiedRecurrence", |
| 36 | + ], |
| 37 | + }, |
| 38 | + recurrence: { |
| 39 | + propDefinition: [ |
| 40 | + addToCalendarPro, |
| 41 | + "recurrence", |
| 42 | + ], |
| 43 | + }, |
| 44 | + recurrenceSimpleType: { |
| 45 | + propDefinition: [ |
| 46 | + addToCalendarPro, |
| 47 | + "recurrenceSimpleType", |
| 48 | + ], |
| 49 | + }, |
| 50 | + recurrenceInterval: { |
| 51 | + propDefinition: [ |
| 52 | + addToCalendarPro, |
| 53 | + "recurrenceInterval", |
| 54 | + ], |
| 55 | + }, |
| 56 | + recurrenceByDay: { |
| 57 | + propDefinition: [ |
| 58 | + addToCalendarPro, |
| 59 | + "recurrenceByDay", |
| 60 | + ], |
| 61 | + }, |
| 62 | + recurrenceByMonth: { |
| 63 | + propDefinition: [ |
| 64 | + addToCalendarPro, |
| 65 | + "recurrenceByMonth", |
| 66 | + ], |
| 67 | + }, |
| 68 | + recurrenceByMonthDay: { |
| 69 | + propDefinition: [ |
| 70 | + addToCalendarPro, |
| 71 | + "recurrenceByMonthDay", |
| 72 | + ], |
| 73 | + }, |
| 74 | + recurrenceCount: { |
| 75 | + propDefinition: [ |
| 76 | + addToCalendarPro, |
| 77 | + "recurrenceCount", |
| 78 | + ], |
| 79 | + }, |
| 80 | + recurrenceWeekStart: { |
| 81 | + propDefinition: [ |
| 82 | + addToCalendarPro, |
| 83 | + "recurrenceWeekStart", |
| 84 | + ], |
| 85 | + }, |
| 86 | + iCalFileName: { |
| 87 | + propDefinition: [ |
| 88 | + addToCalendarPro, |
| 89 | + "iCalFileName", |
| 90 | + ], |
| 91 | + }, |
| 92 | + rsvp: { |
| 93 | + propDefinition: [ |
| 94 | + addToCalendarPro, |
| 95 | + "rsvp", |
| 96 | + ], |
| 97 | + }, |
| 98 | + distribution: { |
| 99 | + propDefinition: [ |
| 100 | + addToCalendarPro, |
| 101 | + "distribution", |
| 102 | + ], |
| 103 | + }, |
| 104 | + hideButton: { |
| 105 | + propDefinition: [ |
| 106 | + addToCalendarPro, |
| 107 | + "hideButton", |
| 108 | + ], |
| 109 | + }, |
| 110 | + cta: { |
| 111 | + propDefinition: [ |
| 112 | + addToCalendarPro, |
| 113 | + "cta", |
| 114 | + ], |
| 115 | + }, |
| 116 | + styleId: { |
| 117 | + propDefinition: [ |
| 118 | + addToCalendarPro, |
| 119 | + "styleId", |
| 120 | + ], |
| 121 | + }, |
| 122 | + landingPageTemplateId: { |
| 123 | + propDefinition: [ |
| 124 | + addToCalendarPro, |
| 125 | + "landingPageTemplateId", |
| 126 | + ], |
| 127 | + optional: true, |
| 128 | + }, |
| 129 | + rsvpTemplateId: { |
| 130 | + propDefinition: [ |
| 131 | + addToCalendarPro, |
| 132 | + "rsvpTemplateId", |
| 133 | + ], |
| 134 | + optional: true, |
| 135 | + }, |
| 136 | + ctaTemplateId: { |
| 137 | + propDefinition: [ |
| 138 | + addToCalendarPro, |
| 139 | + "ctaTemplateId", |
| 140 | + ], |
| 141 | + optional: true, |
| 142 | + }, |
| 143 | + numberOfDates: { |
| 144 | + type: "integer", |
| 145 | + label: "Number of Dates", |
| 146 | + description: "The number of dates to create for the event", |
| 147 | + reloadProps: true, |
| 148 | + }, |
| 149 | + }, |
| 150 | + additionalProps() { |
| 151 | + const props = {}; |
| 152 | + if (!this.numberOfDates) { |
| 153 | + return props; |
| 154 | + } |
| 155 | + for (let i = 0; i < this.numberOfDates; i++) { |
| 156 | + props[`name${i}`] = { |
| 157 | + type: "string", |
| 158 | + label: `Title of Date ${i + 1}`, |
| 159 | + description: `The title of Date ${i + 1}`, |
| 160 | + }; |
| 161 | + props[`startDate${i}`] = { |
| 162 | + type: "string", |
| 163 | + label: `Start Date of Date ${i + 1}`, |
| 164 | + description: `The start date of Date ${i + 1} in format YYYY-MM-DD`, |
| 165 | + }; |
| 166 | + props[`startTime${i}`] = { |
| 167 | + type: "string", |
| 168 | + label: `Start Time of Date ${i + 1}`, |
| 169 | + description: `The start time of Date ${i + 1} in format HH:MM`, |
| 170 | + optional: true, |
| 171 | + }; |
| 172 | + props[`endDate${i}`] = { |
| 173 | + type: "string", |
| 174 | + label: `End Date of Date ${i + 1}`, |
| 175 | + description: `The end date of Date ${i + 1} in format YYYY-MM-DD`, |
| 176 | + optional: true, |
| 177 | + }; |
| 178 | + props[`endTime${i}`] = { |
| 179 | + type: "string", |
| 180 | + label: `End Time of Date ${i + 1}`, |
| 181 | + description: `The end time of Date ${i + 1} in format HH:MM`, |
| 182 | + optional: true, |
| 183 | + }; |
| 184 | + props[`timeZone${i}`] = { |
| 185 | + type: "string", |
| 186 | + label: `Time Zone of Date ${i + 1}`, |
| 187 | + description: `The time zone of Date ${i + 1}. Example: "America/Los_Angeles"`, |
| 188 | + optional: true, |
| 189 | + }; |
| 190 | + props[`description${i}`] = { |
| 191 | + type: "string", |
| 192 | + label: `Description of Date ${i + 1}`, |
| 193 | + description: `The description of Date ${i + 1}`, |
| 194 | + optional: true, |
| 195 | + }; |
| 196 | + props[`location${i}`] = { |
| 197 | + type: "string", |
| 198 | + label: `Location of Date ${i + 1}`, |
| 199 | + description: `The location of Date ${i + 1}`, |
| 200 | + optional: true, |
| 201 | + }; |
| 202 | + props[`availability${i}`] = { |
| 203 | + type: "string", |
| 204 | + label: `Availability of Date ${i + 1}`, |
| 205 | + description: `The availability of Date ${i + 1}`, |
| 206 | + options: [ |
| 207 | + "free", |
| 208 | + "busy", |
| 209 | + ], |
| 210 | + optional: true, |
| 211 | + }; |
| 212 | + props[`organizerName${i}`] = { |
| 213 | + type: "string", |
| 214 | + label: `Organizer Name of Date ${i + 1}`, |
| 215 | + description: `The organizer name of Date ${i + 1}`, |
| 216 | + optional: true, |
| 217 | + }; |
| 218 | + props[`organizerEmail${i}`] = { |
| 219 | + type: "string", |
| 220 | + label: `Organizer Email of Date ${i + 1}`, |
| 221 | + description: `The organizer email of Date ${i + 1}`, |
| 222 | + optional: true, |
| 223 | + }; |
| 224 | + props[`attendeeName${i}`] = { |
| 225 | + type: "string", |
| 226 | + label: `Attendee Name of Date ${i + 1}`, |
| 227 | + description: `The attendee name of Date ${i + 1}`, |
| 228 | + optional: true, |
| 229 | + }; |
| 230 | + props[`attendeeEmail${i}`] = { |
| 231 | + type: "string", |
| 232 | + label: `Attendee Email of Date ${i + 1}`, |
| 233 | + description: `The attendee email of Date ${i + 1}`, |
| 234 | + optional: true, |
| 235 | + }; |
| 236 | + } |
| 237 | + return props; |
| 238 | + }, |
| 239 | + async run({ $ }) { |
| 240 | + if (!this.groupProKey && !this.newEventGroupName) { |
| 241 | + throw new ConfigurationError("Either `groupProKey` or `newEventGroupName` is required."); |
| 242 | + } |
| 243 | + if (this.groupProKey && this.newEventGroupName) { |
| 244 | + throw new ConfigurationError("Only one of `groupProKey` or `newEventGroupName` can be provided."); |
| 245 | + } |
| 246 | + const dates = []; |
| 247 | + for (let i = 0; i < this.numberOfDates; i++) { |
| 248 | + dates.push({ |
| 249 | + name: this[`name${i}`], |
| 250 | + startDate: this[`startDate${i}`], |
| 251 | + startTime: this[`startTime${i}`], |
| 252 | + endDate: this[`endDate${i}`], |
| 253 | + endTime: this[`endTime${i}`], |
| 254 | + timeZone: this[`timeZone${i}`], |
| 255 | + description: this[`description${i}`], |
| 256 | + location: this[`location${i}`], |
| 257 | + availability: this[`availability${i}`], |
| 258 | + organizerName: this[`organizerName${i}`], |
| 259 | + organizerEmail: this[`organizerEmail${i}`], |
| 260 | + attendeeName: this[`attendeeName${i}`], |
| 261 | + attendeeEmail: this[`attendeeEmail${i}`], |
| 262 | + }); |
| 263 | + } |
| 264 | + const event = await this.addToCalendarPro.createEvent({ |
| 265 | + $, |
| 266 | + data: { |
| 267 | + event_group: this.groupProKey, |
| 268 | + new_event_group_name: this.newEventGroupName, |
| 269 | + dates, |
| 270 | + title_event_series: this.titleEventSeries, |
| 271 | + simplified_recurrence: this.simplifiedRecurrence, |
| 272 | + recurrence: this.recurrence, |
| 273 | + recurrence_simple_type: this.recurrenceSimpleType, |
| 274 | + recurrence_interval: this.recurrenceInterval, |
| 275 | + recurrence_byDay: this.recurrenceByDay, |
| 276 | + recurrence_byMonth: this.recurrenceByMonth, |
| 277 | + recurrence_byMonthDay: this.recurrenceByMonthDay, |
| 278 | + recurrence_count: this.recurrenceCount, |
| 279 | + recurrence_weekstart: this.recurrenceWeekStart, |
| 280 | + iCalFileName: this.iCalFileName, |
| 281 | + rsvp: this.rsvp, |
| 282 | + rsvp_block: this.rsvpTemplateId, |
| 283 | + distribution: this.distribution, |
| 284 | + hideButton: this.hideButton, |
| 285 | + cta: this.cta, |
| 286 | + cta_block: this.ctaTemplateId, |
| 287 | + layout: this.styleId, |
| 288 | + landingpage: this.landingPageTemplateId, |
| 289 | + }, |
| 290 | + }); |
| 291 | + $.export("$summary", "Successfully created event."); |
| 292 | + return event; |
| 293 | + }, |
| 294 | +}; |
0 commit comments