Skip to content

Instantly share code, notes, and snippets.

View waptik's full-sized avatar
💻
Learning JavaScript and ReactJS...

TheVirginBrokey waptik

💻
Learning JavaScript and ReactJS...
View GitHub Profile
@waptik
waptik / crypto.ts
Last active October 23, 2023 03:26
Immitating nodejs' cryptoHmac+Buffer.from in Deno by reproducing lemonsqueezy's webhook payload signing(https://github.com/amosbastian/template/blob/bdc77731d4f0dfef0bd2529205c8dd5b733d5b4a/apps/web/app/api/lemonsqueezy/route.ts#L76)
// @see https://github.com/denoland/deno/blob/main/cli/tests/unit_node/crypto/crypto_hash_test.ts#L17
export * as crypto from 'node:crypto';
@waptik
waptik / bot.ts
Last active April 29, 2024 11:27
An example on how to use grammY's Interactive Menus plugin
// I'm using deno
import "https://deno.land/[email protected]/dotenv/load.ts";
import { green } from "https://deno.land/[email protected]/fmt/colors.ts";
import { itemsMenu } from './menus/example.menu.ts';
const grammy = new Bot<GrammyContext>(Deno.env.get("BOT_TOKEN")||""); // replace `BOT_TOKEN` inside `.env` file with your own telegram bot's token
// attaching the menu to bot to get it to work if not we'll get the following errors inside the terminal
// `Error: Cannot send menu 'bot-items-menu'! Did you forget to use bot.use() for it?`
@waptik
waptik / bot.ts
Last active March 27, 2025 14:19
This is a minimal codebase of getting grammY to work with nextjs pages directory. Please use this version of `next-connect`: `"next-connect": "^0.13.0",`
import { Bot, Context } from "grammy";
export const bot = new Bot<Context>(process.env.TELEGRAM_BOT_TOKEN ?? "");
@waptik
waptik / webapp.html
Created June 14, 2023 03:58
rendered webapp page in deno fresh
<html
lang="en"
style="--tg-viewport-height: 100vh; --tg-viewport-stable-height: 100vh"
>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script
src="/_frsh/refresh.js"
nonce="1734e1df1f3e44caaee66e087bc657e6"
@waptik
waptik / openai.ts
Last active April 29, 2023 10:42
a custom class that makes use of Langchain + openai model
import config from "$config/mod.ts";
import {
initializeAgentExecutorWithOptions,
} from "langchain/agents";
import { BaseLanguageModel } from "langchain/base_language";
import { CallbackManager, ConsoleCallbackHandler } from "langchain/callbacks";
import { ChatOpenAI } from "langchain/chat_models/openai";
import { Calculator } from "langchain/tools/calculator";
import { BaseChatMessage } from "langchain/schema";
import { assert } from "asserts";
@waptik
waptik / upstash_redis_adapter_v0-1.ts
Last active April 2, 2023 08:08
This is an implementation of an adapter powered by upstash redis, for grammy.dev
import { Redis } from "https://deno.land/x/[email protected]/mod.ts";
import { StorageAdapter } from "~grammy/deps.ts";
/**
* A storage adapter that uses upstash redis.
* @template T The type of the data to store.
*
* Implementation of StorageAdapter v2 were inspired by @grammyjs/storage-cloudflare
* @see {@link "https://github.com/grammyjs/storages/blob/main/packages/cloudflare/src/kv.ts"}
*/
@waptik
waptik / errors.ts
Created March 24, 2023 20:51
type error when using [email protected] with current version of gramm_chat_members plugin
When i hover `chatMembers`, i get:
```
Argument of type 'Composer<ChatMembersContext>' is not assignable to parameter of type 'Middleware<GrammyContext>'.
Type 'Composer<ChatMembersContext>' is not assignable to type 'MiddlewareObj<GrammyContext>'.
The types returned by 'middleware()' are incompatible between these types.
Type 'MiddlewareFn<ChatMembersContext>' is not assignable to type 'MiddlewareFn<GrammyContext>'.
Types of parameters 'ctx' and 'ctx' are incompatible.
Type 'GrammyContext' is not assignable to type 'ChatMembersContext'.
Type 'SessionFlavor<GrammySession> & { conversation: ConversationControls; } & SessionFlavor<ConversationSessionData> & ChatMembersFlavor & Context & { ...; }' is not assignable to type 'ChatMembersContext'.
Type 'SessionFlavor<GrammySession> & { conversation: ConversationControls; } & SessionFlavor<ConversationSessionData> & ChatMembersFlavor & Context & { ...; }' is not assignable to type 'Context'.
@waptik
waptik / errors.ts
Created March 24, 2023 20:51
type error when using [email protected] with current version of gramm_chat_members plugin
When i hover `chatMembers`, i get:
```
Argument of type 'Composer<ChatMembersContext>' is not assignable to parameter of type 'Middleware<GrammyContext>'.
Type 'Composer<ChatMembersContext>' is not assignable to type 'MiddlewareObj<GrammyContext>'.
The types returned by 'middleware()' are incompatible between these types.
Type 'MiddlewareFn<ChatMembersContext>' is not assignable to type 'MiddlewareFn<GrammyContext>'.
Types of parameters 'ctx' and 'ctx' are incompatible.
Type 'GrammyContext' is not assignable to type 'ChatMembersContext'.
Type 'SessionFlavor<GrammySession> & { conversation: ConversationControls; } & SessionFlavor<ConversationSessionData> & ChatMembersFlavor & Context & { ...; }' is not assignable to type 'ChatMembersContext'.
Type 'SessionFlavor<GrammySession> & { conversation: ConversationControls; } & SessionFlavor<ConversationSessionData> & ChatMembersFlavor & Context & { ...; }' is not assignable to type 'Context'.
@waptik
waptik / getParticipants.ts
Created January 21, 2023 09:50
[GramJS] - Getting participant object in group and channel chats
// The code below works for both gramjs in node and grm in deno
.... // other imports above
import ChannelParticipants = Api.channels.ChannelParticipants;
import ChatParticipant = Api.ChatParticipant;
import ChannelParticipant = Api.ChannelParticipant;
@waptik
waptik / Upload.tsx
Last active October 13, 2022 20:27
A POC for uploading files to a cloudflare r2 public bucket using presigned url in nextjs
// pages/Upload.tsx
import { getPresignedUrl } from "~/utils/files";
export default function Upload() {
const uploadPhoto = async (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
const name = encodeURIComponent(file?.name as string);
const type = encodeURIComponent(file?.type as string);
const res = await getPresignedUrl({ name, type, size: "" + file!.size });