-
Notifications
You must be signed in to change notification settings - Fork 122
feat(figma): add 'New Comment' trigger for Figma component' #3305
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes are unnecessary. Revert them. |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes are unnecessary. Revert them. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,5 @@ | ||
| version="1.0" | ||
|
|
||
| dependencies { | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| import com.bytechef.component.figma.action.FigmaGetCommentsAction; | ||
| import com.bytechef.component.figma.action.FigmaPostCommentAction; | ||
| import com.bytechef.component.figma.connection.FigmaConnection; | ||
| import com.bytechef.component.figma.trigger.FigmaNewCommentTrigger; | ||
|
|
||
| /** | ||
| * Provides the base implementation for the REST based component. | ||
|
|
@@ -41,7 +42,7 @@ public abstract class AbstractFigmaComponentHandler implements OpenApiComponentH | |
| .connection(modifyConnection(FigmaConnection.CONNECTION_DEFINITION)) | ||
| .clusterElements(modifyClusterElements(tool(FigmaGetCommentsAction.ACTION_DEFINITION), | ||
| tool(FigmaPostCommentAction.ACTION_DEFINITION))) | ||
| .triggers(getTriggers()); | ||
| .triggers(FigmaNewCommentTrigger.TRIGGER_DEFINITION); | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you can see in the Figma module, we have an Since Figma is a generated component, any manual changes will be overwritten the next time the generator is run. To add trigger in component definition, overrride |
||
| @Override | ||
| public ComponentDefinition getDefinition() { | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although this trigger is currently implemented using polling, the Figma REST API documentation indicates that file comment events can be delivered via webhooks. Therefore, this trigger could be more efficiently and reliably implemented as a dynamic webhook trigger, which would allow real-time detection of new comments without periodic polling. To improve this implementation, consider switching from |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /* | ||
| * Copyright 2025 ByteChef | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.bytechef.component.figma.trigger; | ||
|
|
||
| import static com.bytechef.component.definition.ComponentDsl.array; | ||
| import static com.bytechef.component.definition.ComponentDsl.object; | ||
| import static com.bytechef.component.definition.ComponentDsl.outputSchema; | ||
| import static com.bytechef.component.definition.ComponentDsl.string; | ||
| import static com.bytechef.component.definition.ComponentDsl.trigger; | ||
|
|
||
| import com.bytechef.component.definition.ComponentDsl.ModifiableTriggerDefinition; | ||
| import com.bytechef.component.definition.Context.Http; | ||
| import com.bytechef.component.definition.Parameters; | ||
| import com.bytechef.component.definition.TriggerContext; | ||
| import com.bytechef.component.definition.TriggerDefinition.PollOutput; | ||
| import com.bytechef.component.definition.TriggerDefinition.TriggerType; | ||
| import com.bytechef.component.definition.TypeReference; | ||
| import java.time.OffsetDateTime; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| public class FigmaNewCommentTrigger { | ||
| public static final ModifiableTriggerDefinition TRIGGER_DEFINITION = trigger("newComment") | ||
| .title("New Comment") | ||
| .description("Trigger when a new comment is added to a Figma file.") | ||
| .type(TriggerType.POLLING) | ||
| .output( | ||
| outputSchema( | ||
| object().properties( | ||
| string("file_key").description("Key of the Figma file."), | ||
| string("file_name").description("Name of the Figma file."), | ||
| array("comment").items(string()) | ||
| .description("List of comment messages."), | ||
| string("comment_id").description("ID of the comment."), | ||
| string("parent_id").description("Parent comment ID, if any."), | ||
| string("created_at").description("Timestamp when the comment was created."), | ||
| string("resolved_at").description("Timestamp when the comment was resolved."), | ||
| string("triggered_by").description("User who added the comment."), | ||
| string("timestamp").description("Event timestamp.")))) | ||
| .poll(FigmaNewCommentTrigger::poll); | ||
|
|
||
| protected static PollOutput poll( | ||
| Parameters inputParameters, | ||
| Parameters connectionParameters, | ||
| Parameters closureParameters, | ||
| TriggerContext triggerContext) { | ||
| String fileKey = inputParameters.getRequiredString("file_key"); | ||
| String token = connectionParameters.getRequiredString("access_token"); | ||
|
|
||
| Map<String, Object> body = triggerContext | ||
| .http(http -> http.get("https://api.figma.com/v1/files/" + fileKey + "/comments")) | ||
| .header("Authorization", "Bearer " + token) | ||
| .configuration(Http.responseType(Http.ResponseType.JSON)) | ||
| .execute() | ||
| .getBody(new TypeReference<>() {}); | ||
|
|
||
| List<Map<String, Object>> comments = (List<Map<String, Object>>) body.get("comments"); | ||
|
|
||
| List<Map<String, Object>> output = comments.stream() | ||
| .map(comment -> Map.of( | ||
| "file_key", fileKey, | ||
| "file_name", body.get("fileName"), | ||
| "comment", List.of(comment.get("message")), | ||
| "comment_id", comment.get("id"), | ||
| "parent_id", comment.get("parent_id"), | ||
| "created_at", comment.get("created_at"), | ||
| "resolved_at", comment.get("resolved_at"), | ||
| "triggered_by", comment.get("user"), | ||
| "timestamp", OffsetDateTime.now() | ||
| .toString())) | ||
| .toList(); | ||
| return new PollOutput(output, Map.of(), false); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes are unnecessary. Revert them.