2
0
Files
bot/packages/embeds/js/src/queries/getInitialChatReplyQuery.ts
2023-05-25 10:32:35 +02:00

34 lines
851 B
TypeScript

import { InitialChatReply } from '@/types'
import { guessApiHost } from '@/utils/guessApiHost'
import type { SendMessageInput, StartParams } from '@typebot.io/schemas'
import { isNotEmpty, sendRequest } from '@typebot.io/lib'
export async function getInitialChatReplyQuery({
typebot,
isPreview,
apiHost,
prefilledVariables,
startGroupId,
resultId,
}: StartParams & {
apiHost?: string
}) {
if (!typebot)
throw new Error('Typebot ID is required to get initial messages')
return sendRequest<InitialChatReply>({
method: 'POST',
url: `${isNotEmpty(apiHost) ? apiHost : guessApiHost()}/api/v1/sendMessage`,
body: {
startParams: {
isPreview,
typebot,
prefilledVariables,
startGroupId,
resultId,
isStreamEnabled: true,
},
} satisfies SendMessageInput,
})
}