How to use @airgram/constants - 3 common examples

To help you get started, we’ve selected a few @airgram/constants examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github airgram / airgram / examples / custom-context / src / index.ts View on Github external
phoneNumber: () => prompt('Please enter your phone number:\n')
}))

airgram.on(UPDATE.updateUser, async ({ $store, update }, next) => {
  const { user } = update
  $store.users.set(user.id, user)
  return next()
})

airgram.on(UPDATE.updateNewChat, async ({ $store, update }, next) => {
  const { chat } = update
  $store.chats.set(chat.id, chat)
  return next()
})

airgram.on(UPDATE.updateChatLastMessage, async ({ $store, update }, next) => {
  $store.chatLastMessage.set(update.chatId, update)
  return next()
})

airgram.api.getChats({
  limit: 10,
  offsetChatId: 0,
  offsetOrder: '9223372036854775807' // 2^63
}).then(({ response, $store }) => {
  if (isError(response)) {
    throw new Error(`[TDLib][${response.code}] ${response.message}`)
  }
  const chats = response.chatIds.map((chatId) => {
    const chat = $store.chats.get(chatId)
    const message = $store.chatLastMessage.get(chatId)
github airgram / airgram / examples / custom-context / src / index.ts View on Github external
// the following option allows to extend the base context
  context: { $store: store }
})

airgram.use(new Auth({
  code: () => prompt('Please enter the secret code:\n'),
  phoneNumber: () => prompt('Please enter your phone number:\n')
}))

airgram.on(UPDATE.updateUser, async ({ $store, update }, next) => {
  const { user } = update
  $store.users.set(user.id, user)
  return next()
})

airgram.on(UPDATE.updateNewChat, async ({ $store, update }, next) => {
  const { chat } = update
  $store.chats.set(chat.id, chat)
  return next()
})

airgram.on(UPDATE.updateChatLastMessage, async ({ $store, update }, next) => {
  $store.chatLastMessage.set(update.chatId, update)
  return next()
})

airgram.api.getChats({
  limit: 10,
  offsetChatId: 0,
  offsetOrder: '9223372036854775807' // 2^63
}).then(({ response, $store }) => {
  if (isError(response)) {
github airgram / airgram / examples / custom-context / src / index.ts View on Github external
const airgram = new Airgram({
  apiId: process.env.APP_ID as number | undefined,
  apiHash: process.env.APP_HASH,
  command: process.env.TDLIB_COMMAND,
  databaseDirectory: '../../db',
  logVerbosityLevel: 2,
  // the following option allows to extend the base context
  context: { $store: store }
})

airgram.use(new Auth({
  code: () => prompt('Please enter the secret code:\n'),
  phoneNumber: () => prompt('Please enter your phone number:\n')
}))

airgram.on(UPDATE.updateUser, async ({ $store, update }, next) => {
  const { user } = update
  $store.users.set(user.id, user)
  return next()
})

airgram.on(UPDATE.updateNewChat, async ({ $store, update }, next) => {
  const { chat } = update
  $store.chats.set(chat.id, chat)
  return next()
})

airgram.on(UPDATE.updateChatLastMessage, async ({ $store, update }, next) => {
  $store.chatLastMessage.set(update.chatId, update)
  return next()
})

@airgram/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.

GPL-3.0
Latest version published 2 years ago

Package Health Score

45 / 100
Full package analysis