-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
68 lines (59 loc) · 1.56 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* 🤘 Welcome to Stagehand!
*
* This is a script to automate scheduling a meeting on Calendly.
*
* TO RUN THIS PROJECT:
* ```
* npm install
* npm run start
* ```
*
* To edit config, see `stagehand.config.ts`
*
*/
import { Page, BrowserContext, Stagehand } from "@browserbasehq/stagehand";
import { z } from "zod";
import chalk from "chalk";
import dotenv from "dotenv";
dotenv.config();
interface CalendlyUser {
name: string;
email: string;
}
async function act(page: Page, instruction: string) {
const candidates = await page.observe({
instruction,
onlyVisible: true,
returnAction: true,
});
console.log(candidates);
await page.act(candidates[0]);
}
export async function main({
page,
context,
stagehand,
calendlyUrl = "https://calendly.com/anirudh-browserbase/30min",
user = {
name: "Anirudh",
email: "[email protected]",
},
eventName = "30min",
}: {
page: Page; // Playwright Page with act, extract, and observe methods
context: BrowserContext; // Playwright BrowserContext
stagehand: Stagehand; // Stagehand instance
calendlyUrl: string;
user: CalendlyUser;
eventName: string;
}) {
await page.goto(calendlyUrl);
await act(page, "click the first available date");
await act(page, "click the first available time");
const nextButton = await act(page, "click button that says next");
await act(page, `fill ${user.name} in the name field`);
await act(page, `fill ${user.email} in the email field`);
await act(page, "click the button that says schedule event");
console.log(nextButton);
}