<template>
<div>
<form @submit.prevent="onSubmit">
<textarea v-model="message" placeholder="Enter your message" />
<button type="submit" :disabled="loading">Send</button>
</form>
</div>
</template>
<script>
import axios from "axios";
import Botpoison from "@botpoison/browser";
export default {
data() {
return {
botpoison: null,
message: null,
loading: false,
};
},
created() {
this.botpoison = new Botpoison({
publicKey: "pk_xxxxxxxx",
});
},
methods: {
async onSubmit() {
this.loading = true;
try {
const { solution } = await this.botpoison.challenge();
await axios.post("https://example.demo/", {
message: this.message,
_botpoison: solution,
});
alert("Form submitted");
this.message = null;
} catch (error) {
alert("Error submitting form");
} finally {
this.loading = false;
}
},
},
};
</script>