28
packages/js/src/queries/getInitialChatReplyQuery.ts
Normal file
28
packages/js/src/queries/getInitialChatReplyQuery.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { InitialChatReply, SendMessageInput, StartParams } from 'models'
|
||||
import { getViewerUrl, sendRequest } from 'utils'
|
||||
|
||||
export async function getInitialChatReplyQuery({
|
||||
typebotId,
|
||||
isPreview,
|
||||
apiHost,
|
||||
prefilledVariables,
|
||||
}: StartParams & {
|
||||
apiHost?: string
|
||||
}) {
|
||||
if (!typebotId)
|
||||
throw new Error('Typebot ID is required to get initial messages')
|
||||
|
||||
const response = await sendRequest<InitialChatReply>({
|
||||
method: 'POST',
|
||||
url: `${apiHost ?? getViewerUrl()}/api/v1/sendMessage`,
|
||||
body: {
|
||||
startParams: {
|
||||
isPreview,
|
||||
typebotId,
|
||||
prefilledVariables,
|
||||
},
|
||||
} satisfies SendMessageInput,
|
||||
})
|
||||
|
||||
return response.data
|
||||
}
|
15
packages/js/src/queries/sendMessageQuery.ts
Normal file
15
packages/js/src/queries/sendMessageQuery.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { ChatReply, SendMessageInput } from 'models'
|
||||
import { getViewerUrl, sendRequest } from 'utils'
|
||||
|
||||
export async function sendMessageQuery({
|
||||
apiHost,
|
||||
...body
|
||||
}: SendMessageInput & { apiHost?: string }) {
|
||||
const response = await sendRequest<ChatReply>({
|
||||
method: 'POST',
|
||||
url: `${apiHost ?? getViewerUrl()}/api/v1/sendMessage`,
|
||||
body,
|
||||
})
|
||||
|
||||
return response.data
|
||||
}
|
Reference in New Issue
Block a user