<script>
import { onMount } from 'svelte'
import axios from "axios";
import Botpoison from "@botpoison/browser";
let botpoison = null;
let message = null;
let loading = false;
onMount(() => {
botpoison = new Botpoison({
publicKey: "pk_xxxxxxxx",
});
});
async function onSubmit() {
loading = true;
try {
const { solution } = await botpoison.challenge();
await axios.post("https://example.demo/", {
message: message,
_botpoison: solution,
});
alert("Form submitted");
message = null;
} catch (error) {
alert("Error submitting form");
} finally {
loading = false;
}
}
</script>
<form on:submit|preventDefault="{onSubmit}">
<textarea bind:value="{message}" />
<button type="submit" disabled="{loading}">Send</button>
</form>