- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
Notion - Comments #15200
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
          
     Merged
      
      
    
  
     Merged
                    Notion - Comments #15200
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            2 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
          
            53 changes: 53 additions & 0 deletions
          
          53 
        
  components/notion/actions/create-comment/create-comment.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import notion from "../../notion.app.mjs"; | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
|  | ||
| export default { | ||
| key: "notion-create-comment", | ||
| name: "Create Comment", | ||
| description: "Creates a comment in a page or existing discussion thread. [See the documentation](https://developers.notion.com/reference/create-a-comment)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| notion, | ||
| pageId: { | ||
| propDefinition: [ | ||
| notion, | ||
| "pageId", | ||
| ], | ||
| description: "Unique identifier of a page. Either this or a Discussion ID is required (not both)", | ||
| optional: true, | ||
| }, | ||
| discussionId: { | ||
| type: "string", | ||
| label: "Discussion ID", | ||
| description: "A UUID identifier for a discussion thread. Either this or a Page ID is required (not both)", | ||
| optional: true, | ||
| }, | ||
| comment: { | ||
| type: "string", | ||
| label: "Comment", | ||
| description: "The comment text", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| if ((this.pageId && this.discussionId) || (!this.pageId && !this.discussionId)) { | ||
| throw new ConfigurationError("Either a Page ID or a Discussion ID is required (not both)"); | ||
| } | ||
|  | ||
| const response = await this.notion._getNotionClient().comments.create({ | ||
| parent: this.pageId && { | ||
| page_id: this.pageId, | ||
| }, | ||
| discussion_id: this.discussionId, | ||
| rich_text: [ | ||
| { | ||
| text: { | ||
| content: this.comment, | ||
| }, | ||
| }, | ||
| ], | ||
| }); | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| $.export("$summary", `Successfully added comment with ID: ${response.id}`); | ||
| return response; | ||
| }, | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/notion", | ||
| "version": "0.2.7", | ||
| "version": "0.3.0", | ||
| "description": "Pipedream Notion Components", | ||
| "main": "notion.app.mjs", | ||
| "keywords": [ | ||
|  | @@ -11,6 +11,7 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "dependencies": { | ||
| "@notionhq/client": "^2.2.3", | ||
| "@pipedream/platform": "^3.0.3", | ||
| "@tryfabric/martian": "^1.2.4", | ||
| "asynckit": "^0.4.0", | ||
| "combined-stream": "^1.0.8", | ||
|  | ||
        
          
          
            59 changes: 59 additions & 0 deletions
          
          59 
        
  components/notion/sources/new-comment-created/new-comment-created.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import base from "../common/base.mjs"; | ||
|  | ||
| export default { | ||
| ...base, | ||
| key: "notion-new-comment-created", | ||
| name: "New Comment Created", | ||
| description: "Emit new event when a new comment is created in a page or block. [See the documentation](https://developers.notion.com/reference/retrieve-a-comment)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| ...base.props, | ||
| pageId: { | ||
| propDefinition: [ | ||
| base.props.notion, | ||
| "pageId", | ||
| ], | ||
| description: "Unique identifier of a page or block", | ||
| }, | ||
| }, | ||
| methods: { | ||
| ...base.methods, | ||
| generateMeta(comment) { | ||
| return { | ||
| id: comment.id, | ||
| summary: `New Comment ID: ${comment.id}`, | ||
| ts: comment.created_time, | ||
| }; | ||
| }, | ||
| }, | ||
| async run() { | ||
| const lastTs = this.getLastCreatedTimestamp(); | ||
| let maxTs = lastTs; | ||
| let cursor; | ||
|  | ||
| do { | ||
| const { | ||
| results, next_cursor: next, | ||
| } = await this.notion._getNotionClient().comments.list({ | ||
| block_id: this.pageId, | ||
| start_cursor: cursor, | ||
| page_size: 100, | ||
| }); | ||
| if (!results?.length) { | ||
| break; | ||
| } | ||
| for (const comment of results) { | ||
| const ts = Date.parse(comment.created_time); | ||
| if (ts >= lastTs) { | ||
| maxTs = Math.max(ts, maxTs); | ||
| this.$emit(comment, this.generateMeta(comment)); | ||
| } | ||
| } | ||
| cursor = next; | ||
| } while (cursor); | ||
|  | ||
| this.setLastCreatedTimestamp(maxTs); | ||
| }, | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| }; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
      
      Oops, something went wrong.
      
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.