Skip to content

Commit

Permalink
fix(hooks): send events to core on bot mount and unmount (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentlp committed Mar 28, 2022
1 parent a7ddbd7 commit fbb4f61
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/studio-be/src/core/app/core-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export const coreActions = {
notifyFlowChanges: async (payload) => {
await coreClient?.post('/notifyFlowChange', payload)
},
unmountBot: async (botId: string) => {
await coreClient?.post('/unmountBot', { botId })
},
mountBot: async (botId: string) => {
await coreClient?.post('/mountBot', { botId })
},
invalidateCmsForBot: async (botId: string) => {
await coreClient?.post('/invalidateCmsForBot', { botId })
},
Expand Down
10 changes: 9 additions & 1 deletion packages/studio-be/src/core/bots/bot-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,19 @@ export class BotService {
await this.configProvider.setBotConfig(botId, newConfig)

if (!updatedBot.disabled) {
if (this.isBotMounted(botId)) {
const isBotMounted = this.isBotMounted(botId)
if (isBotMounted) {
// we need to remount the bot to update the config
await this.unmountBot(botId)
}

await this.mountBot(botId)

// Only send a mount bot request to the core
// if the bot was unmounted
if (!isBotMounted) {
await coreActions.mountBot(botId)
}
}

if (actualBot.defaultLanguage !== updatedBot.defaultLanguage) {
Expand All @@ -164,6 +171,7 @@ export class BotService {

if (!actualBot.disabled && updatedBot.disabled) {
await this.unmountBot(botId)
await coreActions.unmountBot(botId)
}
}

Expand Down

0 comments on commit fbb4f61

Please sign in to comment.