|
| 1 | +import { GoogleChatIcon } from '@/components/icons' |
| 2 | +import type { BlockConfig } from '@/blocks/types' |
| 3 | +import { AuthMode } from '@/blocks/types' |
| 4 | +import type { GoogleChatResponse } from '@/tools/google_chat/types' |
| 5 | + |
| 6 | +export const GoogleChatBlock: BlockConfig<GoogleChatResponse> = { |
| 7 | + type: 'google_chat', |
| 8 | + name: 'Google Chat', |
| 9 | + description: 'Send messages and manage Google Chat spaces', |
| 10 | + authMode: AuthMode.OAuth, |
| 11 | + longDescription: |
| 12 | + 'Integrate with Google Chat to send messages to spaces and list available spaces using OAuth.', |
| 13 | + docsLink: 'https://docs.sim.ai/tools/google-chat', |
| 14 | + category: 'tools', |
| 15 | + bgColor: '#E0E0E0', |
| 16 | + icon: GoogleChatIcon, |
| 17 | + subBlocks: [ |
| 18 | + { |
| 19 | + id: 'operation', |
| 20 | + title: 'Operation', |
| 21 | + type: 'dropdown', |
| 22 | + options: [ |
| 23 | + { label: 'Send Message', id: 'send_message' }, |
| 24 | + { label: 'List Spaces', id: 'list_spaces' }, |
| 25 | + ], |
| 26 | + value: () => 'send_message', |
| 27 | + }, |
| 28 | + { |
| 29 | + id: 'credential', |
| 30 | + title: 'Google Chat Account', |
| 31 | + type: 'oauth-input', |
| 32 | + canonicalParamId: 'oauthCredential', |
| 33 | + mode: 'basic', |
| 34 | + required: true, |
| 35 | + serviceId: 'google-chat', |
| 36 | + requiredScopes: [ |
| 37 | + 'https://www.googleapis.com/auth/chat.spaces.readonly', |
| 38 | + 'https://www.googleapis.com/auth/chat.messages.create', |
| 39 | + ], |
| 40 | + placeholder: 'Select Google account', |
| 41 | + }, |
| 42 | + { |
| 43 | + id: 'manualCredential', |
| 44 | + title: 'Google Chat Account', |
| 45 | + type: 'short-input', |
| 46 | + canonicalParamId: 'oauthCredential', |
| 47 | + mode: 'advanced', |
| 48 | + placeholder: 'Enter credential ID', |
| 49 | + required: true, |
| 50 | + }, |
| 51 | + { |
| 52 | + id: 'spaceId', |
| 53 | + title: 'Space ID', |
| 54 | + type: 'short-input', |
| 55 | + placeholder: 'e.g., spaces/AAAA1234 or AAAA1234', |
| 56 | + required: { field: 'operation', value: 'send_message' }, |
| 57 | + condition: { field: 'operation', value: 'send_message' }, |
| 58 | + }, |
| 59 | + { |
| 60 | + id: 'message', |
| 61 | + title: 'Message', |
| 62 | + type: 'long-input', |
| 63 | + placeholder: 'Enter your message', |
| 64 | + required: { field: 'operation', value: 'send_message' }, |
| 65 | + condition: { field: 'operation', value: 'send_message' }, |
| 66 | + }, |
| 67 | + { |
| 68 | + id: 'threadKey', |
| 69 | + title: 'Thread Key', |
| 70 | + type: 'short-input', |
| 71 | + placeholder: 'Optional thread key for threaded replies', |
| 72 | + condition: { field: 'operation', value: 'send_message' }, |
| 73 | + }, |
| 74 | + { |
| 75 | + id: 'filter', |
| 76 | + title: 'Filter', |
| 77 | + type: 'short-input', |
| 78 | + placeholder: 'e.g., spaceType = "SPACE"', |
| 79 | + condition: { field: 'operation', value: 'list_spaces' }, |
| 80 | + }, |
| 81 | + { |
| 82 | + id: 'pageSize', |
| 83 | + title: 'Max Results', |
| 84 | + type: 'short-input', |
| 85 | + placeholder: 'Maximum spaces to return (default 100)', |
| 86 | + condition: { field: 'operation', value: 'list_spaces' }, |
| 87 | + }, |
| 88 | + ], |
| 89 | + tools: { |
| 90 | + access: ['google_chat_send_message', 'google_chat_list_spaces'], |
| 91 | + config: { |
| 92 | + tool: (params) => { |
| 93 | + switch (params.operation) { |
| 94 | + case 'send_message': |
| 95 | + return 'google_chat_send_message' |
| 96 | + case 'list_spaces': |
| 97 | + return 'google_chat_list_spaces' |
| 98 | + default: |
| 99 | + throw new Error(`Invalid Google Chat operation: ${params.operation}`) |
| 100 | + } |
| 101 | + }, |
| 102 | + params: (params) => { |
| 103 | + const { oauthCredential, operation, ...rest } = params |
| 104 | + |
| 105 | + switch (operation) { |
| 106 | + case 'send_message': |
| 107 | + return { |
| 108 | + oauthCredential, |
| 109 | + spaceId: rest.spaceId, |
| 110 | + message: rest.message, |
| 111 | + threadKey: rest.threadKey, |
| 112 | + } |
| 113 | + case 'list_spaces': |
| 114 | + return { |
| 115 | + oauthCredential, |
| 116 | + pageSize: rest.pageSize ? Number(rest.pageSize) : undefined, |
| 117 | + filter: rest.filter, |
| 118 | + } |
| 119 | + default: |
| 120 | + return { oauthCredential, ...rest } |
| 121 | + } |
| 122 | + }, |
| 123 | + }, |
| 124 | + }, |
| 125 | + inputs: { |
| 126 | + operation: { type: 'string', description: 'Operation to perform' }, |
| 127 | + oauthCredential: { type: 'string', description: 'Google Chat OAuth credential' }, |
| 128 | + spaceId: { type: 'string', description: 'Google Chat space ID' }, |
| 129 | + message: { type: 'string', description: 'Message text to send' }, |
| 130 | + threadKey: { type: 'string', description: 'Thread key for threaded replies' }, |
| 131 | + filter: { type: 'string', description: 'Filter by space type' }, |
| 132 | + pageSize: { type: 'number', description: 'Maximum number of spaces to return' }, |
| 133 | + }, |
| 134 | + outputs: { |
| 135 | + messageName: { type: 'string', description: 'Message resource name' }, |
| 136 | + spaceName: { type: 'string', description: 'Space resource name' }, |
| 137 | + threadName: { type: 'string', description: 'Thread resource name' }, |
| 138 | + text: { type: 'string', description: 'Message text that was sent' }, |
| 139 | + createTime: { type: 'string', description: 'Message creation timestamp' }, |
| 140 | + spaces: { type: 'json', description: 'Array of Google Chat space objects' }, |
| 141 | + nextPageToken: { type: 'string', description: 'Token for next page of results' }, |
| 142 | + }, |
| 143 | +} |
0 commit comments