16
17// This is the entry point for HTTP vals
18export default app.fetch;
10// Helper function to send Telegram message
11async function sendTelegramMessage(chatId: number, text: string) {
12 const response = await fetch(`${TELEGRAM_API_URL}/sendMessage`, {
13 method: 'POST',
14 headers: {
11 e.preventDefault();
12 try {
13 const response = await fetch('/post-job', {
14 method: 'POST',
15 headers: { 'Content-Type': 'application/json' },
59
60 useEffect(() => {
61 async function fetchJobs() {
62 try {
63 const response = await fetch('/get-jobs');
64 const data = await response.json();
65 setJobs(data);
66 } catch (error) {
67 console.error('Error fetching jobs:', error);
68 }
69 }
70 fetchJobs();
71 const interval = setInterval(fetchJobs, 60000); // Refresh every minute
72 return () => clearInterval(interval);
73 }, []);
92
93 useEffect(() => {
94 async function fetchMessages() {
95 try {
96 const response = await fetch('/get-messages');
97 const data = await response.json();
98 setMessages(data);
99 } catch (error) {
100 console.error('Error fetching messages:', error);
101 }
102 }
103 fetchMessages();
104 const interval = setInterval(fetchMessages, 5000); // Refresh every 5 seconds
105 return () => clearInterval(interval);
106 }, []);
109 e.preventDefault();
110 try {
111 const response = await fetch('/send-message', {
112 method: 'POST',
113 headers: { 'Content-Type': 'application/json' },
21});
22
23// HTTP vals expect an exported "fetch handler"
24// This is how you "run the server" in Val Town with Hono
25export default app.fetch;
47});
48
49// HTTP vals expect an exported "fetch handler"
50// This is how you "run the server" in Val Town with Hono
51export default app.fetch;
18
19 useEffect(() => {
20 fetchJobs();
21 fetchMessages();
22 }, []);
23
24 const fetchJobs = async () => {
25 const response = await fetch("/jobs");
26 const data = await response.json();
27 setJobs(data);
28 };
29
30 const fetchMessages = async () => {
31 const response = await fetch("/messages");
32 const data = await response.json();
33 setMessages(data);
36 const handleJobSubmit = async (e) => {
37 e.preventDefault();
38 await fetch("/jobs", {
39 method: "POST",
40 headers: { "Content-Type": "application/json" },
41 body: JSON.stringify(newJob)
42 });
43 fetchJobs();
44 setNewJob({
45 title: "",
55 const handleChatSubmit = async (e) => {
56 e.preventDefault();
57 await fetch("/messages", {
58 method: "POST",
59 headers: { "Content-Type": "application/json" },
60 body: JSON.stringify({ text: chatMessage })
61 });
62 fetchMessages();
63 setChatMessage("");
64 };
33
34// Export the Hono app for Val Town
35export default app.fetch;
36
37// Error handler to expose full error details
42
43// Export the Hono app for Val Town
44export default app.fetch;
1import { email } from "https://esm.town/v/std/email?v=9";
2
3// Fetches a random joke.
4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",
7 );
9}
10
11const randomJoke = await fetchRandomJoke();
12const setup = randomJoke.setup;
13const punchline = randomJoke.punchline;
10 const handleSubmit = async (e) => {
11 e.preventDefault();
12 const response = await fetch("/post-job", {
13 method: "POST",
14 headers: { "Content-Type": "application/json" },
53 const [jobs, setJobs] = useState([]);
54
55 const fetchJobs = async () => {
56 const response = await fetch("/get-jobs");
57 const data = await response.json();
58 setJobs(data);
60
61 useEffect(() => {
62 fetchJobs();
63 }, []);
64
83 const [newMessage, setNewMessage] = useState("");
84
85 const fetchMessages = async () => {
86 const response = await fetch("/get-messages");
87 const data = await response.json();
88 setMessages(data);
91 const sendMessage = async (e) => {
92 e.preventDefault();
93 const response = await fetch("/send-message", {
94 method: "POST",
95 headers: { "Content-Type": "application/json" },
98 if (response.ok) {
99 setNewMessage("");
100 fetchMessages();
101 }
102 };
103
104 useEffect(() => {
105 fetchMessages();
106 const interval = setInterval(fetchMessages, 5000);
107 return () => clearInterval(interval);
108 }, []);
13 setIsLoading(true);
14 try {
15 const response = await fetch("/generate-ideas", {
16 method: "POST",
17 headers: {