-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into pdfs-uploading
- Loading branch information
Showing
18 changed files
with
316 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Deno lint | ||
|
||
on: [push, pull_request] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Setup repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Deno | ||
uses: denoland/setup-deno@v1 | ||
with: | ||
deno-version: v1.x | ||
|
||
- name: Run linter | ||
run: deno lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Deno tests | ||
|
||
on: [push, pull_request] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Setup repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Deno | ||
uses: denoland/setup-deno@v1 | ||
with: | ||
deno-version: v1.x | ||
|
||
- name: Run tests | ||
run: deno test -A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,19 +3,24 @@ import { | |
Bot, | ||
GrammyError, | ||
HttpError, | ||
} from 'https://deno.land/x/grammy@v1.20.3/mod.ts' | ||
} from 'https://deno.land/x/grammy@v1.21.1/mod.ts' | ||
import { createConversation } from 'https://deno.land/x/[email protected]/conversation.ts' | ||
import { conversations } from 'https://deno.land/x/[email protected]/mod.ts' | ||
import { | ||
askApiKey, | ||
saveBunchUrls, | ||
setDefaultLabel, | ||
updateToken, | ||
} from './src/conversations.ts' | ||
import { cancelMenu } from './src/menus.ts' | ||
import { OmnivoreApi } from './src/omnivore/api.ts' | ||
import { MyContext, sessionHandler } from './src/sessionsHandler.ts' | ||
import { inlineQuery } from "./src/inlineQuery.ts"; | ||
import { fileListener } from "./src/files.ts"; | ||
import { slashCommandsListener } from './src/slashCommands.ts' | ||
import { cancelMenuAndResetLabel } from "./src/menus.ts"; | ||
import { getUrlAndLabels } from "./src/utils/getUrlAndLabels.ts"; | ||
import { includeSourceChoiceMenu } from "./src/menus.ts"; | ||
|
||
await load({ export: true }) | ||
|
||
|
@@ -31,29 +36,37 @@ bot.use(conversations()) | |
bot.use(createConversation(askApiKey)) | ||
bot.use(createConversation(saveBunchUrls)) | ||
bot.use(createConversation(updateToken)) | ||
bot.use(createConversation(setDefaultLabel)) | ||
|
||
// Menu | ||
bot.use(cancelMenu) | ||
bot.use(cancelMenuAndResetLabel) | ||
bot.use(includeSourceChoiceMenu) | ||
|
||
// inline query | ||
bot.use(inlineQuery) | ||
|
||
// file handling | ||
bot.use(fileListener) | ||
|
||
// slash commands handler | ||
bot.use(slashCommandsListener) | ||
|
||
// handlers | ||
bot.on('message:entities:url', async ctx => { | ||
// retrieve stuff from session | ||
const token = ctx.session.apiToken | ||
|
||
const api = new OmnivoreApi(token) | ||
|
||
await api.saveUrl(ctx.message.text || '') | ||
const {url, labels} = getUrlAndLabels(ctx) | ||
|
||
if (api.addedEntriesCount === 1) { | ||
await ctx.reply('Successfully added link to Omnivore! 😸👍') | ||
} else { | ||
await ctx.reply('Failed to add the link. 😿') | ||
} | ||
await api.saveUrl(url, labels) | ||
|
||
const feedback = api.addedEntriesCount === 1 | ||
? 'Successfully added link to Omnivore! 😸👍' | ||
: 'Failed to add the link. 😿' | ||
|
||
await ctx.reply(feedback) | ||
}) | ||
|
||
bot.command('start', async ctx => { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ import { | |
} from './graphql.ts' | ||
import { InlineQueryResultBuilder } from 'https://deno.land/x/[email protected]/mod.ts' | ||
import { File } from "https://deno.land/x/[email protected]/message.ts"; | ||
import { InlineQueryResultBuilder } from 'https://deno.land/x/[email protected]/mod.ts' | ||
import { Label, ProcessUrlsParams } from "../types.ts"; | ||
|
||
interface OmnivoreApiInterface { | ||
apiToken: string | ||
|
@@ -29,12 +31,13 @@ export class OmnivoreApi implements OmnivoreApiInterface { | |
this.apiToken = apiToken | ||
} | ||
|
||
async saveUrl(url: string) { | ||
async saveUrl(url: string, labels: Label[]) { | ||
const variables = { | ||
input: { | ||
clientRequestId: globalThis.crypto.randomUUID(), | ||
source: 'api', | ||
url, | ||
labels | ||
}, | ||
} | ||
|
||
|
@@ -70,13 +73,18 @@ export class OmnivoreApi implements OmnivoreApiInterface { | |
} | ||
} | ||
|
||
async processUrls(urls: string[], startIndex = 0) { | ||
async processUrls({ urls, additionalLabels, startIndex = 0 }: ProcessUrlsParams) { | ||
const batchSize = 50 | ||
const remainingUrls = urls.slice(startIndex) | ||
|
||
for (let i = 0; i <= batchSize && i < remainingUrls.length; i++) { | ||
const url = remainingUrls[i] | ||
await this.saveUrl(url) | ||
const url = remainingUrls[i].url | ||
const urlLabels = remainingUrls[i].labels | ||
|
||
// add additional labels to each url | ||
additionalLabels?.map((label) => urlLabels.push(label)) | ||
|
||
await this.saveUrl(url, urlLabels) | ||
} | ||
|
||
const nextIndex = startIndex + batchSize + 1 | ||
|
@@ -85,7 +93,7 @@ export class OmnivoreApi implements OmnivoreApiInterface { | |
await new Promise(resolve => | ||
setTimeout(resolve, OmnivoreApi.delayBetweenRequests) | ||
) | ||
await this.processUrls(urls, nextIndex) | ||
await this.processUrls({urls, startIndex: nextIndex}) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import { | |
Context, | ||
session, | ||
SessionFlavor, | ||
} from 'https://deno.land/x/grammy@v1.20.3/mod.ts' | ||
} from 'https://deno.land/x/grammy@v1.21.1/mod.ts' | ||
import { createClient } from 'https://esm.sh/@supabase/[email protected]' | ||
import { supabaseAdapter } from 'https://deno.land/x/[email protected]/supabase/src/mod.ts' | ||
import { load } from 'https://deno.land/[email protected]/dotenv/mod.ts' | ||
|
@@ -22,6 +22,8 @@ const storage = supabaseAdapter({ | |
|
||
interface SessionData { | ||
apiToken: string | ||
defaultLabel: string | ||
includeSource: boolean | ||
} | ||
|
||
export type MyContext = Context & | ||
|
@@ -31,6 +33,8 @@ export type MyContext = Context & | |
function initial(): SessionData { | ||
return { | ||
apiToken: '', | ||
defaultLabel: '', | ||
includeSource: false | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Composer } from 'https://deno.land/x/[email protected]/mod.ts' | ||
import { MyContext } from './sessionsHandler.ts' | ||
import { cancelMenuAndResetLabel, includeSourceChoiceMenu } from "./menus.ts"; | ||
|
||
export const slashCommandsListener = new Composer<MyContext>() | ||
|
||
slashCommandsListener.hears('/set_default_label', async ctx => { | ||
ctx.reply( | ||
'Send the label you want to be added for all of the links you send me', | ||
{ | ||
reply_markup: cancelMenuAndResetLabel, | ||
} | ||
) | ||
|
||
await ctx.conversation.enter('setDefaultLabel') | ||
}) | ||
|
||
slashCommandsListener.hears('/set_include_source', ctx => { | ||
ctx.reply( | ||
'Do you want to include label from what channel or contact you\'ve saved the article?', { | ||
reply_markup: includeSourceChoiceMenu | ||
}) | ||
}) |
Oops, something went wrong.
02d123d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failed to deploy: