-
-
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.
✨ Add webhook blocks API public endpoints
- Loading branch information
1 parent
f9ffdbc
commit c799717
Showing
67 changed files
with
3,033 additions
and
432 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
1 change: 1 addition & 0 deletions
1
apps/builder/src/features/blocks/integrations/webhook/api/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './router' |
74 changes: 74 additions & 0 deletions
74
...lder/src/features/blocks/integrations/webhook/api/procedures/getResultExampleProcedure.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { getLinkedTypebots } from '@/features/blocks/logic/typebotLink/api' | ||
import prisma from '@/lib/prisma' | ||
import { canReadTypebot } from '@/utils/api/dbRules' | ||
import { authenticatedProcedure } from '@/utils/server/trpc' | ||
import { TRPCError } from '@trpc/server' | ||
import { Typebot, Webhook } from 'models' | ||
import { z } from 'zod' | ||
import { parseResultExample } from '../utils' | ||
|
||
export const getResultExampleProcedure = authenticatedProcedure | ||
.meta({ | ||
openapi: { | ||
method: 'GET', | ||
path: '/typebots/{typebotId}/webhookBlocks/{blockId}/getResultExample', | ||
protect: true, | ||
summary: 'Get result example', | ||
description: | ||
'Returns "fake" result for webhook block to help you anticipate how the webhook will behave.', | ||
tags: ['Webhook'], | ||
}, | ||
}) | ||
.input( | ||
z.object({ | ||
typebotId: z.string(), | ||
blockId: z.string(), | ||
}) | ||
) | ||
.output( | ||
z.object({ | ||
resultExample: z | ||
.object({ | ||
message: z.literal( | ||
'This is a sample result, it has been generated ⬇️' | ||
), | ||
'Submitted at': z.string(), | ||
}) | ||
.and(z.record(z.string().optional())) | ||
.describe('Can contain any fields.'), | ||
}) | ||
) | ||
.query(async ({ input: { typebotId, blockId }, ctx: { user } }) => { | ||
const typebot = (await prisma.typebot.findFirst({ | ||
where: canReadTypebot(typebotId, user), | ||
select: { | ||
groups: true, | ||
edges: true, | ||
variables: true, | ||
webhooks: true, | ||
}, | ||
})) as | ||
| (Pick<Typebot, 'groups' | 'edges' | 'variables'> & { | ||
webhooks: Webhook[] | ||
}) | ||
| null | ||
|
||
if (!typebot) | ||
throw new TRPCError({ code: 'NOT_FOUND', message: 'Typebot not found' }) | ||
|
||
const block = typebot.groups | ||
.flatMap((g) => g.blocks) | ||
.find((s) => s.id === blockId) | ||
|
||
if (!block) | ||
throw new TRPCError({ code: 'NOT_FOUND', message: 'Block not found' }) | ||
|
||
const linkedTypebots = await getLinkedTypebots(typebot, user) | ||
|
||
return { | ||
resultExample: await parseResultExample( | ||
typebot, | ||
linkedTypebots | ||
)(block.groupId), | ||
} | ||
}) |
4 changes: 4 additions & 0 deletions
4
apps/builder/src/features/blocks/integrations/webhook/api/procedures/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './getResultExampleProcedure' | ||
export * from './listWebhookBlocksProcedure' | ||
export * from './subscribeWebhookProcedure' | ||
export * from './unsubscribeWebhookProcedure' |
65 changes: 65 additions & 0 deletions
65
...der/src/features/blocks/integrations/webhook/api/procedures/listWebhookBlocksProcedure.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import prisma from '@/lib/prisma' | ||
import { canReadTypebot } from '@/utils/api/dbRules' | ||
import { authenticatedProcedure } from '@/utils/server/trpc' | ||
import { TRPCError } from '@trpc/server' | ||
import { Group, Typebot, Webhook, WebhookBlock } from 'models' | ||
import { byId, isWebhookBlock } from 'utils' | ||
import { z } from 'zod' | ||
|
||
export const listWebhookBlocksProcedure = authenticatedProcedure | ||
.meta({ | ||
openapi: { | ||
method: 'GET', | ||
path: '/typebots/{typebotId}/webhookBlocks', | ||
protect: true, | ||
summary: 'List webhook blocks', | ||
description: | ||
'Returns a list of all the webhook blocks that you can subscribe to.', | ||
tags: ['Webhook'], | ||
}, | ||
}) | ||
.input( | ||
z.object({ | ||
typebotId: z.string(), | ||
}) | ||
) | ||
.output( | ||
z.object({ | ||
webhookBlocks: z.array( | ||
z.object({ | ||
id: z.string(), | ||
label: z.string(), | ||
url: z.string().optional(), | ||
}) | ||
), | ||
}) | ||
) | ||
.query(async ({ input: { typebotId }, ctx: { user } }) => { | ||
const typebot = (await prisma.typebot.findFirst({ | ||
where: canReadTypebot(typebotId, user), | ||
select: { | ||
groups: true, | ||
webhooks: true, | ||
}, | ||
})) as (Pick<Typebot, 'groups'> & { webhooks: Webhook[] }) | null | ||
if (!typebot) | ||
throw new TRPCError({ code: 'NOT_FOUND', message: 'Typebot not found' }) | ||
|
||
const webhookBlocks = (typebot?.groups as Group[]).reduce< | ||
{ id: string; label: string; url: string | undefined }[] | ||
>((webhookBlocks, group) => { | ||
const blocks = group.blocks.filter((block) => | ||
isWebhookBlock(block) | ||
) as WebhookBlock[] | ||
return [ | ||
...webhookBlocks, | ||
...blocks.map((b) => ({ | ||
id: b.id, | ||
label: `${group.title} > ${b.id}`, | ||
url: typebot?.webhooks.find(byId(b.webhookId))?.url ?? undefined, | ||
})), | ||
] | ||
}, []) | ||
|
||
return { webhookBlocks } | ||
}) |
64 changes: 64 additions & 0 deletions
64
...lder/src/features/blocks/integrations/webhook/api/procedures/subscribeWebhookProcedure.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import prisma from '@/lib/prisma' | ||
import { canWriteTypebot } from '@/utils/api/dbRules' | ||
import { authenticatedProcedure } from '@/utils/server/trpc' | ||
import { TRPCError } from '@trpc/server' | ||
import { Typebot, Webhook, WebhookBlock } from 'models' | ||
import { byId, isWebhookBlock } from 'utils' | ||
import { z } from 'zod' | ||
|
||
export const subscribeWebhookProcedure = authenticatedProcedure | ||
.meta({ | ||
openapi: { | ||
method: 'POST', | ||
path: '/typebots/{typebotId}/webhookBlocks/{blockId}/subscribe', | ||
protect: true, | ||
summary: 'Subscribe to webhook block', | ||
tags: ['Webhook'], | ||
}, | ||
}) | ||
.input( | ||
z.object({ | ||
typebotId: z.string(), | ||
blockId: z.string(), | ||
url: z.string(), | ||
}) | ||
) | ||
.output( | ||
z.object({ | ||
id: z.string(), | ||
url: z.string().nullable(), | ||
}) | ||
) | ||
.query(async ({ input: { typebotId, blockId, url }, ctx: { user } }) => { | ||
const typebot = (await prisma.typebot.findFirst({ | ||
where: canWriteTypebot(typebotId, user), | ||
select: { | ||
groups: true, | ||
webhooks: true, | ||
}, | ||
})) as (Pick<Typebot, 'groups'> & { webhooks: Webhook[] }) | null | ||
|
||
if (!typebot) | ||
throw new TRPCError({ code: 'NOT_FOUND', message: 'Typebot not found' }) | ||
|
||
const webhookBlock = typebot.groups | ||
.flatMap((g) => g.blocks) | ||
.find(byId(blockId)) as WebhookBlock | null | ||
|
||
if (!webhookBlock || !isWebhookBlock(webhookBlock)) | ||
throw new TRPCError({ | ||
code: 'NOT_FOUND', | ||
message: 'Webhook block not found', | ||
}) | ||
|
||
await prisma.webhook.upsert({ | ||
where: { id: webhookBlock.webhookId }, | ||
update: { url, body: '{{state}}', method: 'POST' }, | ||
create: { url, body: '{{state}}', method: 'POST', typebotId }, | ||
}) | ||
|
||
return { | ||
id: blockId, | ||
url, | ||
} | ||
}) |
62 changes: 62 additions & 0 deletions
62
...er/src/features/blocks/integrations/webhook/api/procedures/unsubscribeWebhookProcedure.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import prisma from '@/lib/prisma' | ||
import { canWriteTypebot } from '@/utils/api/dbRules' | ||
import { authenticatedProcedure } from '@/utils/server/trpc' | ||
import { TRPCError } from '@trpc/server' | ||
import { Typebot, Webhook, WebhookBlock } from 'models' | ||
import { byId, isWebhookBlock } from 'utils' | ||
import { z } from 'zod' | ||
|
||
export const unsubscribeWebhookProcedure = authenticatedProcedure | ||
.meta({ | ||
openapi: { | ||
method: 'POST', | ||
path: '/typebots/{typebotId}/webhookBlocks/{blockId}/unsubscribe', | ||
protect: true, | ||
summary: 'Unsubscribe from webhook block', | ||
tags: ['Webhook'], | ||
}, | ||
}) | ||
.input( | ||
z.object({ | ||
typebotId: z.string(), | ||
blockId: z.string(), | ||
}) | ||
) | ||
.output( | ||
z.object({ | ||
id: z.string(), | ||
url: z.string().nullable(), | ||
}) | ||
) | ||
.query(async ({ input: { typebotId, blockId }, ctx: { user } }) => { | ||
const typebot = (await prisma.typebot.findFirst({ | ||
where: canWriteTypebot(typebotId, user), | ||
select: { | ||
groups: true, | ||
webhooks: true, | ||
}, | ||
})) as (Pick<Typebot, 'groups'> & { webhooks: Webhook[] }) | null | ||
|
||
if (!typebot) | ||
throw new TRPCError({ code: 'NOT_FOUND', message: 'Typebot not found' }) | ||
|
||
const webhookBlock = typebot.groups | ||
.flatMap((g) => g.blocks) | ||
.find(byId(blockId)) as WebhookBlock | null | ||
|
||
if (!webhookBlock || !isWebhookBlock(webhookBlock)) | ||
throw new TRPCError({ | ||
code: 'NOT_FOUND', | ||
message: 'Webhook block not found', | ||
}) | ||
|
||
await prisma.webhook.update({ | ||
where: { id: webhookBlock.webhookId }, | ||
data: { url: null }, | ||
}) | ||
|
||
return { | ||
id: blockId, | ||
url: null, | ||
} | ||
}) |
14 changes: 14 additions & 0 deletions
14
apps/builder/src/features/blocks/integrations/webhook/api/router.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { router } from '@/utils/server/trpc' | ||
import { | ||
listWebhookBlocksProcedure, | ||
subscribeWebhookProcedure, | ||
unsubscribeWebhookProcedure, | ||
getResultExampleProcedure, | ||
} from './procedures' | ||
|
||
export const webhookRouter = router({ | ||
listWebhookBlocks: listWebhookBlocksProcedure, | ||
getResultExample: getResultExampleProcedure, | ||
subscribeWebhook: subscribeWebhookProcedure, | ||
unsubscribeWebhook: unsubscribeWebhookProcedure, | ||
}) |
1 change: 1 addition & 0 deletions
1
apps/builder/src/features/blocks/integrations/webhook/api/utils/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './parseResultExample' |
Oops, something went wrong.
c799717
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
bot.joof.it
yoda.riku.ai
bergamo.store
bot.tvbeat.it
app.yvon.earth
bots.bridge.ai
chat.hayuri.id
gollum.riku.ai
talk.gocare.io
bot.jesopizz.it
fitness.riku.ai
bot.contakit.com
zap.fundviser.in
bot.rihabilita.it
viewer.typebot.io
bot.danyservice.it
bot.dsignagency.com
chatbot.matthesv.de
demo.wemakebots.xyz
88584434.therpm.club
92109660.therpm.club
bot.barrettamario.it
hello.advergreen.com
bot.coachayongzul.com
bot.digitalpointer.id
bot.eikju.photography
bot.outstandbrand.com
bot.robertohairlab.it
criar.somaperuzzo.com
bot.ilmuseoaiborghi.it
bot.pratikmandalia.com
form.bridesquadapp.com
michaeljackson.riku.ai
87656003.actualizar.xyz
88152257.actualizar.xyz
91375310.actualizar.xyz
arrivalx2.wpwakanda.com
bot.hotelplayarimini.it
link.venturasuceder.com
invite.bridesquadapp.com
bot.amicidisanfaustino.it
chat.thehomebuyersusa.com
forms.hiabhaykulkarni.com
typebot-viewer.vercel.app
bot.adventureconsulting.hu
casestudyemb.wpwakanda.com
chat.atlasoutfittersk9.com
herbalife.barrettamario.it
homepageonly.wpwakanda.com
liveconvert.kandalearn.com
mainmenu1one.wpwakanda.com
tarian.theiofoundation.org
bot.pinpointinteractive.com
bot.polychromes-project.com
bot.seidinembroseanchetu.it
liveconvert2.kandalearn.com
bot.seidibergamoseanchetu.it
forms.escoladeautomacao.com.br
viewer-v2-typebot-io.vercel.app
bot.studiotecnicoimmobiliaremerelli.it
viewer-v2-git-main-typebot-io.vercel.app
c799717
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-git-main-typebot-io.vercel.app
docs-typebot-io.vercel.app
docs.typebot.io
c799717
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-alpha – ./apps/viewer
ns8.vn
yobot.me
247987.com
8jours.top
bot.aws.bj
bot.bbc.bj
finplex.be
sat.cr8.ai
bot.aipr.kr
minipost.uk
bt.id8rs.com
bot.krdfy.com
goldorayo.com
vhpage.cr8.ai
am.nigerias.io
an.nigerias.io
ar.nigerias.io
bot.enreso.org
bot.lalmon.com
ticketfute.com
apo.nigerias.io
apr.nigerias.io
aso.nigerias.io
bot.ageenda.com
bot.artiweb.app
bot.devitus.com
bot.tc-mail.com
chat.sureb4.com
eventhub.com.au
games.klujo.com
sakuranembro.it
typebot.aloe.do
bot.piccinato.co
botc.ceox.com.br
clo.closeer.work
faqs.nigerias.io
feedback.ofx.one
form.syncwin.com
kw.wpwakanda.com
myrentalhost.com
stan.vselise.com
start.taxtree.io
typebot.aloe.bot
voicehelp.cr8.ai
app.chatforms.net
bot.agfunnel.tech
bot.hostnation.de
bot.maitempah.com
bot.phuonghub.com
bot.reviewzer.com
cares.urlabout.me
fmm.wpwakanda.com
gentleman-shop.fr
k1.kandabrand.com
lb.ticketfute.com
ov1.wpwakanda.com
ov2.wpwakanda.com
ov3.wpwakanda.com
1988.bouclidom.com
andreimayer.com.br
bot.megafox.com.br
bot.neferlopez.com
bots.robomotion.io
cadu.uninta.edu.br
dicanatural.online
goalsettingbot.com
positivobra.com.br
survey.digienge.io
this-is-a-test.com
zap.techadviser.in
bot.digitalbled.com
bot.eventhub.com.au
bot.jepierre.com.br
bot.winglabs.com.br
carsalesenquiry.com
demo.botscientis.us
forms.webisharp.com
kbsub.wpwakanda.com
live.botscientis.us
mentoria.omelhor.vc
nutrisamirbayde.com
order.maitempah.com
quest.wpwakanda.com
survey1.digienge.io
test.botscientis.us
typebot.stillio.com
wordsandimagery.com
bium.gratirabbit.com
bot.ansuraniphone.my
bot.cotemeuplano.com
chat.hayurihijab.com
chatbee.agfunnel.com
click.sevenoways.com
connect.growthguy.in
kuiz.sistemniaga.com
offer.botscientis.us
sellmycarglasgow.com
tenorioadvogados.com
uppity.wpwakanda.com
abutton.wpwakanda.com
c799717
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-typebot-io.vercel.app
app.typebot.io
builder-v2-git-main-typebot-io.vercel.app
c799717
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:
landing-page-v2 – ./apps/landing-page
landing-page-v2-git-main-typebot-io.vercel.app
typebot.io
www.typebot.io
landing-page-v2-typebot-io.vercel.app
get-typebot.com
www.get-typebot.com