Getting started with Angular
1. Install and import the @botpoison/browser library.
npm install @botpoison/browser
2. Create a new Botpoison instance with your public key.
3. Process a challenge using the challenge() function.
4. Forward the solution to your server for verification.
typescript
import { Component } from "@angular/core";import { HttpClient } from "@angular/common/http";// 1. Import the libraryimport Botpoison from "@botpoison/browser";@Component({selector: "app-contact-form",template: `<form (ngSubmit)="onSubmit()"><textarea [(ngModel)]="message" name="message" placeholder="Enter your message"></textarea><button type="submit" [disabled]="loading">Send</button></form>`,})export class ContactFormComponent {message = "";loading = false;// 2. Create a new instance with your public keyprivate botpoison = new Botpoison({publicKey: "pk_xxxxxxxx",});constructor(private http: HttpClient) {}async onSubmit() {this.loading = true;try {// 3. Process a challengeconst { solution } = await this.botpoison.challenge();await this.http.post("https://example.demo/", {message: this.message,// 4. Forward the solution_botpoison: solution,}).toPromise();alert("Form submitted");this.message = "";} catch (error) {alert("Error submitting form");} finally {this.loading = false;}}}