-
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.
πΎ Bunch of features for sending urls with labels (#6)
- Loading branch information
Showing
16 changed files
with
259 additions
and
96 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 |
---|---|---|
|
@@ -3,18 +3,23 @@ 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 { 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 }) | ||
|
||
|
@@ -30,26 +35,34 @@ 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) | ||
|
||
// 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
Oops, something went wrong.