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
9 changes: 9 additions & 0 deletions bots/bugbuster/bot.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ export default new sdk.BotDefinition({
.describe('List of recently linted issues'),
}),
},
watchedTeams: {
type: 'bot',
schema: sdk.z.object({
teamKeys: sdk.z
.array(sdk.z.string())
.title('Team Keys')
.describe('The keys of the teams for which BugBuster should lint issues'),
}),
},
},
__advanced: {
useLegacyZuiTransformer: true,
Expand Down
9 changes: 7 additions & 2 deletions bots/bugbuster/src/handlers/issue-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { BotLogger } from '@botpress/sdk'
import { Issue } from '@linear/sdk'
import { LinearApi } from 'src/utils/linear-utils'
import * as linlint from '../linear-lint-issue'
import { listTeams } from './teams-manager'
import { Client } from '.botpress'

/**
* @returns The corresponding issue, or `undefined` if the issue is not found or not valid.
Expand All @@ -11,7 +13,9 @@ export async function findIssue(
teamKey: string | undefined,
logger: BotLogger,
eventName: string,
linear: LinearApi
linear: LinearApi,
client: Client,
botId: string
): Promise<Issue | undefined> {
if (!issueNumber || !teamKey) {
logger.error('Missing issueNumber or teamKey in event payload')
Expand All @@ -20,7 +24,8 @@ export async function findIssue(

logger.info(`Linear issue ${eventName} event received`, `${teamKey}-${issueNumber}`)

if (!linear.isTeam(teamKey) || teamKey !== 'SQD') {
const teams = await listTeams(client, botId)
if (!linear.isTeam(teamKey) || !teams.result?.includes(teamKey)) {
logger.error(`Ignoring issue of team "${teamKey}"`)
return
}
Expand Down
2 changes: 1 addition & 1 deletion bots/bugbuster/src/handlers/linear-issue-created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as bp from '.botpress'
export const handleLinearIssueCreated: bp.EventHandlers['linear:issueCreated'] = async (props) => {
const { number: issueNumber, teamKey } = props.event.payload
const linear = await utils.linear.LinearApi.create()
const issue = await findIssue(issueNumber, teamKey, props.logger, 'created', linear)
const issue = await findIssue(issueNumber, teamKey, props.logger, 'created', linear, props.client, props.ctx.botId)

if (!issue) {
return
Expand Down
2 changes: 1 addition & 1 deletion bots/bugbuster/src/handlers/linear-issue-updated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as bp from '.botpress'
export const handleLinearIssueUpdated: bp.EventHandlers['linear:issueUpdated'] = async (props) => {
const { number: issueNumber, teamKey } = props.event.payload
const linear = await utils.linear.LinearApi.create()
const issue = await findIssue(issueNumber, teamKey, props.logger, 'updated', linear)
const issue = await findIssue(issueNumber, teamKey, props.logger, 'updated', linear, props.client, props.ctx.botId)

if (!issue) {
return
Expand Down
51 changes: 49 additions & 2 deletions bots/bugbuster/src/handlers/message-created.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,61 @@
import * as utils from '../utils'
import { addTeam, listTeams, removeTeam } from './teams-manager'
import * as bp from '.botpress'

const MESSAGING_INTEGRATIONS = ['telegram', 'slack']
const COMMAND_LIST_MESSAGE = `Unknown command. Here's a list of possible commands:
/addTeam [teamName]
/removeTeam [teamName]
/listTeams`
const ARGUMENT_REQUIRED_MESSAGE = 'Error: an argument is required with this command.'

export const handleMessageCreated: bp.MessageHandlers['*'] = async (props) => {
const { conversation, message } = props
const { conversation, message, client, ctx } = props
if (!MESSAGING_INTEGRATIONS.includes(conversation.integration)) {
props.logger.info(`Ignoring message from ${conversation.integration}`)
return
}

const botpress = await utils.botpress.BotpressApi.create(props)
await botpress.respondText(message.conversationId, "Hey, I'm BugBuster.")

if (message.type !== 'text') {
await botpress.respondText(conversation.id, COMMAND_LIST_MESSAGE)
return
}

const [command, teamKey] = message.payload.text.trim().split(' ')
if (!command) {
await botpress.respondText(conversation.id, COMMAND_LIST_MESSAGE)
}

switch (command) {
case '/addTeam': {
if (!teamKey) {
await botpress.respondText(conversation.id, ARGUMENT_REQUIRED_MESSAGE)
return
}
const linear = await utils.linear.LinearApi.create()
const result = await addTeam(client, ctx.botId, teamKey, linear)
await botpress.respondText(conversation.id, result.message)
break
}
case '/removeTeam': {
if (!teamKey) {
await botpress.respondText(conversation.id, ARGUMENT_REQUIRED_MESSAGE)
return
}
const result = await removeTeam(client, ctx.botId, teamKey)
await botpress.respondText(conversation.id, result.message)
break
}
case '/listTeams': {
const result = await listTeams(client, ctx.botId)
await botpress.respondText(conversation.id, result.message)
break
}
default: {
await botpress.respondText(conversation.id, COMMAND_LIST_MESSAGE)
break
}
}
}
89 changes: 89 additions & 0 deletions bots/bugbuster/src/handlers/teams-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { LinearApi } from 'src/utils/linear-utils'
import * as bp from '.botpress'

export type Result<T> = {
success: boolean
message: string
result?: T
}

const _getWatchedTeams = async (client: bp.Client, botId: string) => {
return (
await client.getOrSetState({
id: botId,
name: 'watchedTeams',
type: 'bot',
payload: {
teamKeys: [],
},
})
).state.payload.teamKeys
}

const _setWatchedTeams = async (client: bp.Client, botId: string, teamKeys: string[]) => {
await client.setState({
id: botId,
name: 'watchedTeams',
type: 'bot',
payload: {
teamKeys,
},
})
}

export async function addTeam(client: bp.Client, botId: string, key: string, linear: LinearApi): Promise<Result<void>> {
const teamKeys = await _getWatchedTeams(client, botId)
if (teamKeys.includes(key)) {
return {
success: false,
message: `Error: the team with the key '${key}' is already being watched.`,
}
}
if (!linear.isTeam(key)) {
return {
success: false,
message: `Error: the team with the key '${key}' does not exist.`,
}
}

await _setWatchedTeams(client, botId, [...teamKeys, key])
return {
success: true,
message: `Success: the team with the key '${key}' has been added to the watched team list.`,
}
}

export async function removeTeam(client: bp.Client, botId: string, key: string): Promise<Result<void>> {
const teamKeys = await _getWatchedTeams(client, botId)
if (!teamKeys.includes(key)) {
return {
message: `Error: the team with the key '${key}' is not currently being watched.`,
success: false,
}
}

await _setWatchedTeams(
client,
botId,
teamKeys.filter((k) => k !== key)
)
return {
success: false,
message: `Success: the team with the key '${key}' has been removed from the watched team list.`,
}
}

export async function listTeams(client: bp.Client, botId: string): Promise<Result<readonly string[]>> {
const teamKeys = await _getWatchedTeams(client, botId)
if (teamKeys.length === 0) {
return {
success: false,
message: 'You have no watched teams.',
}
}
return {
success: true,
message: teamKeys.join(', '),
result: teamKeys,
}
}
18 changes: 10 additions & 8 deletions integrations/browser/integration.definition.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
/* bplint-disable */
import { IntegrationDefinition } from '@botpress/sdk'
import { actionDefinitions } from 'src/definitions/actions'

export default new IntegrationDefinition({
name: 'browser',
title: 'Browser',
version: '0.8.0',
version: '0.8.1',
description:
'Capture screenshots and retrieve web page content with metadata for automated browsing and data extraction.',
readme: 'hub.md',
icon: 'icon.svg',
actions: actionDefinitions,
secrets: {
SCREENSHOT_API_KEY: {},
FIRECRAWL_API_KEY: {},
LOGO_API_KEY: {},
},
__advanced: {
useLegacyZuiTransformer: true,
SCREENSHOT_API_KEY: {
description: 'ScreenShot key',
},
FIRECRAWL_API_KEY: {
description: 'FireCrawl key',
},
LOGO_API_KEY: {
description: 'Logo key',
},
},
})
1 change: 0 additions & 1 deletion integrations/browser/src/actions/browse-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const getPageContent = async (props: {

try {
const result = await firecrawl.scrape(props.url, {
fastMode: true,
onlyMainContent: true,
maxAge: 60 * 60 * 24 * 7, // 1 week
removeBase64Images: true,
Expand Down
Loading
Loading