Skip to content

Commit

Permalink
馃悰 (whatsapp) Fix image or video bubble before choice input
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Feb 19, 2024
1 parent e783bb4 commit 18c0445
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/bot-engine/whatsapp/sendChatReplyToWhatsApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { computeTypingDuration } from '../computeTypingDuration'
import { continueBotFlow } from '../continueBotFlow'
import { InputBlockType } from '@typebot.io/schemas/features/blocks/inputs/constants'
import { defaultSettings } from '@typebot.io/schemas/features/typebot/settings/constants'
import { BubbleBlockType } from '@typebot.io/schemas/features/blocks/bubbles/constants'

// Media can take some time to be delivered. This make sure we don't send a message before the media is delivered.
const messageAfterMediaTimeout = 5000
Expand All @@ -39,7 +40,10 @@ export const sendChatReplyToWhatsApp = async ({
credentials,
state,
}: Props): Promise<void> => {
const messagesBeforeInput = isLastMessageIncludedInInput(input)
const messagesBeforeInput = isLastMessageIncludedInInput(
input,
messages.at(-1)
)
? messages.slice(0, -1)
: messages

Expand Down Expand Up @@ -202,10 +206,14 @@ const getTypingDuration = ({
}

const isLastMessageIncludedInInput = (
input: ContinueChatResponse['input']
input: ContinueChatResponse['input'],
lastMessage?: ContinueChatResponse['messages'][number]
): boolean => {
if (isNotDefined(input)) return false
return input.type === InputBlockType.CHOICE
return (
input.type === InputBlockType.CHOICE &&
(!lastMessage || lastMessage.type === BubbleBlockType.TEXT)
)
}

const executeClientSideAction =
Expand Down

0 comments on commit 18c0445

Please sign in to comment.