2
0
Files
bot/apps/builder/services/webhook.ts

24 lines
682 B
TypeScript
Raw Normal View History

import { Webhook } from 'models'
import { sendRequest } from 'utils'
export const saveWebhook = (webhookId: string, webhook: Partial<Webhook>) =>
sendRequest<{ webhook: Webhook }>({
method: 'PUT',
url: `/api/webhooks/${webhookId}`,
body: webhook,
})
export const duplicateWebhook = async (
2022-05-13 06:46:17 -07:00
typebotId: string,
existingWebhookId: string,
newWebhookId: string
): Promise<Webhook | undefined> => {
const { data } = await sendRequest<{ webhook: Webhook }>(
2022-05-13 06:46:17 -07:00
`/api/webhooks/${existingWebhookId}`
)
if (!data) return
2022-05-13 06:46:17 -07:00
const newWebhook = { ...data.webhook, id: newWebhookId, typebotId }
await saveWebhook(newWebhook.id, newWebhook)
return newWebhook
}