Skip to content

Commit 373e21e

Browse files
authored
feat(plugins/conversation-insights): interval between AI insight updates is now configurable (botpress#14684)
1 parent b3df2e6 commit 373e21e

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

plugins/conversation-insights/plugin.definition.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ import { PluginDefinition, z } from '@botpress/sdk'
22

33
export default new PluginDefinition({
44
name: 'conversation-insights',
5-
version: '0.4.8',
5+
version: '0.5.0',
66
configuration: {
77
schema: z.object({
88
aiEnabled: z.boolean().default(true).describe('Set to true to enable title, summary and sentiment ai generation'),
9+
aiGenerationInterval: z
10+
.number()
11+
.optional()
12+
.title('AI Generation Interval')
13+
.describe('Interval in minutes between AI insight generations'),
914
}),
1015
},
1116
conversation: {

plugins/conversation-insights/src/handlers/after-incoming-message.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ import * as bp from '.botpress'
44
const HOUR_MILLISECONDS = 60 * 60 * 1000
55

66
export const handleAfterIncomingMessage: bp.HookHandlers['after_incoming_message']['*'] = async (props) => {
7-
const conversation = await props.conversations['*']['*'].getById({ id: props.data.conversationId })
7+
const { conversations, configuration, events, data } = props
8+
const conversation = await conversations['*']['*'].getById({ id: data.conversationId })
89
await onNewMessageHandler.onNewMessage({ ...props, conversation })
910

10-
if (props.configuration.aiEnabled) {
11-
const events = await props.events.updateAiInsight.list({ status: 'scheduled' }).take(1)
12-
if (events.length === 0) {
13-
const dateTime = new Date(Date.now() + HOUR_MILLISECONDS).toISOString()
14-
await props.events.updateAiInsight.schedule({}, { dateTime })
11+
if (configuration.aiEnabled) {
12+
const updateAiEvents = await events.updateAiInsight.list({ status: 'scheduled' }).take(1)
13+
if (updateAiEvents.length === 0) {
14+
const interval = configuration.aiGenerationInterval
15+
? configuration.aiGenerationInterval * 60 * 1000
16+
: HOUR_MILLISECONDS
17+
const dateTime = new Date(Date.now() + interval).toISOString()
18+
await events.updateAiInsight.schedule({}, { dateTime })
1519
}
1620
}
1721

0 commit comments

Comments
 (0)