|
| 1 | +import { ConfigurationError } from "@pipedream/platform"; |
| 2 | +import { |
| 3 | + ATTENDEE_ABILITY_OPTIONS, |
| 4 | + FREE_BUSY_STATUS_OPTIONS, |
| 5 | + ICON_TYPE_OPTIONS, |
| 6 | + VC_TYPE_OPTIONS, |
| 7 | + VISIBILITY_OPTIONS, |
| 8 | +} from "../../common/constants.mjs"; |
| 9 | +import lark from "../../lark.app.mjs"; |
| 10 | + |
| 11 | +export default { |
| 12 | + key: "lark-create-new-lark-calendar-event", |
| 13 | + name: "Create New Lark Calendar Event", |
| 14 | + description: "Creates a new event in Lark's calendar. [See the documentation](https://open.larksuite.com/document/server-docs/calendar-v4/calendar-event/create)", |
| 15 | + version: "0.0.1", |
| 16 | + type: "action", |
| 17 | + props: { |
| 18 | + lark, |
| 19 | + calendarId: { |
| 20 | + propDefinition: [ |
| 21 | + lark, |
| 22 | + "calendarId", |
| 23 | + ], |
| 24 | + }, |
| 25 | + summary: { |
| 26 | + type: "string", |
| 27 | + label: "Summary", |
| 28 | + description: "Event title.", |
| 29 | + }, |
| 30 | + description: { |
| 31 | + type: "string", |
| 32 | + label: "Description", |
| 33 | + description: "Event description. Supports parsing HTML tags. **Note:** While HTML tags can be used to achieve some rich text formatting, the rich text formatting generated by the client is not implemented using HTML tags. If you update the description through the API after generating rich text formatting on the client side, it may result in the loss of the original rich text formatting applied by the client.", |
| 34 | + optional: true, |
| 35 | + }, |
| 36 | + needNotification: { |
| 37 | + type: "boolean", |
| 38 | + label: "Need Notification", |
| 39 | + description: "Whether to send Bot notifications to event participants when updating the event.", |
| 40 | + optional: true, |
| 41 | + }, |
| 42 | + startTimeDate: { |
| 43 | + type: "string", |
| 44 | + label: "Start Time Date", |
| 45 | + description: "Start time, only use this field for all-day events, [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) format, for example, 2018-09-01.", |
| 46 | + optional: true, |
| 47 | + }, |
| 48 | + startTimeTimestamp: { |
| 49 | + type: "string", |
| 50 | + label: "Start Time Timestamp", |
| 51 | + description: "Second-level timestamp, used to set a specific start time. For example, 1602504000 means 2020/10/12 20:00:00 (UTC +8 time zone).", |
| 52 | + optional: true, |
| 53 | + }, |
| 54 | + startTimeTimezone: { |
| 55 | + type: "string", |
| 56 | + label: "Start Time Timezone", |
| 57 | + description: "Time zone. Use IANA Time Zone Database standards such as Asia/Shanghai.", |
| 58 | + optional: true, |
| 59 | + }, |
| 60 | + endTimeDate: { |
| 61 | + type: "string", |
| 62 | + label: "End Time Date", |
| 63 | + description: "End time, only use this field for all-day events, [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) format, for example, 2018-09-01.", |
| 64 | + optional: true, |
| 65 | + }, |
| 66 | + endTimeTimestamp: { |
| 67 | + type: "string", |
| 68 | + label: "End Time Timestamp", |
| 69 | + description: "Second-level timestamp, used to set a specific end time. For example, 1602504000 means 2020/10/12 20:00:00 (UTC +8 time zone).", |
| 70 | + optional: true, |
| 71 | + }, |
| 72 | + endTimeTimezone: { |
| 73 | + type: "string", |
| 74 | + label: "End Time Timezone", |
| 75 | + description: "Time zone. Use IANA Time Zone Database standards such as Asia/Shanghai.", |
| 76 | + optional: true, |
| 77 | + }, |
| 78 | + vcType: { |
| 79 | + type: "string", |
| 80 | + label: "VC Type", |
| 81 | + description: "Video conferencing type. If video conferencing is not required, no_meeting must be passed. **Default value:** empty, which means the Lark video conference URL will be automatically generated when a event participant is added for the first time.", |
| 82 | + options: VC_TYPE_OPTIONS, |
| 83 | + optional: true, |
| 84 | + }, |
| 85 | + iconType: { |
| 86 | + type: "string", |
| 87 | + label: "Icon Type", |
| 88 | + description: "The icon type of the video conferencing.", |
| 89 | + options: ICON_TYPE_OPTIONS, |
| 90 | + optional: true, |
| 91 | + }, |
| 92 | + vchatDescription: { |
| 93 | + type: "string", |
| 94 | + label: "VChat Description", |
| 95 | + description: "Video conference copywriting.", |
| 96 | + optional: true, |
| 97 | + }, |
| 98 | + meetingUrl: { |
| 99 | + type: "string", |
| 100 | + label: "Meeting URL", |
| 101 | + description: "Video conference URL.", |
| 102 | + optional: true, |
| 103 | + }, |
| 104 | + visibility: { |
| 105 | + type: "string", |
| 106 | + label: "Visibility", |
| 107 | + description: "Event visibility. The value is Default for new events by default. This is valid for all invitees only when an event is created. Any changes to the property are valid only for the current identity.", |
| 108 | + options: VISIBILITY_OPTIONS, |
| 109 | + optional: true, |
| 110 | + }, |
| 111 | + attendeeAbility: { |
| 112 | + type: "string", |
| 113 | + label: "Attendee Ability", |
| 114 | + description: "Event invitees' scopes.", |
| 115 | + options: ATTENDEE_ABILITY_OPTIONS, |
| 116 | + optional: true, |
| 117 | + }, |
| 118 | + freeBusyStatus: { |
| 119 | + type: "string", |
| 120 | + label: "Free/Busy Status", |
| 121 | + description: "Event availability. The value is Busy for new events by default. This is valid for all invitees only when an event is created. Any changes to the property are valid only for the current identity.", |
| 122 | + options: FREE_BUSY_STATUS_OPTIONS, |
| 123 | + optional: true, |
| 124 | + }, |
| 125 | + locationName: { |
| 126 | + type: "string", |
| 127 | + label: "Location Name", |
| 128 | + description: "Name of the location.", |
| 129 | + optional: true, |
| 130 | + }, |
| 131 | + locationAddress: { |
| 132 | + type: "string", |
| 133 | + label: "Location Address", |
| 134 | + description: "Address of the location.", |
| 135 | + optional: true, |
| 136 | + }, |
| 137 | + locationLatitude: { |
| 138 | + type: "string", |
| 139 | + label: "Location Latitude", |
| 140 | + description: "Latitude coordinate of the location. Locations within China Mainland should comply with the GCJ-02 standard, and locations outside China Mainland should comply with the WGS84 standard.", |
| 141 | + optional: true, |
| 142 | + }, |
| 143 | + locationLongitude: { |
| 144 | + type: "string", |
| 145 | + label: "Location Longitude", |
| 146 | + description: "Longitude coordinate of the location. Locations within China Mainland should comply with the GCJ-02 standard, and locations outside China Mainland should comply with the WGS84 standard.", |
| 147 | + optional: true, |
| 148 | + }, |
| 149 | + color: { |
| 150 | + type: "integer", |
| 151 | + label: "Color", |
| 152 | + description: "Event color, the value is represented by an int32 color RGB value.", |
| 153 | + optional: true, |
| 154 | + }, |
| 155 | + recurrence: { |
| 156 | + type: "string", |
| 157 | + label: "Recurrence", |
| 158 | + description: "Recurrence rule for recurring events. For details, see [RFC 5545](https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.10). E.g. `FREQ=DAILY;INTERVAL=1`.", |
| 159 | + optional: true, |
| 160 | + }, |
| 161 | + }, |
| 162 | + async run({ $ }) { |
| 163 | + if (!this.startTimeDate && !this.startTimeTimestamp) { |
| 164 | + throw new ConfigurationError("You must provide at least one of `start time date` or `start time timestamp`"); |
| 165 | + } |
| 166 | + if (this.startTimeDate && this.startTimeTimestamp) { |
| 167 | + throw new ConfigurationError("You must provide either `start time date` or `start time timestamp`, but not both"); |
| 168 | + } |
| 169 | + if (!this.endTimeDate && !this.endTimeTimestamp) { |
| 170 | + throw new ConfigurationError("You must provide at least one of `end time date` or `end time timestamp`"); |
| 171 | + } |
| 172 | + if (this.endTimeDate && this.endTimeTimestamp) { |
| 173 | + throw new ConfigurationError("You must provide either `end time date` or `end time timestamp`, but not both"); |
| 174 | + } |
| 175 | + |
| 176 | + const response = await this.lark.createCalendarEvent({ |
| 177 | + $, |
| 178 | + calendarId: this.calendarId, |
| 179 | + data: { |
| 180 | + summary: this.summary, |
| 181 | + description: this.description, |
| 182 | + need_notification: this.needNotification, |
| 183 | + start_time: { |
| 184 | + date: this.startTimeDate, |
| 185 | + timestamp: this.startTimeTimestamp, |
| 186 | + timezone: this.startTimeTimezone, |
| 187 | + }, |
| 188 | + end_time: { |
| 189 | + date: this.endTimeDate, |
| 190 | + timestamp: this.endTimeTimestamp, |
| 191 | + timezone: this.endTimeTimezone, |
| 192 | + }, |
| 193 | + vchat: { |
| 194 | + vc_type: this.vcType, |
| 195 | + icon_type: this.iconType, |
| 196 | + description: this.vchatDescription, |
| 197 | + meeting_url: this.meetingUrl, |
| 198 | + }, |
| 199 | + visibility: this.visibility, |
| 200 | + attendee_ability: this.attendeeAbility, |
| 201 | + free_busy_status: this.freeBusyStatus, |
| 202 | + location: { |
| 203 | + name: this.locationName, |
| 204 | + address: this.locationAddress, |
| 205 | + latitude: this.locationLatitude |
| 206 | + ? parseFloat(this.locationLatitude) |
| 207 | + : undefined, |
| 208 | + longitude: this.locationLongitude |
| 209 | + ? parseFloat(this.locationLongitude) |
| 210 | + : undefined, |
| 211 | + }, |
| 212 | + color: this.color, |
| 213 | + recurrence: this.recurrence, |
| 214 | + }, |
| 215 | + }); |
| 216 | + |
| 217 | + $.export("$summary", `Successfully created calendar event with ID: ${response.data.event.event_id}`); |
| 218 | + return response; |
| 219 | + }, |
| 220 | +}; |
0 commit comments