2
0

🧑‍💻 (chat) Introduce startChat and continueChat endpoints

Closes #1030
This commit is contained in:
Baptiste Arnaud
2023-11-13 15:27:36 +01:00
parent 63233eb7ee
commit 084588a086
74 changed files with 28426 additions and 645 deletions

View File

@@ -2,7 +2,7 @@ import {
SessionState,
GoogleSheetsGetOptions,
VariableWithValue,
ReplyLog,
ChatLog,
} from '@typebot.io/schemas'
import { isNotEmpty, byId, isDefined } from '@typebot.io/lib'
import { getAuthenticatedGoogleDoc } from './helpers/getAuthenticatedGoogleDoc'
@@ -18,7 +18,7 @@ export const getRow = async (
options,
}: { outgoingEdgeId?: string; options: GoogleSheetsGetOptions }
): Promise<ExecuteIntegrationResponse> => {
const logs: ReplyLog[] = []
const logs: ChatLog[] = []
const { variables } = state.typebotsQueue[0].typebot
const { sheetId, cellsToExtract, filter, ...parsedOptions } =
deepParseVariables(variables)(options)

View File

@@ -1,7 +1,7 @@
import {
SessionState,
GoogleSheetsInsertRowOptions,
ReplyLog,
ChatLog,
} from '@typebot.io/schemas'
import { parseCellValues } from './helpers/parseCellValues'
import { getAuthenticatedGoogleDoc } from './helpers/getAuthenticatedGoogleDoc'
@@ -17,7 +17,7 @@ export const insertRow = async (
const { variables } = state.typebotsQueue[0].typebot
if (!options.cellsToInsert || !options.sheetId) return { outgoingEdgeId }
const logs: ReplyLog[] = []
const logs: ChatLog[] = []
const doc = await getAuthenticatedGoogleDoc({
credentialsId: options.credentialsId,

View File

@@ -1,7 +1,7 @@
import {
SessionState,
GoogleSheetsUpdateRowOptions,
ReplyLog,
ChatLog,
} from '@typebot.io/schemas'
import { parseCellValues } from './helpers/parseCellValues'
import { getAuthenticatedGoogleDoc } from './helpers/getAuthenticatedGoogleDoc'
@@ -28,7 +28,7 @@ export const updateRow = async (
if (!options.cellsToUpsert || !sheetId || (!referenceCell && !filter))
return { outgoingEdgeId }
const logs: ReplyLog[] = []
const logs: ChatLog[] = []
const doc = await getAuthenticatedGoogleDoc({
credentialsId: options.credentialsId,

View File

@@ -1,5 +1,5 @@
import { isNotEmpty } from '@typebot.io/lib/utils'
import { ChatReply } from '@typebot.io/schemas'
import { ContinueChatResponse } from '@typebot.io/schemas'
import { OpenAIBlock } from '@typebot.io/schemas/features/blocks/integrations/openai'
import { HTTPError } from 'got'
import { ClientOptions, OpenAI } from 'openai'
@@ -10,7 +10,7 @@ type Props = Pick<
> & {
apiKey: string
temperature: number | undefined
currentLogs?: ChatReply['logs']
currentLogs?: ContinueChatResponse['logs']
isRetrying?: boolean
} & Pick<NonNullable<OpenAIBlock['options']>, 'apiVersion' | 'baseUrl'>
@@ -25,9 +25,9 @@ export const executeChatCompletionOpenAIRequest = async ({
currentLogs = [],
}: Props): Promise<{
chatCompletion?: OpenAI.Chat.Completions.ChatCompletion
logs?: ChatReply['logs']
logs?: ContinueChatResponse['logs']
}> => {
const logs: ChatReply['logs'] = currentLogs
const logs: ContinueChatResponse['logs'] = currentLogs
if (messages.length === 0) return { logs }
try {
const config = {

View File

@@ -1,5 +1,5 @@
import { byId, isDefined } from '@typebot.io/lib'
import { ChatReply, SessionState } from '@typebot.io/schemas'
import { ContinueChatResponse, SessionState } from '@typebot.io/schemas'
import { ChatCompletionOpenAIOptions } from '@typebot.io/schemas/features/blocks/integrations/openai'
import { VariableWithUnknowValue } from '@typebot.io/schemas/features/typebot/variable'
import { updateVariablesInSession } from '../../../variables/updateVariablesInSession'
@@ -14,7 +14,7 @@ export const resumeChatCompletion =
}: {
outgoingEdgeId?: string
options: ChatCompletionOpenAIOptions
logs?: ChatReply['logs']
logs?: ContinueChatResponse['logs']
}
) =>
async (message: string, totalTokens?: number) => {

View File

@@ -1,7 +1,7 @@
import { DefaultBotNotificationEmail, render } from '@typebot.io/emails'
import {
AnswerInSessionState,
ReplyLog,
ChatLog,
SendEmailBlock,
SessionState,
SmtpCredentials,
@@ -25,7 +25,7 @@ export const executeSendEmailBlock = async (
state: SessionState,
block: SendEmailBlock
): Promise<ExecuteIntegrationResponse> => {
const logs: ReplyLog[] = []
const logs: ChatLog[] = []
const { options } = block
const { typebot, resultId, answers } = state.typebotsQueue[0]
const isPreview = !resultId
@@ -114,8 +114,8 @@ const sendEmail = async ({
typebot: TypebotInSession
answers: AnswerInSessionState[]
fileUrls?: string | string[]
}): Promise<ReplyLog[] | undefined> => {
const logs: ReplyLog[] = []
}): Promise<ChatLog[] | undefined> => {
const logs: ChatLog[] = []
const { name: replyToName } = parseEmailRecipient(replyTo)
const { host, port, isTlsEnabled, username, password, from } =

View File

@@ -8,7 +8,7 @@ import {
Variable,
WebhookResponse,
KeyValue,
ReplyLog,
ChatLog,
ExecutableWebhook,
AnswerInSessionState,
} from '@typebot.io/schemas'
@@ -34,7 +34,7 @@ export const executeWebhookBlock = async (
state: SessionState,
block: WebhookBlock | ZapierBlock | MakeComBlock | PabblyConnectBlock
): Promise<ExecuteIntegrationResponse> => {
const logs: ReplyLog[] = []
const logs: ChatLog[] = []
const webhook =
block.options?.webhook ??
('webhookId' in block
@@ -142,8 +142,8 @@ const parseWebhookAttributes =
export const executeWebhook = async (
webhook: ParsedWebhook
): Promise<{ response: WebhookResponse; logs?: ReplyLog[] }> => {
const logs: ReplyLog[] = []
): Promise<{ response: WebhookResponse; logs?: ChatLog[] }> => {
const logs: ChatLog[] = []
const { headers, url, method, basicAuth, body, isJson } = webhook
const contentType = headers ? headers['Content-Type'] : undefined

View File

@@ -2,7 +2,7 @@ import { byId } from '@typebot.io/lib'
import {
MakeComBlock,
PabblyConnectBlock,
ReplyLog,
ChatLog,
VariableWithUnknowValue,
WebhookBlock,
ZapierBlock,
@@ -15,7 +15,7 @@ import { updateVariablesInSession } from '../../../variables/updateVariablesInSe
type Props = {
state: SessionState
block: WebhookBlock | ZapierBlock | MakeComBlock | PabblyConnectBlock
logs?: ReplyLog[]
logs?: ChatLog[]
response: {
statusCode: number
data?: unknown

View File

@@ -3,7 +3,7 @@ import {
TypebotLinkBlock,
SessionState,
Variable,
ReplyLog,
ChatLog,
Edge,
typebotInSessionStateSchema,
TypebotInSession,
@@ -19,7 +19,7 @@ export const executeTypebotLink = async (
state: SessionState,
block: TypebotLinkBlock
): Promise<ExecuteLogicResponse> => {
const logs: ReplyLog[] = []
const logs: ChatLog[] = []
const typebotId = block.options?.typebotId
if (!typebotId) {
logs.push({