1// View at https://lmackenzie94-htmlExample.web.val.run?name=Luke
2export default async function(req: Request): Promise<Response> {
3 const query = new URL(req.url).searchParams;
4
4const query = "\"val.town\" OR \"val town\" -_ValTown_";
5
6export async function twitterAlert({ lastRunAt }: Interval) {
7 const results = await twitterSearch({
8 query,
2import { easyAQI } from "https://esm.town/v/stevekrouse/easyAQI";
3
4export default async function(interval: Interval) {
5 const location = "Geneva"; // <-- change to place, city, or zip code
6 const data = await easyAQI({ location });
35
36export const hydrate = (importMetaURL: string) =>
37 async function(req: Request): Promise<Response> {
38 const { author, name } = extractValInfo(importMetaURL);
39 const valURL = `https://www.val.town/v/${author}/${name}`;
10 * @param authorization
11 */
12export async function telegramText(text: string, options?: TextOptions, authorization?: string) {
13 return telegramRequest("text", { text, options }, authorization);
14}
20 * @param authorization
21 */
22export async function telegramPhoto(options: PhotoOptions, authorization?: string) {
23 return telegramRequest("photo", { options }, authorization);
24}
25
26async function telegramRequest(path, body, authorization?: string) {
27 const response = await fetch("https://stevekrouse-telegramValTownAPI.web.val.run/" + path, {
28 method: "POST",
47 * @deprecated since 4/20/2024
48 */
49export async function telegram(secret: string, text: string, options?: MergedOptions) {
50 return runVal("stevekrouse.telegramValTownBot", secret, text, options);
51}
42};
43
44function handleTelegramResponse(response) {
45 console.log(response);
46 if (response.ok) {
23
24// UTILS
25function generateJWT(userId: string) {
26 return new SignJWT({ userId }).setProtectedHeader({ alg: "HS256" }).sign(SECRET);
27}
28function verifyJWT(token: string) {
29 return jwtVerify(token, SECRET);
30}
31function generateRandomString() {
32 return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
33}
1// View at https://andreterron-htmlExample.web.val.run?name=Andre
2export default async function(req: Request): Promise<Response> {
3 const query = new URL(req.url).searchParams;
4
1# OpenAI ChatGPT helper function
2
3This val uses your OpenAI token if you have one, and the @std/openai if not, so it provides limited OpenAI usage for free.
1import type { ChatCompletion, ChatCompletionCreateParamsNonStreaming, Message } from "npm:@types/openai";
2
3async function getOpenAI() {
4 // if you don't have a key, use our std library version
5 if (Deno.env.get("OPENAI_API_KEY") === undefined) {
14/**
15 * Initiates a chat conversation with OpenAI's GPT model and retrieves the content of the first response.
16 * This function can handle both single string inputs and arrays of message objects.
17 * It supports various GPT models, allowing for flexibility in choosing the model based on the application's needs.
18 *
21 * @returns {Promise<string>} A promise that resolves to the content of the first response from the completion.
22 */
23export async function chat(
24 input: string | Message[],
25 options?: Omit<ChatCompletionCreateParamsNonStreaming, "messages">,