link
Constants
Telegram API contains so many types of objects and updates. It's easy to make a typo or miss some changes when new version of TDLib is coming. To prevent it, Airgram provides a package with names of all the types, predicates and updates.
link
Installation
npm install @airgram/constants
link
Usage
In the following example we import UPDATE
and AUTHORIZATION_STATE
enums and use them instead of string
values:
import { UPDATE, AUTHORIZATION_STATE } from '@airgram/constants'
airgram.on(UPDATE.updateAuthorizationState, async ({ update }, next) => {
const { authorizationState } = update
switch (authorizationState._) {
case AUTHORIZATION_STATE.authorizationStateWaitPhoneNumber: {
await airgram.api.setAuthenticationPhoneNumber({
phoneNumber: '1234567890'
})
break
}
case AUTHORIZATION_STATE.authorizationStateWaitCode: {
await airgram.api.checkAuthenticationCode({
code: '1234'
})
break
}
case AUTHORIZATION_STATE.authorizationStateReady: {
console.log('Success authorization!')
return next()
}
default: {
return next()
}
}
})