Comments (12)
adding a counter will solve the error part
let counter = false;
airgram.on(UPDATE.updateAuthorizationState, async ({ update }, next) => {
const { authorizationState } = update;
if (authorizationState._ === AUTHORIZATION_STATE.authorizationStateWaitCode && counter === false) {
counter = true;
airgram.api.resendAuthenticationCode().then(() => {
}).catch(err => {
console.error(err)
});
}
return next();
});
from airgram.
and it's not logging in
from airgram.
the full code i use is @airgram
import mongoose from 'mongoose';
import { Airgram, Auth, prompt } from 'airgram';
import { UPDATE, AUTHORIZATION_STATE } from 'airgram-api';
import provider from './lib/provider';
import getInput from './lib/getInput';
import generateName from './lib/generateName';
import { User } from './models';
const LOCAL_DB = 'telegram-reader';
const MONGODB_URI = process.env.MONGODB_URI || `mongodb://localhost/${LOCAL_DB}`;
// MongoDB
// mongoose.set('debug', true);
mongoose.Promise = global.Promise;
mongoose.connect(MONGODB_URI, {
useNewUrlParser: true,
useCreateIndex: true,
autoIndex: true,
useFindAndModify: false,
});
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
const main = async () => {
while (true) {
const phoneNumber = String(await getInput('Please Enter phone Number'));
const airgram = new Airgram({
provider: provider(),
apiId: *****,
apiHash: '** * ***',
databaseDirectory: `./db/${phoneNumber}`,
});
let counter = false;
airgram.on(UPDATE.updateAuthorizationState, async ({ update }, next) => {
const { authorizationState } = update;
if (
authorizationState._ === AUTHORIZATION_STATE.authorizationStateWaitCode
&& counter === false
) {
counter = true;
await airgram.api
.resendAuthenticationCode()
.then(() => {
console.log('Please get ready to get call');
})
.catch(() => {
console.error('please try with another number');
});
}
return next();
});
const auth = new Auth(airgram);
await auth.use({
code: () => prompt('Please enter code'),
phoneNumber,
firstName: generateName().firstName,
lastName: generateName().lastName,
});
await airgram.api.getMe().then((res) => {
console.log('logged in user is ', res.firstName, res.lastName);
});
await User.findOneAndUpdate(
{ phoneNumber },
{ phoneNumber, alive: true, lastUsed: new Date() },
{ upsert: true },
);
}
};
main();
from airgram.
Fixed logging in part with airgram-api fix. but duplicate input part is not fixed yet
from airgram.
If you need to cancel previous prompt, try to wrap prompt
function something like that:
let prevPrompt: { resolve: (data: any) => any, reject: (error: Error) => any } | null
auth.use({
code: () => new Promise((resolve, reject) => {
if (prevPrompt) {
prevPrompt.reject(new Error('Expired prompt'))
}
prevPrompt = { resolve, reject }
return prompt('Please enter code')
.then(resolve, reject)
.finally(() => prevPrompt = null)
})
})
from airgram.
Nice code but this doesn't fix the problem it won't cancel previous promt
from airgram.
I see. Please check out this code with version 1.1.1
:
import { Airgram, Auth, prompt, PromptDeferred } from 'airgram'
const auth = new Auth(airgram)
let prevPrompt: PromptDeferred | null
auth.use({
code: () => prompt('Please enter code', (deferred: PromptDeferred) => {
if (prevPrompt) {
prevPrompt.reject(new Error('Expired prompt'))
}
prevPrompt = deferred
})
})
from airgram.
the duplicate input problem is fixed now but not authing problem re-happened @airgram
from airgram.
Actually, I am not sure what you do and why you need to resend authorization code. Maybe your approach is not correct. Can you clarify it?
from airgram.
I want to shorten telegram official app's calling(resend code via phone) time. building a new telegram app
from airgram.
When Auth
middleware got authorization status authorizationStateWaitPhoneNumber
and receive phone number, Airgram invokes setAuthenticationPhoneNumber
method. So you should not use resendAuthenticationCode
immediately.
Probably, you need to have possibility to set allowFlashCall
and isCurrentPhoneNumber
parameters for the setAuthenticationPhoneNumber
method.
from airgram.
Thankyou
from airgram.
Related Issues (20)
- error {code = 400 message = "Failed to parse JSON object as TDLib request: Can't parse "<bot_id_string>" as an integer"}
- failed authentication telegram when using self signed certificate
- check sending status
- how to import telegram web UI
- how to import telegram web UI
- Valid api_id must be provided. Can be obtained at HOT 10
- Chat info not found
- API object show empty {} and not working any api function
- Airgram JavaScript example not working HOT 1
- TdLib 1.8.6+ requires modified authorization object. HOT 1
- Example/how-to on how to access database (messages)?
- Reactions missing from MessageInteractionInfo
- is posible, create and manage bots with airgram?
- Enable `ignore_background_updates` in Airgram HOT 1
- spoilered message is unsupported
- "@airgram/web": "^5.0.0", cannot send images when running on the browser. No matter what value the Path is set to, it will display [sendMessage][400] Can't find real file path.
- Incompatible architecture [macOS]
- Auth Problem: Cant receive code
- Execute bot command in 1-1 personal chat instead of showing command text
- Is this project maintained? the current version is not compatible with the latest version of TDLib
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from airgram.