-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - google_chat #17368
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
New Components - google_chat #17368
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6c0de7d
new sources
michelle0927 7c57c34
pnpm-lock.yaml
michelle0927 bf1292f
pnpm-lock.yaml
michelle0927 6637782
pnpm-lock.yaml
michelle0927 23caa14
fix pagination
michelle0927 d57c531
update
michelle0927 659857a
update
michelle0927 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
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
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,108 @@ | ||
| import googleChat from "../../google_chat.app.mjs"; | ||
| import { | ||
| DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, ConfigurationError, | ||
| } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| props: { | ||
| googleChat, | ||
| db: "$.service.db", | ||
| timer: { | ||
| type: "$.interface.timer", | ||
| default: { | ||
| intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
| }, | ||
| }, | ||
| spaceId: { | ||
| propDefinition: [ | ||
| googleChat, | ||
| "spaceId", | ||
| ], | ||
| }, | ||
| }, | ||
| methods: { | ||
| _getLastTs() { | ||
| return this.db.get("lastTs"); | ||
| }, | ||
| _setLastTs(ts) { | ||
| this.db.set("lastTs", ts); | ||
| }, | ||
| async *paginateMessages(max) { | ||
| const lastTs = this._getLastTs(); | ||
| let next, count = 0; | ||
| const params = { | ||
| filter: lastTs | ||
| ? `createTime > "${lastTs}"` | ||
| : undefined, | ||
| orderBy: "createTime DESC", | ||
| }; | ||
|
|
||
| do { | ||
| const { | ||
| messages, nextPageToken, | ||
| } = await this.googleChat.listMessages({ | ||
| spaceId: this.spaceId, | ||
| params, | ||
| }); | ||
|
|
||
| if (!messages.length) { | ||
| return; | ||
| } | ||
|
|
||
| for (const message of messages) { | ||
| yield message; | ||
| if (max && ++count >= max) { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| next = nextPageToken; | ||
| params.pageToken = next; | ||
| } while (next); | ||
| }, | ||
| async getPaginatedMessages(max) { | ||
| const messages = []; | ||
| for await (const message of this.paginateMessages(max)) { | ||
| messages.push(message); | ||
| } | ||
| return messages; | ||
| }, | ||
| isRelevant() { | ||
| return true; | ||
| }, | ||
| generateMeta(message) { | ||
| return { | ||
| id: message.name, | ||
| summary: this.getSummary(message), | ||
| ts: Date.parse(message.createTime), | ||
| }; | ||
| }, | ||
| async processEvent(max) { | ||
| const messages = await this.getPaginatedMessages(max); | ||
|
|
||
| const relevantMessages = messages.filter((message) => this.isRelevant(message)); | ||
|
|
||
| if (!relevantMessages?.length) { | ||
| return; | ||
| } | ||
|
|
||
| this._setLastTs(relevantMessages[0].createTime); | ||
|
|
||
| relevantMessages.reverse().forEach((message) => { | ||
| const meta = this.generateMeta(message); | ||
| this.$emit(message, meta); | ||
| }); | ||
| }, | ||
| getSummary() { | ||
| throw new ConfigurationError("getSummary is not implemented"); | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async deploy() { | ||
| await this.processEvent(25); | ||
| }, | ||
| }, | ||
| async run() { | ||
| await this.processEvent(); | ||
| }, | ||
| }; |
31 changes: 31 additions & 0 deletions
31
components/google_chat/sources/new-command-used/new-command-used.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,31 @@ | ||
| import common from "../common/base.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "google_chat-new-command-used", | ||
| name: "New Command Used", | ||
| description: "Emit new event when a new command is used in a space. [See the documentation](https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.messages/list)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| ...common.props, | ||
| command: { | ||
| type: "string", | ||
| label: "Command", | ||
| description: "The command to emit events for.", | ||
| }, | ||
| }, | ||
| methods: { | ||
| ...common.methods, | ||
| isRelevant(message) { | ||
| const command = this.command.startsWith("/") | ||
| ? this.command | ||
| : `/${this.command}`; | ||
| return message.text.startsWith(command); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| getSummary(message) { | ||
| return `New Command Used in Message: ${message.text.slice(0, 50)}`; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }; | ||
32 changes: 32 additions & 0 deletions
32
components/google_chat/sources/new-mention-received/new-mention-received.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,32 @@ | ||
| import common from "../common/base.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "google_chat-new-mention-received", | ||
| name: "New Mention Received", | ||
| description: "Emit new event when a new mention is received in a space. [See the documentation](https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.messages/list)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| ...common.props, | ||
| memberId: { | ||
| propDefinition: [ | ||
| common.props.googleChat, | ||
| "memberId", | ||
| (c) => ({ | ||
| spaceId: c.spaceId, | ||
| }), | ||
| ], | ||
| }, | ||
| }, | ||
| methods: { | ||
| ...common.methods, | ||
| isRelevant(message) { | ||
| return message.formattedText.includes(`<users/${this.memberId}>`); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| getSummary(message) { | ||
| return `New Mention in Message: ${message.formattedText.slice(0, 50)}`; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }; | ||
17 changes: 17 additions & 0 deletions
17
components/google_chat/sources/new-message-in-space/new-message-in-space.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,17 @@ | ||
| import common from "../common/base.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "google_chat-new-message-in-space", | ||
| name: "New Message in Space", | ||
| description: "Emit new event when a new message is posted in a space. [See the documentation](https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.messages/list)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| methods: { | ||
| ...common.methods, | ||
| getSummary(message) { | ||
| return `New Message: ${message.text.slice(0, 50)}`; | ||
| }, | ||
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.