Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions bots/sheetzy/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const set: Command = async (props, args) => {
const values = parseResult.data

await props.client.callAction({
type: 'gsheets:updateValues',
type: 'gsheets:setValues',
input: {
range,
values: _stringifyValues(values),
Expand All @@ -80,11 +80,32 @@ const set: Command = async (props, args) => {
const append: Command = async (props, args) => {
const utils = new ApiUtils(props)

const [range, ...body] = args
const [firstArg, secondArg, ...body] = args
const jsonValues = body.join(' ')

if (!range) {
throw new CommandError('Missing range')
if (!firstArg) {
throw new CommandError('Missing startColumn')
}

let sheetName: string | undefined
let startColumn: string

if (secondArg && !secondArg.startsWith('[') && !secondArg.startsWith('{')) {
sheetName = firstArg
startColumn = secondArg
} else {
startColumn = firstArg
if (firstArg.includes('!')) {
const parts = firstArg.split('!')
if (parts.length > 1 && parts[1]) {
sheetName = parts[0]
startColumn = parts[1]
}
}
}

if (!startColumn) {
throw new CommandError('Missing startColumn')
}

const parseResult = valuesSchema.safeParse(JSON.parse(jsonValues))
Expand All @@ -97,7 +118,8 @@ const append: Command = async (props, args) => {
await props.client.callAction({
type: 'gsheets:appendValues',
input: {
range,
sheetName,
startColumn,
values: _stringifyValues(values),
},
})
Expand Down
48 changes: 47 additions & 1 deletion integrations/gmail/definitions/actions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
import * as sdk from '@botpress/sdk'
import { changeMessageLabels } from './actions/change-message-labels'
import { createDraft } from './actions/create-draft'
import { createLabel } from './actions/create-label'
import { deleteDraft } from './actions/delete-draft'
import { deleteLabel } from './actions/delete-label'
import { deleteMessage } from './actions/delete-message'
import { getDraft } from './actions/get-draft'
import { getLabel } from './actions/get-label'
import { getMessageAttachment } from './actions/get-message-attachment'
import { getMessageAttachmentFromMail } from './actions/get-message-attachment-from-mail'
import { getThread } from './actions/get-thread'
import { listDrafts } from './actions/list-drafts'
import { listLabels } from './actions/list-labels'
import { listThreads } from './actions/list-threads'
import { sendDraft } from './actions/send-draft'
import { trashMessage } from './actions/trash-message'
import { trashThread } from './actions/trash-thread'
import { untrashMessage } from './actions/untrash-message'
import { untrashThread } from './actions/untrash-thread'
import { updateDraft } from './actions/update-draft'
import { updateLabel } from './actions/update-label'

export const actions = {} as const satisfies sdk.IntegrationDefinitionProps['actions']
export const actions = {
deleteMessage,
trashMessage,
untrashMessage,
changeMessageLabels,
getMessageAttachment,
getMessageAttachmentFromMail,

listThreads,
getThread,
trashThread,
untrashThread,

listLabels,
getLabel,
createLabel,
deleteLabel,
updateLabel,

listDrafts,
getDraft,
createDraft,
deleteDraft,
updateDraft,
sendDraft,
} as const satisfies sdk.IntegrationDefinitionProps['actions']
25 changes: 25 additions & 0 deletions integrations/gmail/definitions/actions/change-message-labels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { z } from '@botpress/sdk'
import { ActionDef } from './types'

export const changeMessageLabels = {
title: 'Change Message Labels',
description: 'Modifies the labels on the specified message by adding or removing label IDs.',
input: {
schema: z.object({
id: z.string().title('Message ID').describe('The ID of the message to modify.'),
addLabelIds: z
.array(z.string())
.optional()
.title('Add Label IDs')
.describe('A list of IDs of labels to add to this message.'),
removeLabelIds: z
.array(z.string())
.optional()
.title('Remove Label IDs')
.describe('A list of IDs of labels to remove from this message.'),
}),
},
output: {
schema: z.object({}).title('Empty').describe('Empty output'),
},
} as const satisfies ActionDef
27 changes: 27 additions & 0 deletions integrations/gmail/definitions/actions/create-draft.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { z } from '@botpress/sdk'
import { ActionDef } from './types'

export const createDraft = {
title: 'Create Draft',
description: 'Creates a new draft with the specified email content.',
input: {
schema: z.object({
to: z.string().title('To').describe('The recipient email address.'),
subject: z.string().title('Subject').describe('The subject of the email.'),
body: z.string().title('Body').describe('The body content of the email.'),
}),
},
output: {
schema: z.object({
id: z.string().optional().title('Draft ID').describe('The immutable ID of the created draft.'),
message: z
.object({
id: z.string().optional().describe('The ID of the message.'),
threadId: z.string().optional().describe('The ID of the thread.'),
})
.optional()
.title('Message')
.describe('The message content of the draft.'),
}),
},
} as const satisfies ActionDef
19 changes: 19 additions & 0 deletions integrations/gmail/definitions/actions/create-label.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { z } from '@botpress/sdk'
import { ActionDef } from './types'

export const createLabel = {
title: 'Create Label',
description: "Creates a new label in the user's mailbox.",
input: {
schema: z.object({
name: z.string().title('Name').describe('The display name of the label to create.'),
}),
},
output: {
schema: z.object({
id: z.string().optional().title('Label ID').describe('The immutable ID of the created label.'),
name: z.string().optional().title('Name').describe('The display name of the label.'),
type: z.string().optional().title('Type').describe('The owner type for the label (system or user).'),
}),
},
} as const satisfies ActionDef
15 changes: 15 additions & 0 deletions integrations/gmail/definitions/actions/delete-draft.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { z } from '@botpress/sdk'
import { ActionDef } from './types'

export const deleteDraft = {
title: 'Delete Draft',
description: 'Immediately and permanently deletes the specified draft. This operation cannot be undone.',
input: {
schema: z.object({
id: z.string().title('Draft ID').describe('The ID of the draft to delete.'),
}),
},
output: {
schema: z.object({}).title('Empty').describe('Empty output'),
},
} as const satisfies ActionDef
16 changes: 16 additions & 0 deletions integrations/gmail/definitions/actions/delete-label.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { z } from '@botpress/sdk'
import { ActionDef } from './types'

export const deleteLabel = {
title: 'Delete Label',
description:
'Immediately and permanently deletes the specified label. Messages and threads are not deleted, they simply lose this label.',
input: {
schema: z.object({
id: z.string().title('Label ID').describe('The ID of the label to delete.'),
}),
},
output: {
schema: z.object({}).title('Empty').describe('Empty output'),
},
} as const satisfies ActionDef
16 changes: 16 additions & 0 deletions integrations/gmail/definitions/actions/delete-message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { z } from '@botpress/sdk'
import { ActionDef } from './types'

export const deleteMessage = {
title: 'Delete Message',
description:
'Immediately and permanently deletes the specified message using its ID. This operation cannot be undone. Prefer messages.trash instead',
input: {
schema: z.object({
id: z.string().title('Message ID').describe('The ID of the message to delete.'),
}),
},
output: {
schema: z.object({}).title('Empty').describe('Empty output'),
},
} as const satisfies ActionDef
27 changes: 27 additions & 0 deletions integrations/gmail/definitions/actions/get-draft.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { z } from '@botpress/sdk'
import { ActionDef } from './types'

export const getDraft = {
title: 'Get Draft',
description: 'Gets the specified draft by its ID.',
input: {
schema: z.object({
id: z.string().title('Draft ID').describe('The ID of the draft to retrieve.'),
}),
},
output: {
schema: z.object({
id: z.string().optional().title('Draft ID').describe('The immutable ID of the draft.'),
message: z
.object({
id: z.string().optional().describe('The ID of the message.'),
threadId: z.string().optional().describe('The ID of the thread.'),
labelIds: z.array(z.string()).optional().describe('List of label IDs applied to the draft message.'),
snippet: z.string().optional().describe('A short part of the message text.'),
})
.optional()
.title('Message')
.describe('The message content of the draft.'),
}),
},
} as const satisfies ActionDef
57 changes: 57 additions & 0 deletions integrations/gmail/definitions/actions/get-label.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { z } from '@botpress/sdk'
import { ActionDef } from './types'

export const getLabel = {
title: 'Get Label',
description: 'Gets the specified label by its ID.',
input: {
schema: z.object({
id: z.string().title('Label ID').describe('The ID of the label to retrieve.'),
}),
},
output: {
schema: z.object({
id: z.string().optional().title('Label ID').describe('The immutable ID of the label.'),
name: z.string().optional().title('Name').describe('The display name of the label.'),
type: z.string().optional().title('Type').describe('The owner type for the label (system or user).'),
messageListVisibility: z
.string()
.optional()
.title('Message List Visibility')
.describe('The visibility of messages with this label in the message list.'),
labelListVisibility: z
.string()
.optional()
.title('Label List Visibility')
.describe('The visibility of the label in the label list.'),
messagesTotal: z
.number()
.optional()
.title('Messages Total')
.describe('The total number of messages with the label.'),
messagesUnread: z
.number()
.optional()
.title('Messages Unread')
.describe('The number of unread messages with the label.'),
threadsTotal: z
.number()
.optional()
.title('Threads Total')
.describe('The total number of threads with the label.'),
threadsUnread: z
.number()
.optional()
.title('Threads Unread')
.describe('The number of unread threads with the label.'),
color: z
.object({
backgroundColor: z.string().optional().describe('The background color.'),
textColor: z.string().optional().describe('The text color.'),
})
.optional()
.title('Color')
.describe('The color to assign to the label.'),
}),
},
} as const satisfies ActionDef
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { z } from '@botpress/sdk'
import { attachmentSchema } from './get-message-attachment'
import { ActionDef } from './types'

export const getMessageAttachmentFromMail = {
title: 'Get Message Attachment From Mail',
description: 'Gets the first attachment from a message by automatically finding the attachment ID from the message.',
input: {
schema: z.object({
messageId: z.string().title('Message ID').describe('The ID of the message containing the attachment.'),
}),
},
output: {
schema: z.object({
attachment: attachmentSchema,
}),
},
} as const satisfies ActionDef
37 changes: 37 additions & 0 deletions integrations/gmail/definitions/actions/get-message-attachment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { z } from '@botpress/sdk'
import { ActionDef } from './types'

export const attachmentSchema = z
.object({
size: z.number().nullable().optional().title('Size').describe('The size of the attachment in bytes.'),
data: z
.string()
.nullable()
.optional()
.title('Data')
.describe('The body data of a MIME message part as a base64url encoded string.'),
attachmentId: z
.string()
.nullable()
.optional()
.title('Attachment ID')
.describe('The immutable ID of the attachment.'),
})
.title('Attachment')
.describe('The attachment retrieved from the message.')

export const getMessageAttachment = {
title: 'Get Message Attachment',
description: 'Gets the specified message attachment by its ID.',
input: {
schema: z.object({
messageId: z.string().title('Message ID').describe('The ID of the message containing the attachment.'),
attachmentId: z.string().title('Attachment ID').describe('The ID of the attachment to retrieve.'),
}),
},
output: {
schema: z.object({
attachment: attachmentSchema,
}),
},
} as const satisfies ActionDef
Loading
Loading