2022-03-01 07:13:09 +01:00
|
|
|
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,
|
|
|
|
})
|
2022-03-21 19:20:44 +01:00
|
|
|
|
|
|
|
export const duplicateWebhook = async (
|
2022-05-13 06:46:17 -07:00
|
|
|
typebotId: string,
|
|
|
|
existingWebhookId: string,
|
|
|
|
newWebhookId: string
|
2022-03-21 19:20:44 +01:00
|
|
|
): Promise<Webhook | undefined> => {
|
|
|
|
const { data } = await sendRequest<{ webhook: Webhook }>(
|
2022-05-13 06:46:17 -07:00
|
|
|
`/api/webhooks/${existingWebhookId}`
|
2022-03-21 19:20:44 +01:00
|
|
|
)
|
|
|
|
if (!data) return
|
2022-05-13 06:46:17 -07:00
|
|
|
const newWebhook = { ...data.webhook, id: newWebhookId, typebotId }
|
2022-03-21 19:20:44 +01:00
|
|
|
await saveWebhook(newWebhook.id, newWebhook)
|
|
|
|
return newWebhook
|
|
|
|
}
|