mirror of
https://github.com/baptisteArno/typebot.io.git
synced 2026-06-13 21:02:56 +08:00
💚 Fix lint
This commit is contained in:
parent
8f37e6520d
commit
433fcc08f0
@ -4,37 +4,55 @@ import type {
|
||||
PaymentInputBlock,
|
||||
PaymentInputRuntimeOptions,
|
||||
} from "@typebot.io/blocks-inputs/payment/schema";
|
||||
import type { SessionState } from "@typebot.io/chat-session/schemas";
|
||||
import { decrypt } from "@typebot.io/credentials/decrypt";
|
||||
import { getCredentials } from "@typebot.io/credentials/getCredentials";
|
||||
import type { StripeCredentials } from "@typebot.io/credentials/schemas";
|
||||
import type { SessionStore } from "@typebot.io/runtime-session-store";
|
||||
import { parseVariables } from "@typebot.io/variables/parseVariables";
|
||||
import type { Variable } from "@typebot.io/variables/schemas";
|
||||
import Stripe from "stripe";
|
||||
|
||||
export const computePaymentInputRuntimeOptions = (
|
||||
options: PaymentInputBlock["options"],
|
||||
{ sessionStore, state }: { sessionStore: SessionStore; state: SessionState },
|
||||
) => createStripePaymentIntent(options, { sessionStore, state });
|
||||
{
|
||||
sessionStore,
|
||||
variables,
|
||||
isPreview,
|
||||
workspaceId,
|
||||
}: {
|
||||
sessionStore: SessionStore;
|
||||
variables: Variable[];
|
||||
isPreview: boolean;
|
||||
workspaceId: string;
|
||||
},
|
||||
) =>
|
||||
createStripePaymentIntent(options, {
|
||||
sessionStore,
|
||||
variables,
|
||||
isPreview,
|
||||
workspaceId,
|
||||
});
|
||||
|
||||
const createStripePaymentIntent = async (
|
||||
options: PaymentInputBlock["options"],
|
||||
{ sessionStore, state }: { sessionStore: SessionStore; state: SessionState },
|
||||
{
|
||||
sessionStore,
|
||||
variables,
|
||||
isPreview,
|
||||
workspaceId,
|
||||
}: {
|
||||
sessionStore: SessionStore;
|
||||
variables: Variable[];
|
||||
isPreview: boolean;
|
||||
workspaceId: string;
|
||||
},
|
||||
): Promise<PaymentInputRuntimeOptions> => {
|
||||
const {
|
||||
resultId,
|
||||
typebot: { variables },
|
||||
} = state.typebotsQueue[0];
|
||||
const isPreview = !resultId;
|
||||
if (!options?.credentialsId)
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Missing credentialsId",
|
||||
});
|
||||
const stripeKeys = await getStripeInfo(
|
||||
options.credentialsId,
|
||||
state.workspaceId,
|
||||
);
|
||||
const stripeKeys = await getStripeInfo(options.credentialsId, workspaceId);
|
||||
if (!stripeKeys)
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
|
||||
@ -27,7 +27,7 @@ import type { ForgedBlock } from "@typebot.io/forge-repository/schemas";
|
||||
import { getBlockById } from "@typebot.io/groups/helpers/getBlockById";
|
||||
import type { Group } from "@typebot.io/groups/schemas";
|
||||
import { parseUnknownError } from "@typebot.io/lib/parseUnknownError";
|
||||
import { byId, isDefined } from "@typebot.io/lib/utils";
|
||||
import { byId, isDefined, isNotDefined } from "@typebot.io/lib/utils";
|
||||
import type { AnswerInSessionState } from "@typebot.io/results/schemas/answers";
|
||||
import type { SessionStore } from "@typebot.io/runtime-session-store";
|
||||
import { defaultSystemMessages } from "@typebot.io/settings/constants";
|
||||
@ -624,7 +624,12 @@ const parseRetryMessage = async (
|
||||
},
|
||||
},
|
||||
],
|
||||
input: await formatInputForChatResponse(block, { state, sessionStore }),
|
||||
input: await formatInputForChatResponse(block, {
|
||||
variables: state.typebotsQueue[0].typebot.variables,
|
||||
isPreview: isNotDefined(state.typebotsQueue[0].resultId),
|
||||
workspaceId: state.workspaceId,
|
||||
sessionStore,
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -4,9 +4,9 @@ import type {
|
||||
ContinueChatResponse,
|
||||
RuntimeOptions,
|
||||
} from "@typebot.io/chat-api/schemas";
|
||||
import type { SessionState } from "@typebot.io/chat-session/schemas";
|
||||
import type { SessionStore } from "@typebot.io/runtime-session-store";
|
||||
import { deepParseVariables } from "@typebot.io/variables/deepParseVariables";
|
||||
import type { Variable } from "@typebot.io/variables/schemas";
|
||||
import { injectVariableValuesInCardsBlock } from "./blocks/cards/injectVariableValuesInCardsBlock";
|
||||
import { injectVariableValuesInButtonsInputBlock } from "./blocks/inputs/buttons/injectVariableValuesInButtonsInputBlock";
|
||||
import { parseDateInput } from "./blocks/inputs/date/parseDateInput";
|
||||
@ -16,18 +16,28 @@ import { getPrefilledInputValue } from "./getPrefilledValue";
|
||||
|
||||
export const formatInputForChatResponse = async (
|
||||
block: InputBlock,
|
||||
{ state, sessionStore }: { state: SessionState; sessionStore: SessionStore },
|
||||
{
|
||||
variables,
|
||||
sessionStore,
|
||||
isPreview,
|
||||
workspaceId,
|
||||
}: {
|
||||
variables: Variable[];
|
||||
sessionStore: SessionStore;
|
||||
isPreview: boolean;
|
||||
workspaceId: string;
|
||||
},
|
||||
): Promise<ContinueChatResponse["input"]> => {
|
||||
switch (block.type) {
|
||||
case InputBlockType.CHOICE: {
|
||||
return injectVariableValuesInButtonsInputBlock(block, {
|
||||
state,
|
||||
variables,
|
||||
sessionStore,
|
||||
});
|
||||
}
|
||||
case InputBlockType.PICTURE_CHOICE: {
|
||||
return injectVariableValuesInPictureChoiceBlock(block, {
|
||||
variables: state.typebotsQueue[0].typebot.variables,
|
||||
variables,
|
||||
sessionStore,
|
||||
});
|
||||
}
|
||||
@ -35,19 +45,17 @@ export const formatInputForChatResponse = async (
|
||||
return deepParseVariables(
|
||||
{
|
||||
...block,
|
||||
prefilledValue: getPrefilledInputValue(
|
||||
state.typebotsQueue[0].typebot.variables,
|
||||
)(block),
|
||||
prefilledValue: getPrefilledInputValue(variables)(block),
|
||||
},
|
||||
{
|
||||
variables: state.typebotsQueue[0].typebot.variables,
|
||||
variables,
|
||||
sessionStore,
|
||||
},
|
||||
);
|
||||
}
|
||||
case InputBlockType.DATE: {
|
||||
return parseDateInput(block, {
|
||||
variables: state.typebotsQueue[0].typebot.variables,
|
||||
variables,
|
||||
sessionStore,
|
||||
});
|
||||
}
|
||||
@ -55,19 +63,17 @@ export const formatInputForChatResponse = async (
|
||||
return deepParseVariables(
|
||||
{
|
||||
...block,
|
||||
prefilledValue: getPrefilledInputValue(
|
||||
state.typebotsQueue[0].typebot.variables,
|
||||
)(block),
|
||||
prefilledValue: getPrefilledInputValue(variables)(block),
|
||||
},
|
||||
{
|
||||
variables: state.typebotsQueue[0].typebot.variables,
|
||||
variables,
|
||||
sessionStore,
|
||||
},
|
||||
);
|
||||
}
|
||||
case InputBlockType.CARDS: {
|
||||
return injectVariableValuesInCardsBlock(block, {
|
||||
variables: state.typebotsQueue[0].typebot.variables,
|
||||
variables,
|
||||
sessionStore,
|
||||
});
|
||||
}
|
||||
@ -77,14 +83,14 @@ export const formatInputForChatResponse = async (
|
||||
...block,
|
||||
runtimeOptions: await computeRuntimeOptions(block, {
|
||||
sessionStore,
|
||||
state,
|
||||
variables,
|
||||
isPreview,
|
||||
workspaceId,
|
||||
}),
|
||||
prefilledValue: getPrefilledInputValue(
|
||||
state.typebotsQueue[0].typebot.variables,
|
||||
)(block),
|
||||
prefilledValue: getPrefilledInputValue(variables)(block),
|
||||
},
|
||||
{
|
||||
variables: state.typebotsQueue[0].typebot.variables,
|
||||
variables,
|
||||
sessionStore,
|
||||
},
|
||||
);
|
||||
@ -94,13 +100,25 @@ export const formatInputForChatResponse = async (
|
||||
|
||||
const computeRuntimeOptions = (
|
||||
block: InputBlock,
|
||||
{ sessionStore, state }: { sessionStore: SessionStore; state: SessionState },
|
||||
{
|
||||
sessionStore,
|
||||
variables,
|
||||
isPreview,
|
||||
workspaceId,
|
||||
}: {
|
||||
sessionStore: SessionStore;
|
||||
variables: Variable[];
|
||||
isPreview: boolean;
|
||||
workspaceId: string;
|
||||
},
|
||||
): Promise<RuntimeOptions> | undefined => {
|
||||
switch (block.type) {
|
||||
case InputBlockType.PAYMENT: {
|
||||
return computePaymentInputRuntimeOptions(block.options, {
|
||||
sessionStore,
|
||||
state,
|
||||
variables,
|
||||
isPreview,
|
||||
workspaceId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -246,7 +246,9 @@ const executeGroup = async (
|
||||
return {
|
||||
messages,
|
||||
input: await formatInputForChatResponse(block, {
|
||||
state: newSessionState,
|
||||
variables: newSessionState.typebotsQueue[0].typebot.variables,
|
||||
isPreview: isNotDefined(newSessionState.typebotsQueue[0].resultId),
|
||||
workspaceId: newSessionState.workspaceId,
|
||||
sessionStore,
|
||||
}),
|
||||
newSessionState: {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user