Skip to content

Commit

Permalink
deps file
Browse files Browse the repository at this point in the history
  • Loading branch information
uriva committed Feb 25, 2024
1 parent 7716cbb commit 991e7c7
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 30 deletions.
4 changes: 0 additions & 4 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"tasks": {
"build": "deno run --allow-env --allow-read --allow-write --allow-net --allow-run build_npm.ts"
},
"imports": {
"gamla": "https://deno.land/x/[email protected]/src/index.ts",
"grammy_types": "https://deno.land/x/[email protected]/mod.ts"
}
}
2 changes: 2 additions & 0 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * as gamla from "https://deno.land/x/[email protected]/src/index.ts";
export * as grammy from "https://deno.land/x/[email protected]/mod.ts";
3 changes: 2 additions & 1 deletion example/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import {
withSpinner,
} from "../src/index.ts";

import { coerce, sleep } from "gamla";
import { gamla } from "../deps.ts";
import { reply } from "../src/api.ts";
import {
whatsappBusinessHandler,
whatsappWebhookVerificationHandler,
} from "../src/whatsapp.ts";

const { coerce, sleep } = gamla;
const telegramToken = coerce(Deno.env.get("TELEGRAM_TOKEN"));
const botServerSuffix = "/bot-url-suffix";

Expand Down
4 changes: 3 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { context } from "gamla";
import { gamla } from "../deps.ts";

const { context } = gamla;

export const { inject: injectFileLimitMB, access: fileLimitMB } = context(() =>
Infinity
Expand Down
5 changes: 4 additions & 1 deletion src/greenApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { pipe } from "gamla";
import { gamla } from "../deps.ts";

// @ts-expect-error no typing
import greenApi from "npm:@green-api/whatsapp-api-client";

const { pipe } = gamla;

import {
injectFileLimitMB,
injectReply,
Expand Down
4 changes: 3 additions & 1 deletion src/taskBouncer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { coerce, sideLog } from "gamla";
import http from "node:http";
import querystring from "node:querystring";
import url from "node:url";
import { gamla } from "../deps.ts";

const { coerce, sideLog } = gamla;

const getJson = <T>(req: http.IncomingMessage): Promise<T> =>
new Promise((resolve, reject) => {
Expand Down
35 changes: 16 additions & 19 deletions src/telegram.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { coerce, letIn, max, pipe, prop, retry, sleep, throttle } from "gamla";
import {
Contact,
File,
Message,
ParseMode,
PhotoSize,
Update,
} from "grammy_types";
import { Readable } from "node:stream";
import { Telegraf, Telegram } from "npm:telegraf";

import { gamla, grammy } from "../deps.ts";

const { coerce, letIn, max, pipe, prop, retry, sleep, throttle } = gamla;

import { encodeBase64 } from "https://deno.land/[email protected]/encoding/base64.ts";
import { get } from "node:https";
import {
Expand Down Expand Up @@ -111,7 +106,7 @@ export const sendTelegramMessage = (token: string) =>
chat_id,
text,
disable_web_page_preview: true,
parse_mode: "HTML" as ParseMode,
parse_mode: "HTML" as grammy.ParseMode,
}),
}).then((r) =>
r.json()
Expand All @@ -136,7 +131,7 @@ const fileIdToContentBase64 =
);
if (!response.ok) throw new Error("could not fetch photo url");
const { result: { file_path } } = (await response.json()) as {
result: File;
result: grammy.File;
};
const imageResponse = await fetch(
`https://api.telegram.org/file/bot${token}/${file_path}`,
Expand All @@ -147,21 +142,23 @@ const fileIdToContentBase64 =

const image = (token: string) =>
pipe(
max(prop<PhotoSize>()("width")),
prop<PhotoSize>()("file_id"),
max(prop<grammy.PhotoSize>()("width")),
prop<grammy.PhotoSize>()("file_id"),
fileIdToContentBase64(token),
);

const sharedOwnPhone = (ownId: number, { user_id, phone_number }: Contact) =>
(user_id === ownId) ? phone_number : undefined;
const sharedOwnPhone = (
ownId: number,
{ user_id, phone_number }: grammy.Contact,
) => (user_id === ownId) ? phone_number : undefined;

const contactToFullName = ({ first_name, last_name }: Contact) =>
const contactToFullName = ({ first_name, last_name }: grammy.Contact) =>
first_name + (last_name ? " " + last_name : "");

export const getBestPhoneFromContactShared = ({
phone_number,
vcard,
}: Contact) => {
}: grammy.Contact) => {
if (!vcard) return phone_number;
const lines = vcard.split("\n");
const preferredCellphone = lines.find(
Expand All @@ -177,7 +174,7 @@ export const getBestPhoneFromContactShared = ({

const abstractMessage = (token: string) =>
async (
msg: Message,
msg: grammy.Message,
): Promise<AbstractIncomingMessage> => ({
text: msg.text,
contact: msg.contact && {
Expand All @@ -198,7 +195,7 @@ export const makeTelegramHandler = (
bounce: true,
method: "POST",
path,
handler: ({ message }: Update) =>
handler: ({ message }: grammy.Update) =>
message?.from && message.text
? pipe(
abstractMessage(telegramToken),
Expand Down
4 changes: 2 additions & 2 deletions src/websocket.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { complement, equals, nonempty, pipe } from "gamla";
import http from "node:http";
import { WebSocket, WebSocketServer } from "npm:ws";

import { gamla } from "../deps.ts";
import {
injectFileLimitMB,
injectProgressBar,
Expand All @@ -13,6 +12,7 @@ import {
UniqueUserId,
} from "./api.ts";

const { complement, equals, nonempty, pipe } = gamla;
type Messsage = {
key?: number;
text?: string;
Expand Down
4 changes: 3 additions & 1 deletion src/whatsapp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { anymap, coerce, letIn, pipe, sideLog } from "gamla";
import {
injectBotPhone,
injectReply,
Expand All @@ -7,6 +6,9 @@ import {
} from "./api.ts";
import { TaskHandler } from "./index.ts";
import { Endpoint } from "./taskBouncer.ts";
import { gamla } from "../deps.ts";

const { anymap, coerce, letIn, pipe, sideLog } = gamla;

export const sendWhatsappMessage =
(accessToken: string, fromNumberId: string) =>
Expand Down

0 comments on commit 991e7c7

Please sign in to comment.