-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,7 +92,13 @@ For backward compatibility reasons, invalid \`routeParams\` will be treated as \ | |
`, | ||
}, | ||
features: { | ||
requireConfig: false, | ||
requireConfig: [ | ||
{ | ||
name: 'TELEGRAM_SESSION', | ||
optional: true, | ||
description: '', | ||
}, | ||
], | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportBT: false, | ||
|
@@ -110,13 +116,12 @@ For backward compatibility reasons, invalid \`routeParams\` will be treated as \ | |
handler, | ||
description: ` | ||
:::tip | ||
Due to Telegram restrictions, some channels involving pornography, copyright, and politics cannot be subscribed. You can confirm by visiting \`https://t.me/s/:username\`. | ||
Due to Telegram restrictions, some channels involving pornography, copyright, and politics cannot be subscribed. You can confirm by visiting \`https://t.me/s/:username\`, it's recommended to deploy your own instance with configs (create your telegram via \`https://core.telegram.org/api/obtaining_api_id\`, run this command \`node ./lib/routes/telegram/scripts/get-telegram-session.mjs\` to get \`TELEGRAM_SESSION\` and set it as Environment Variable). | ||
:::`, | ||
}; | ||
|
||
async function handler(ctx) { | ||
const useWeb = ctx.req.param('routeParams') || !config.telegram.session; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pseudoyu
Author
Collaborator
|
||
if (!useWeb) { | ||
if (ctx.req.param('routeParams') && config.telegram.session) { | ||
return tglibchannel(ctx); | ||
} | ||
|
||
|
@@ -191,6 +196,10 @@ async function handler(ctx) { | |
: $('.tgme_widget_message_wrap:not(.tgme_widget_message_wrap:has(.service_message,.tme_no_messages_found))'); // also exclude service messages | ||
|
||
if (list.length === 0 && $('.tgme_channel_history').length === 0) { | ||
if (config.telegram.session) { | ||
return tglibchannel(ctx); | ||
} | ||
|
||
throw new Error(`Unable to fetch message feed from this channel. Please check this URL to see if you can view the message preview: ${resourceUrl}`); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { TelegramClient } from 'telegram'; | ||
import { StringSession } from 'telegram/sessions/index.js'; | ||
import readline from 'readline'; | ||
|
||
function userInput(question) { | ||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout | ||
}); | ||
return new Promise((resolve) => { | ||
rl.question(question, (answer) => { | ||
rl.close(); | ||
resolve(answer); | ||
}); | ||
}); | ||
} | ||
|
||
async function getSessionString() { | ||
const apiId = parseInt(await userInput('Please enter your API ID: ')); | ||
const apiHash = await userInput('Please enter your API Hash: '); | ||
const stringSession = new StringSession(''); | ||
const client = new TelegramClient(stringSession, apiId, apiHash, { | ||
connectionRetries: 5, | ||
}); | ||
await client.start({ | ||
phoneNumber: async () => await userInput('Please enter your phone number: '), | ||
password: async () => await userInput('Please enter your password: '), | ||
phoneCode: async () => await userInput('Please enter the code you received: '), | ||
onError: (err) => console.log(err), | ||
This comment has been minimized.
Sorry, something went wrong.
CaoMeiYouRen
Contributor
|
||
}); | ||
|
||
console.log('You are now connected.'); | ||
const sessionString = client.session.save(); | ||
|
||
console.log('Your session string is:', sessionString); | ||
await client.disconnect(); | ||
return sessionString; | ||
} | ||
|
||
// Run the function | ||
getSessionString().catch(console.error); |
Is it reversing the logic? 🤔
Was: use tglib if no
routeParams
are defined and session is defined.Now: use tglig if
routeParams
are defined and session is defined.I'm just making sure there are no unexpected bugs. Please correct me if I'm wrong.