2022-03-01 07:13:09 +01:00
|
|
|
import { Webhook } from 'models'
|
|
|
|
import { sendRequest } from 'utils'
|
2023-02-15 14:51:58 +01:00
|
|
|
import { createWebhookQuery } from './createWebhookQuery'
|
2022-03-01 07:13:09 +01:00
|
|
|
|
2023-02-15 14:51:58 +01:00
|
|
|
type Props = {
|
|
|
|
existingIds: { typebotId: string; webhookId: string }
|
|
|
|
newIds: { typebotId: string; webhookId: string }
|
|
|
|
}
|
|
|
|
export const duplicateWebhookQuery = async ({
|
|
|
|
existingIds,
|
|
|
|
newIds,
|
|
|
|
}: Props): Promise<Webhook | undefined> => {
|
2022-03-21 19:20:44 +01:00
|
|
|
const { data } = await sendRequest<{ webhook: Webhook }>(
|
2023-02-15 14:51:58 +01:00
|
|
|
`/api/typebots/${existingIds.typebotId}/webhooks/${existingIds.webhookId}`
|
2022-03-21 19:20:44 +01:00
|
|
|
)
|
|
|
|
if (!data) return
|
2023-02-15 14:51:58 +01:00
|
|
|
const newWebhook = {
|
|
|
|
...data.webhook,
|
|
|
|
id: newIds.webhookId,
|
|
|
|
typebotId: newIds.typebotId,
|
|
|
|
}
|
|
|
|
await createWebhookQuery({
|
|
|
|
typebotId: newIds.typebotId,
|
|
|
|
data: { ...data.webhook, id: newIds.webhookId },
|
|
|
|
})
|
2022-03-21 19:20:44 +01:00
|
|
|
return newWebhook
|
|
|
|
}
|