Skip to content

Commit

Permalink
⚗️ Implement chat API
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Nov 29, 2022
1 parent 49ba434 commit bf0d0c2
Show file tree
Hide file tree
Showing 122 changed files with 5,075 additions and 292 deletions.
1 change: 0 additions & 1 deletion apps/builder/next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const { withSentryConfig } = require('@sentry/nextjs')
const path = require('path')
const withTM = require('next-transpile-modules')([
Expand Down
1 change: 0 additions & 1 deletion apps/builder/src/features/auth/api/getAuthenticatedUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const getAuthenticatedUser = async (
const authenticateByToken = async (
apiToken: string
): Promise<User | undefined> => {
console.log(window)
if (typeof window !== 'undefined') return
return (await prisma.user.findFirst({
where: { apiTokens: { some: { token: apiToken } } },
Expand Down
1 change: 1 addition & 0 deletions apps/builder/src/features/dashboard/api/parseNewTypebot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const parseNewTypebot = ({
| 'icon'
| 'isArchived'
| 'isClosed'
| 'resultsTablePreferences'
> => {
const startGroupId = cuid()
const startBlockId = cuid()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { duplicateWebhookQueries } from '@/features/blocks/integrations/webhook'
import cuid from 'cuid'
import { Plan } from 'db'
import { Plan, Prisma } from 'db'
import {
ChoiceInputBlock,
ConditionBlock,
Expand Down Expand Up @@ -38,7 +38,10 @@ export const importTypebotQuery = async (typebot: Typebot, userPlan: Plan) => {
const duplicateTypebot = (
typebot: Typebot,
userPlan: Plan
): { typebot: Typebot; webhookIdsMapping: Map<string, string> } => {
): {
typebot: Omit<Prisma.TypebotUncheckedCreateInput, 'id'> & { id: string }
webhookIdsMapping: Map<string, string>
} => {
const groupIdsMapping = generateOldNewIdsMapping(typebot.groups)
const edgeIdsMapping = generateOldNewIdsMapping(typebot.edges)
const webhookIdsMapping = generateOldNewIdsMapping(
Expand Down Expand Up @@ -119,8 +122,8 @@ const duplicateTypebot = (
general: { ...typebot.settings.general, isBrandingEnabled: true },
}
: typebot.settings,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
createdAt: new Date(),
updatedAt: new Date(),
resultsTablePreferences: typebot.resultsTablePreferences ?? undefined,
},
webhookIdsMapping,
Expand Down
10 changes: 5 additions & 5 deletions apps/builder/src/features/editor/hooks/useUndo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum ActionType {
Flush = 'FLUSH',
}

export interface Actions<T extends { updatedAt: string } | undefined> {
export interface Actions<T extends { updatedAt: Date } | undefined> {
set: (
newPresent: T | ((current: T) => T),
options?: { updateDate: boolean }
Expand All @@ -24,13 +24,13 @@ export interface Actions<T extends { updatedAt: string } | undefined> {
presentRef: React.MutableRefObject<T>
}

interface Action<T extends { updatedAt: string } | undefined> {
interface Action<T extends { updatedAt: Date } | undefined> {
type: ActionType
newPresent?: T
updateDate?: boolean
}

export interface State<T extends { updatedAt: string } | undefined> {
export interface State<T extends { updatedAt: Date } | undefined> {
past: T[]
present: T
future: T[]
Expand All @@ -42,7 +42,7 @@ const initialState = {
future: [],
}

const reducer = <T extends { updatedAt: string } | undefined>(
const reducer = <T extends { updatedAt: Date } | undefined>(
state: State<T>,
action: Action<T>
) => {
Expand Down Expand Up @@ -112,7 +112,7 @@ const reducer = <T extends { updatedAt: string } | undefined>(
}
}

const useUndo = <T extends { updatedAt: string } | undefined>(
const useUndo = <T extends { updatedAt: Date } | undefined>(
initialPresent: T
): [State<T>, Actions<T>] => {
const [state, dispatch] = useReducer(reducer, {
Expand Down
5 changes: 3 additions & 2 deletions apps/builder/src/features/publish/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const parsePublicTypebotToTypebot = (
workspaceId: existingTypebot.workspaceId,
isArchived: existingTypebot.isArchived,
isClosed: existingTypebot.isClosed,
resultsTablePreferences: existingTypebot.resultsTablePreferences,
})

export const parseTypebotToPublicTypebot = (
Expand All @@ -38,8 +39,8 @@ export const parseTypebotToPublicTypebot = (
settings: typebot.settings,
theme: typebot.theme,
variables: typebot.variables,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
createdAt: new Date(),
updatedAt: new Date(),
})

export const checkIfTypebotsAreEqual = (typebotA: Typebot, typebotB: Typebot) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const ResultsTableContainer = () => {

{typebot && (
<SubmissionsTable
preferences={typebot.resultsTablePreferences}
preferences={typebot.resultsTablePreferences ?? undefined}
resultHeader={resultHeader}
data={tableData}
onScrollToBottom={fetchNextPage}
Expand Down
4 changes: 2 additions & 2 deletions apps/builder/src/pages/api/typebots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
data:
'groups' in data
? data
: (parseNewTypebot({
: parseNewTypebot({
ownerAvatarUrl: user.image,
isBrandingEnabled: workspace.plan === Plan.FREE,
...data,
}) as Prisma.TypebotUncheckedCreateInput),
}),
})
return res.send(typebot)
}
Expand Down
7 changes: 7 additions & 0 deletions apps/builder/src/pages/api/v1/[...trpc].ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { createContext } from '@/utils/server/context'
import { appRouter } from '@/utils/server/routers/v1/_app'
import { captureException } from '@sentry/nextjs'
import { createOpenApiNextHandler } from 'trpc-openapi'

export default createOpenApiNextHandler({
router: appRouter,
createContext,
onError({ error }) {
if (error.code === 'INTERNAL_SERVER_ERROR') {
captureException(error)
console.error('Something went wrong', error)
}
},
})
2 changes: 1 addition & 1 deletion apps/builder/src/utils/server/generateOpenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ const openApiDocument = generateOpenApiDocument(appRouter, {
})

writeFileSync(
'./openapi/builder.json',
'./openapi/builder/_spec_.json',
JSON.stringify(openApiDocument, null, 2)
)
4 changes: 2 additions & 2 deletions apps/docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ module.exports = {
},
presets: [
[
'docusaurus-preset-openapi',
/** @type {import('docusaurus-preset-openapi').Options} */
'@typebot.io/docusaurus-preset-openapi',
/** @type {import('@typebot.io/docusaurus-preset-openapi').Options} */
{
api: {
path: 'openapi',
Expand Down
4 changes: 4 additions & 0 deletions apps/docs/openapi/builder/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Builder",
"sidebar_position": 2
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
sidebar_position: 1
slug: /
---

# Authentication
Expand Down
3 changes: 3 additions & 0 deletions apps/docs/openapi/chat/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"label": "Chat (Experimental 🧪)"
}
Loading

5 comments on commit bf0d0c2

@vercel
Copy link

@vercel vercel bot commented on bf0d0c2 Nov 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./apps/docs

docs-typebot-io.vercel.app
docs.typebot.io
docs-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on bf0d0c2 Nov 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on bf0d0c2 Nov 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

app.typebot.io
builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on bf0d0c2 Nov 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on bf0d0c2 Nov 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2-alpha – ./apps/viewer

ns8.vn
yobot.me
247987.com
8jours.top
bot.aws.bj
bot.bbc.bj
sat.cr8.ai
sellmycarglasgow.com
talkbot.agfunnel.com
tenorioadvogados.com
uppity.wpwakanda.com
abutton.wpwakanda.com
aidigitalmarketing.kr
bbutton.wpwakanda.com
bot.incusservices.com
bot.meuesocial.com.br
bot.ramonmatos.com.br
cdd.searchcube.com.sg
chat.missarkansas.org
chatbot.ownacademy.co
sbutton.wpwakanda.com
815639944.21000000.one
aplicacao.bmind.com.br
apply.ansuraniphone.my
bbutton.wpwwakanda.com
bot.louismarcondes.com
bot.t20worldcup.com.au
c23111azqw.nigerias.io
felipewelington.com.br
form.searchcube.com.sg
gcase.barrettamario.it
help.giversforgood.com
info.clickasuransi.com
kodawariab736.skeep.it
my.swamprecordsgnv.com
premium.kandabrand.com
report.gratirabbit.com
resume.gratirabbit.com
83242573.actualizar.xyz
bot.blackboxtips.com.br
bot.upgradesolutions.eu
help.comebackreward.com
mainmenu.diddancing.com
register.kandabrand.com
signup.hypemarketing.in
subfooter.wpwakanda.com
survey.hypemarketing.in
testbot.afterorigin.com
91181264.your-access.one
ai.chromebookstoreph.com
form.sergiolimajr.com.br
hunterbot.saleshunter.ai
instant.botscientis.info
link.cascadigital.com.br
onboarding.growthside.io
reward.onlinebotdemo.xyz
type.opaulovieira.com.br
aibot.angrybranding.co.uk
bot.aidigitalmarketing.kr
bot.arraesecenteno.com.br
bot.blackboxsports.com.br
bot.cabinrentalagency.com
boyfriend-breakup.riku.ai
brigadeirosemdrama.com.br
chat.ertcrebateportal.com
chat.thisiscrushhouse.com
sellmyharleylouisiana.com
verfica.botmachine.com.br
configurator.bouclidom.com
help.atlasoutfittersk9.com
ted.meujalecobrasil.com.br
type.dericsoncalari.com.br
chatbot.berbelanjabiz.trade
designguide.techyscouts.com
presente.empresarias.com.mx
sell.sellthemotorhome.co.uk
anamnese.odontopavani.com.br
austin.channelautomation.com
bot.marketingplusmindset.com
piazzatorre.barrettamario.it
requests.swamprecordsgnv.com
type.cookieacademyonline.com
bot.brigadeirosemdrama.com.br
onboarding.libertydreamcare.ie
type.talitasouzamarques.com.br
agendamento.sergiolimajr.com.br
anamnese.clinicamegasjdr.com.br
bookings.littlepartymonkeys.com
bot.comercializadoraomicron.com
elevateyourmind.groovepages.com
yourfeedback.comebackreward.com
personal-trainer.barrettamario.it
preagendamento.sergiolimajr.com.br
studiotecnicoimmobiliaremerelli.it
download.thailandmicespecialist.com
register.thailandmicespecialist.com
viewer-v2-alpha-typebot-io.vercel.app
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
viewer-v2-alpha-git-main-typebot-io.vercel.app

Please sign in to comment.