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
3 changes: 0 additions & 3 deletions bots/doppel-doer/bot.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ export default new sdk.BotDefinition({
recurringEvents: {},
user: {},
conversation: {},
__advanced: {
useLegacyZuiTransformer: true,
},
})
.addIntegration(todoist, {
alias: 'todoist-src',
Expand Down
3 changes: 0 additions & 3 deletions bots/echo/bot.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ export default new sdk.BotDefinition({
states: {},
events: {},
recurringEvents: {},
__advanced: {
useLegacyZuiTransformer: true,
},
}).addIntegration(chat, { enabled: true, configuration: {} })
3 changes: 0 additions & 3 deletions bots/hello-world/bot.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ export default new sdk.BotDefinition({
},
},
},
__advanced: {
useLegacyZuiTransformer: true,
},
})
.addIntegration(telegram, {
enabled: true,
Expand Down
3 changes: 0 additions & 3 deletions bots/hit-looper/bot.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ export default new sdk.BotDefinition({
},
},
conversation: {},
__advanced: {
useLegacyZuiTransformer: true,
},
})
.addIntegration(chat, {
enabled: true,
Expand Down
6 changes: 1 addition & 5 deletions bots/knowledgiani/bot.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import telegram from './bp_modules/telegram'

type OpenAiModel = sdk.z.infer<typeof openai.definition.entities.modelRef.schema>

export default new sdk.BotDefinition({
__advanced: {
useLegacyZuiTransformer: true,
},
})
export default new sdk.BotDefinition({})
.addIntegration(telegram, {
enabled: true,
configuration: {
Expand Down
3 changes: 0 additions & 3 deletions bots/notionaut/bot.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ export default new sdk.BotDefinition({
recurringEvents: {},
user: {},
conversation: {},
__advanced: {
useLegacyZuiTransformer: true,
},
})
.addIntegration(chat, {
enabled: true,
Expand Down
3 changes: 0 additions & 3 deletions bots/sheetzy/bot.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ export default new sdk.BotDefinition({
},
},
},
__advanced: {
useLegacyZuiTransformer: true,
},
})
.addIntegration(gsheets, {
enabled: true,
Expand Down
6 changes: 1 addition & 5 deletions bots/sinlin/bot.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import chat from './bp_modules/chat'
import linear from './bp_modules/linear'
import synchronizer from './bp_modules/synchronizer'

export default new sdk.BotDefinition({
__advanced: {
useLegacyZuiTransformer: true,
},
})
export default new sdk.BotDefinition({})
.addIntegration(linear, {
enabled: true,
configurationType: 'apiKey',
Expand Down
3 changes: 0 additions & 3 deletions bots/synchrotron/bot.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ export default new sdk.BotDefinition({
recurringEvents: {},
user: {},
conversation: {},
__advanced: {
useLegacyZuiTransformer: true,
},
})
.addIntegration(chat, {
enabled: true,
Expand Down
5 changes: 3 additions & 2 deletions integrations/sunco/integration.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { sentry as sentryHelpers } from '@botpress/sdk-addons'
import proactiveConversation from 'bp_modules/proactive-conversation'
import proactiveUser from 'bp_modules/proactive-user'
import typingIndicator from 'bp_modules/typing-indicator'
import { events } from './src/definitions'

export default new IntegrationDefinition({
name: 'sunco',
version: '1.0.4',
version: '1.1.1',
title: 'Sunshine Conversations',
description: 'Give your bot access to a powerful omnichannel messaging platform.',
icon: 'icon.svg',
Expand Down Expand Up @@ -43,7 +44,7 @@ export default new IntegrationDefinition({
},
},
actions: {},
events: {},
events,
secrets: sentryHelpers.COMMON_SECRET_NAMES,
user: {
tags: {
Expand Down
13 changes: 13 additions & 0 deletions integrations/sunco/src/definitions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { z, IntegrationDefinitionProps } from '@botpress/sdk'

export const events = {
conversationCreated: {
title: 'Conversation Created',
description: 'This event occurs when a conversation is created',
schema: z.object({
userId: z.string().title('User ID').describe('The Botpress user ID'),
conversationId: z.string().title('Conversation ID').describe('The Botpress conversation ID'),
}),
ui: {},
},
} satisfies IntegrationDefinitionProps['events']
42 changes: 42 additions & 0 deletions integrations/sunco/src/events/conversation-created.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { ConversationCreateEvent } from '../messaging-events'
import { Logger, Client } from '.botpress'

export const executeConversationCreated = async (props: {
event: ConversationCreateEvent
client: Client
logger: Logger
}) => {
const { event, client, logger } = props
const payload = event.payload

const conversationId = payload.conversation?.id
const userId = payload.user?.id

if (!conversationId?.length || !userId?.length) {
logger.forBot().warn('conversation:create event missing conversation ID or user ID')
return
}

const { conversation } = await client.getOrCreateConversation({
channel: 'channel',
tags: {
id: conversationId,
},
})

const { user } = await client.getOrCreateUser({
tags: {
id: userId,
},
})

await client.createEvent({
type: 'conversationCreated',
conversationId: conversation.id,
userId: user.id,
payload: {
userId: user.id,
conversationId: conversation.id,
},
})
}
34 changes: 12 additions & 22 deletions integrations/sunco/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { RuntimeError } from '@botpress/client'
import { sentry as sentryHelpers } from '@botpress/sdk-addons'
import { executeConversationCreated } from './events/conversation-created'
import { register, unregister } from './setup'
import { createClient } from './sunshine-api'
import * as bp from '.botpress'
const SunshineConversationsClient = require('sunshine-conversations-client')

Expand Down Expand Up @@ -36,8 +39,8 @@ const POSTBACK_PREFIX = 'postback::'
const SAY_PREFIX = 'say::'

const integration = new bp.Integration({
register: async () => {},
unregister: async () => {},
register,
unregister,
actions: {
startTypingIndicator: async ({ client, ctx, input }) => {
const { conversationId } = input
Expand Down Expand Up @@ -151,7 +154,7 @@ const integration = new bp.Integration({
},
},
},
handler: async ({ req, client }) => {
handler: async ({ req, client, logger }) => {
if (!req.body) {
console.warn('Handler received an empty body')
return
Expand All @@ -160,7 +163,9 @@ const integration = new bp.Integration({
const data = JSON.parse(req.body)

for (const event of data.events) {
if (event.type !== 'conversation:message') {
if (event.type === 'conversation:create') {
await executeConversationCreated({ event, client, logger })
} else if (event.type !== 'conversation:message') {
console.warn('Received an event that is not a message')
continue
}
Expand Down Expand Up @@ -275,21 +280,6 @@ function getConversationId(conversation: SendMessageProps['conversation']) {
return conversationId
}

function createClient(keyId: string, keySecret: string) {
const client = new SunshineConversationsClient.ApiClient()
const auth = client.authentications['basicAuth']
auth.username = keyId
auth.password = keySecret

return {
messages: new SunshineConversationsClient.MessagesApi(client),
activity: new SunshineConversationsClient.ActivitiesApi(client),
apps: new SunshineConversationsClient.AppsApi(client),
conversations: new SunshineConversationsClient.ConversationsApi(client),
users: new SunshineConversationsClient.UsersApi(client),
}
}

type SendMessageProps = Pick<bp.AnyMessageProps, 'ctx' | 'conversation' | 'ack'>

async function sendMessage({ conversation, ctx, ack }: SendMessageProps, payload: any) {
Expand All @@ -303,7 +293,7 @@ async function sendMessage({ conversation, ctx, ack }: SendMessageProps, payload

const { messages } = await client.messages.postMessage(ctx.configuration.appId, getConversationId(conversation), data)

const message = messages[0]
const message = messages?.[0]

if (!message) {
throw new Error('Message not sent')
Expand All @@ -327,13 +317,13 @@ async function sendActivity({ client, ctx, conversationId, typingStatus, markAsR
const { appId, keyId, keySecret } = ctx.configuration
const suncoClient = createClient(keyId, keySecret)
if (markAsRead) {
await suncoClient.activity.postActivity(appId, suncoConversationId, {
await suncoClient.activities.postActivity(appId, suncoConversationId, {
type: 'conversation:read',
author: { type: 'business' },
})
}
if (typingStatus) {
await suncoClient.activity.postActivity(appId, suncoConversationId, {
await suncoClient.activities.postActivity(appId, suncoConversationId, {
type: `typing:${typingStatus}`,
author: { type: 'business' },
})
Expand Down
29 changes: 29 additions & 0 deletions integrations/sunco/src/messaging-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Types for Sunshine Conversations webhook events
* Based on the Sunshine Conversations API webhook structure
*/
export type ConversationCreateEvent = {
type: 'conversation:create'
payload: {
conversation?: {
id: string
type?: string
brandId?: string
activeSwitchboardIntegration?: {
id: string
name: string
integrationId: string
integrationType: string
}
}
user?: {
id: string
authenticated?: boolean
}
creationReason?: string
source?: {
type: string
integrationId: string
}
}
}
2 changes: 2 additions & 0 deletions integrations/sunco/src/setup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { register } from './register'
export { unregister } from './unregister'
23 changes: 23 additions & 0 deletions integrations/sunco/src/setup/register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { RuntimeError } from '@botpress/client'
import { getNetworkErrorDetails } from 'src/util'
import * as bp from '../../.botpress'
import { createClient } from '../sunshine-api'

export const register: bp.IntegrationProps['register'] = async ({ ctx, logger }) => {
logger.forBot().info('Starting Sunshine Conversations integration registration...')

const suncoClient = createClient(ctx.configuration.keyId, ctx.configuration.keySecret)

logger.forBot().info('Verifying credentials...')
try {
const app = await suncoClient.apps.getApp(ctx.configuration.appId)
logger.forBot().info('✅ Credentials verified successfully. App details:', JSON.stringify(app, null, 2))
} catch (thrown: unknown) {
const details = getNetworkErrorDetails(thrown)
if (details) {
throw new RuntimeError(`Invalid credentials: ${details?.message}`)
}
const errMsg = thrown instanceof Error ? thrown.message : String(thrown)
throw new RuntimeError(errMsg)
}
}
3 changes: 3 additions & 0 deletions integrations/sunco/src/setup/unregister.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as bp from '../../.botpress'

export const unregister: bp.IntegrationProps['unregister'] = async ({}) => {}
Loading
Loading