问题描述
我想从不同的频道收集新闻,并在第二个频道中回显它们,而我可以用代码读取频道(不是全部,而是全部)。
我现在在回声问题上停留了一段时间,对如何做到这一点一无所知,mtproto对我来说是全新的,谢谢。
我正在使用下面来自另一个stackoverflow问题的代码。
const { MTProto,getSRPParams } = require('@mtproto/core');
const prompts = require('prompts');
const api_id = 'xxxxx';
const api_hash = 'xxxxx';
async function getPhone() {
return (await prompts({
type: 'text',name: 'phone',message: 'Enter your phone number:'
})).phone
}
async function getCode() {
// you can implement your code fetching strategy here
return (await prompts({
type: 'text',name: 'code',message: 'Enter the code sent:',})).code
}
async function getpassword() {
return (await prompts({
type: 'text',name: 'password',message: 'Enter Password:',})).password
}
const mtproto = new MTProto({
api_id,api_hash,});
function startListener() {
console.log('[+] starting listener')
mtproto.updates.on('updates',({ updates }) => {
const newChannelMessages = updates.filter((update) => update._ === 'updateNewChannelMessage').map(({ message }) => message) // filter `updateNewChannelMessage` types only and extract the 'message' object
for (const message of newChannelMessages) {
// printing new channel messages
console.log(`[${message.to_id.channel_id}] ${message.message}`)
}
});
}
// checking authentication status
mtproto
.call('users.getFullUser',{
id: {
_: 'inputUserSelf',},})
.then(startListener) // means the user is logged in -> so start the listener
.catch(async error => {
// The user is not logged in
console.log('[+] You must log in')
const phone_number = await getPhone()
mtproto.call('auth.sendCode',{
phone_number: phone_number,settings: {
_: 'codeSettings',})
.catch(error => {
if (error.error_message.includes('_MIGRATE_')) {
const [type,nextDcId] = error.error_message.split('_MIGRATE_');
mtproto.setDefaultDc(+nextDcId);
return sendCode(phone_number);
}
})
.then(async result => {
return mtproto.call('auth.signIn',{
phone_code: await getCode(),phone_number: phone_number,phone_code_hash: result.phone_code_hash,});
})
.catch(error => {
if (error.error_message === 'SESSION_PASSWORD_NEEDED') {
return mtproto.call('account.getpassword').then(async result => {
const { srp_id,current_algo,srp_B } = result;
const { salt1,salt2,g,p } = current_algo;
const { A,M1 } = await getSRPParams({
g,p,salt1,gB: srp_B,password: await getpassword(),});
return mtproto.call('auth.checkPassword',{
password: {
_: 'inputCheckPasswordSRP',srp_id,A,M1,});
});
}
})
.then(result => {
console.log('[+] successfully authenticated');
// start listener since the user has logged in Now
startListener()
});
})
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)