-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 New sendMessage version for the new parser
Make sure old client still communicate with old parser
- Loading branch information
1 parent
6f3e9e9
commit 3838ac9
Showing
35 changed files
with
702 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import { publicProcedure } from '@/helpers/server/trpc' | ||
import { | ||
chatReplySchema, | ||
sendMessageInputSchema, | ||
} from '@typebot.io/schemas/features/chat/schema' | ||
import { TRPCError } from '@trpc/server' | ||
import { getSession } from '@typebot.io/bot-engine/queries/getSession' | ||
import { startSession } from '@typebot.io/bot-engine/startSession' | ||
import { saveStateToDatabase } from '@typebot.io/bot-engine/saveStateToDatabase' | ||
import { restartSession } from '@typebot.io/bot-engine/queries/restartSession' | ||
import { continueBotFlow } from '@typebot.io/bot-engine/continueBotFlow' | ||
import { parseDynamicTheme } from '@typebot.io/bot-engine/parseDynamicTheme' | ||
import { isDefined } from '@typebot.io/lib/utils' | ||
|
||
export const sendMessageV2 = publicProcedure | ||
.meta({ | ||
openapi: { | ||
method: 'POST', | ||
path: '/sendMessage', | ||
summary: 'Send a message', | ||
description: | ||
'To initiate a chat, do not provide a `sessionId` nor a `message`.\n\nContinue the conversation by providing the `sessionId` and the `message` that should answer the previous question.\n\nSet the `isPreview` option to `true` to chat with the non-published version of the typebot.', | ||
}, | ||
}) | ||
.input(sendMessageInputSchema) | ||
.output(chatReplySchema) | ||
.mutation( | ||
async ({ | ||
input: { sessionId, message, startParams, clientLogs }, | ||
ctx: { user }, | ||
}) => { | ||
const session = sessionId ? await getSession(sessionId) : null | ||
|
||
const isSessionExpired = | ||
session && | ||
isDefined(session.state.expiryTimeout) && | ||
session.updatedAt.getTime() + session.state.expiryTimeout < Date.now() | ||
|
||
if (isSessionExpired) | ||
throw new TRPCError({ | ||
code: 'NOT_FOUND', | ||
message: 'Session expired. You need to start a new session.', | ||
}) | ||
|
||
if (!session) { | ||
if (!startParams) | ||
throw new TRPCError({ | ||
code: 'BAD_REQUEST', | ||
message: 'Missing startParams', | ||
}) | ||
const { | ||
typebot, | ||
messages, | ||
input, | ||
resultId, | ||
dynamicTheme, | ||
logs, | ||
clientSideActions, | ||
newSessionState, | ||
} = await startSession({ | ||
version: 2, | ||
startParams, | ||
userId: user?.id, | ||
message, | ||
}) | ||
|
||
const allLogs = clientLogs ? [...(logs ?? []), ...clientLogs] : logs | ||
|
||
const session = startParams?.isOnlyRegistering | ||
? await restartSession({ | ||
state: newSessionState, | ||
}) | ||
: await saveStateToDatabase({ | ||
session: { | ||
state: newSessionState, | ||
}, | ||
input, | ||
logs: allLogs, | ||
clientSideActions, | ||
}) | ||
|
||
return { | ||
sessionId: session.id, | ||
typebot: typebot | ||
? { | ||
id: typebot.id, | ||
theme: typebot.theme, | ||
settings: typebot.settings, | ||
} | ||
: undefined, | ||
messages, | ||
input, | ||
resultId, | ||
dynamicTheme, | ||
logs, | ||
clientSideActions, | ||
} | ||
} else { | ||
const { | ||
messages, | ||
input, | ||
clientSideActions, | ||
newSessionState, | ||
logs, | ||
lastMessageNewFormat, | ||
} = await continueBotFlow(message, { version: 2, state: session.state }) | ||
|
||
const allLogs = clientLogs ? [...(logs ?? []), ...clientLogs] : logs | ||
|
||
if (newSessionState) | ||
await saveStateToDatabase({ | ||
session: { | ||
id: session.id, | ||
state: newSessionState, | ||
}, | ||
input, | ||
logs: allLogs, | ||
clientSideActions, | ||
}) | ||
|
||
return { | ||
messages, | ||
input, | ||
clientSideActions, | ||
dynamicTheme: parseDynamicTheme(newSessionState), | ||
logs, | ||
lastMessageNewFormat, | ||
} | ||
} | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...wer/src/helpers/server/routers/v1/_app.ts → ...src/helpers/server/routers/appRouterV1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { sendMessageV2 } from '@/features/chat/api/sendMessageV2' | ||
import { whatsAppRouter } from '@/features/whatsapp/api/router' | ||
import { router } from '../trpc' | ||
import { updateTypebotInSession } from '@/features/chat/api/updateTypebotInSession' | ||
import { getUploadUrl } from '@/features/fileUpload/api/deprecated/getUploadUrl' | ||
import { generateUploadUrl } from '@/features/fileUpload/api/generateUploadUrl' | ||
|
||
export const appRouter = router({ | ||
sendMessageV2, | ||
getUploadUrl, | ||
generateUploadUrl, | ||
updateTypebotInSession, | ||
whatsAppRouter, | ||
}) | ||
|
||
export type AppRouter = typeof appRouter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { appRouter } from '@/helpers/server/routers/appRouterV2' | ||
import { captureException } from '@sentry/nextjs' | ||
import { createOpenApiNextHandler } from 'trpc-openapi' | ||
import cors from 'nextjs-cors' | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import { createContext } from '@/helpers/server/context' | ||
|
||
const handler = async (req: NextApiRequest, res: NextApiResponse) => { | ||
await cors(req, res) | ||
|
||
return createOpenApiNextHandler({ | ||
router: appRouter, | ||
createContext, | ||
onError({ error }) { | ||
if (error.code === 'INTERNAL_SERVER_ERROR') { | ||
captureException(error) | ||
console.error('Something went wrong', error) | ||
} | ||
}, | ||
})(req, res) | ||
} | ||
|
||
export default handler |
Oops, something went wrong.
3838ac9
There was a problem hiding this comment.
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
builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
app.typebot.io
3838ac9
There was a problem hiding this comment.
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
3838ac9
There was a problem hiding this comment.
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 – ./apps/viewer
survey.collab.day
test.eqfeqfeq.com
viewer.typebot.io
welcome.triplo.ai
www.thegymgame.it
zeropendencia.com
1988.bouclidom.com
a.onewebcenter.com
amancarseat.online
amostra-safe.click
andreimayer.com.br
bebesemcolicas.com
bot.innovacion.fun
bot.jogodospix.com
bot.jogomilion.com
bot.lucide.contact
bot.neferlopez.com
bot.photonative.de
bot.rajatanjak.com
bot.samplehunt.com
bot.sinalcerto.com
bot.wphelpchat.com
bots.robomotion.io
brandingmkt.com.br
bt.chatgptlabs.org
cadu.uninta.edu.br
chat.daftarjer.com
chat.foxbot.online
chat.hand-made.one
chat.tuanpakya.com
chat.webisharp.com
chatbotforthat.com
descobrindotudo.me
dicanatural.online
digitalhelp.com.au
draraquelnutri.com
drcarlosyoshi.site
goalsettingbot.com
golpenuncamais.com
leads.gecoelho.com
noticiasnet.online
novoappespiao.site
omarcodosanjos.com
pant.maxbot.com.br
pantherview.cr8.ai
positivobra.com.br
rollingball.cr8.ai
ruletaiapro.online
bot.leadbooster.help
bot.mycompay.reviews
bot.projetodashi.com
bot.socialcliques.me
cha.onewebcenter.com
chat.febredojogo.com
chat.gnipharmahq.com
chat.hayurihijab.com
chat.jottagreens.com
chatbee.agfunnel.com
click.sevenoways.com
connect.growthguy.in
demo.solidrock.space
detetivepatricia.com
drapamela.gikpro.com
drgisellegarcia.site
encodebot.share5.net
forms.bonanza.design
hello.advergreen.com
viewer-v2-typebot-io.vercel.app
bot.studiotecnicoimmobiliaremerelli.it
mdb.assessoria.boaventura.progenbr.com
mdb.assessoria.jtrebesqui.progenbr.com
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
gabinete.baleia.formulario.progenbr.com
mdb.assessoria.carreirinha.progenbr.com
chrome-os-inquiry-system.itschromeos.com
mdb.assessoria.paulomarques.progenbr.com
viewer-v2-git-main-typebot-io.vercel.app
main-menu-for-itschromeos.itschromeos.com
mdb.assessoria.qrcode.ademir.progenbr.com
mdb.assessoria.qrcode.arthur.progenbr.com
mdb.assessoria.qrcode.danilo.progenbr.com
mdb.assessoria.qrcode.marcao.progenbr.com
mdb.assessoria.qrcode.marcio.progenbr.com
mdb.assessoria.qrcode.aloisio.progenbr.com
mdb.assessoria.qrcode.girotto.progenbr.com
mdb.assessoria.qrcode.marinho.progenbr.com
mdb.assessoria.qrcode.rodrigo.progenbr.com
mdb.assessoria.carlosalexandre.progenbr.com
mdb.assessoria.qrcode.desideri.progenbr.com
mdb.assessoria.qrcode.fernanda.progenbr.com
mdb.assessoria.qrcode.jbatista.progenbr.com
mdb.assessoria.qrcode.mauricio.progenbr.com
mdb.assessoria.fernanda.regional.progenbr.com
mdb.assessoria.qrcode.boaventura.progenbr.com
mdb.assessoria.qrcode.jtrebesqui.progenbr.com
mdb.assessoria.qrcode.carreirinha.progenbr.com
mdb.assessoria.qrcode.paulomarques.progenbr.com
mdb.assessoria.qrcode.carlosalexandre.progenbr.com
mdb.assessoria.qrcode.fernanda.regional.progenbr.com