📙
gramjs
  • Quick Start
  • Introduction
    • Advanced Installation
  • Concepts
    • Authentication
    • Updates (events)
    • Available methods
      • GetMessages
      • Uploading files
      • Downloading files
      • Getting participants of a group/channel
    • Handling Errors
    • Browser
  • FAQ
  • Raw Methods (Generated)
  • Accepting the Terms of Service
    • help.acceptTermsOfService
    • help.getTermsOfServiceUpdate
  • Dealing with spam and ToS violations
    • account.reportPeer
    • channels.reportSpam
    • messages.report
    • messages.reportEncryptedSpam
    • messages.reportSpam
  • Fetching configuration
    • help.dismissSuggestion
    • help.getAppChangelog
    • help.getAppConfig
    • help.getAppUpdate
    • help.getConfig
    • help.getCountriesList
    • help.getInviteText
    • help.getNearestDc
    • help.getSupport
    • help.getSupportName
  • Login via QR code
    • auth.acceptLoginToken
    • auth.exportLoginToken
    • auth.importLoginToken
  • Miscellaneous
    • help.saveAppLog
    • initConnection
    • invokeAfterMsg
    • invokeAfterMsgs
    • invokeWithLayer
    • invokeWithoutUpdates
  • Registration and Authorization
    • auth.bindTempAuthKey
    • auth.cancelCode
    • auth.checkPassword
    • auth.dropTempAuthKeys
    • auth.exportAuthorization
    • auth.importAuthorization
    • auth.importBotAuthorization
    • auth.logOut
    • auth.recoverPassword
    • auth.requestPasswordRecovery
    • auth.resendCode
    • auth.resetAuthorizations
    • auth.sendCode
    • auth.signIn
    • auth.signUp
  • Working with 2FA login
    • account.cancelPasswordEmail
    • account.confirmPasswordEmail
    • account.getPassword
    • account.getPasswordSettings
    • account.resendPasswordEmail
    • account.updatePasswordSettings
  • Working with bot inline queries and callback buttons
    • messages.editInlineBotMessage
    • messages.getBotCallbackAnswer
    • messages.getInlineBotResults
    • messages.sendInlineBotResult
    • messages.setBotCallbackAnswer
    • messages.setInlineBotResults
  • Working with bots (internal bot API use)
    • bots.answerWebhookJSONQuery
    • bots.sendCustomRequest
    • help.setBotUpdatesStatus
  • Working with bots
    • bots.setBotCommands
  • Working with channels and supergroups and geogroups
    • channels.createChannel
    • channels.deleteChannel
    • channels.deleteHistory
    • channels.deleteMessages
    • channels.deleteUserHistory
    • channels.editAdmin
    • channels.editBanned
    • channels.editCreator
    • channels.editLocation
    • channels.editPhoto
    • channels.editTitle
    • channels.exportMessageLink
    • channels.getAdminedPublicChannels
    • channels.getAdminLog
    • channels.getChannels
    • channels.getFullChannel
    • channels.getGroupsForDiscussion
    • channels.getInactiveChannels
    • channels.getMessages
    • channels.getParticipant
    • channels.getParticipants
    • channels.inviteToChannel
    • channels.joinChannel
    • channels.leaveChannel
    • channels.readHistory
    • channels.readMessageContents
    • channels.setDiscussionGroup
    • channels.setStickers
    • channels.togglePreHistoryHidden
    • channels.toggleSignatures
    • channels.toggleSlowMode
    • messages.getStatsURL
  • Working with chats and supergroups and channels
    • messages.addChatUser
    • messages.checkChatInvite
    • messages.createChat
    • messages.deleteChatUser
    • messages.editChatAbout
    • messages.editChatAdmin
    • messages.editChatDefaultBannedRights
    • messages.editChatPhoto
    • messages.editChatTitle
    • messages.exportChatInvite
    • messages.getAllChats
    • messages.getChats
    • messages.getCommonChats
    • messages.getFullChat
    • messages.importChatInvite
    • messages.migrateChat
  • Working with cloud themes
    • account.createTheme
    • account.getTheme
    • account.getThemes
    • account.installTheme
    • account.saveTheme
    • account.updateTheme
    • account.uploadTheme
  • Working with contacts and top peers
    • account.getContactSignUpNotification
    • account.setContactSignUpNotification
    • contacts.acceptContact
    • contacts.addContact
    • contacts.block
    • contacts.deleteByPhones
    • contacts.deleteContacts
    • contacts.getBlocked
    • contacts.getContactIDs
    • contacts.getContacts
    • contacts.getLocated
    • contacts.getSaved
    • contacts.getStatuses
    • contacts.getTopPeers
    • contacts.importContacts
    • contacts.resetSaved
    • contacts.resetTopPeerRating
    • contacts.search
    • contacts.toggleTopPeers
    • contacts.unblock
  • Working with credit cards
    • payments.getBankCardData
  • Working with deep links
    • help.getDeepLinkInfo
    • help.getRecentMeUrls
    • messages.startBot
  • Working with dialogs
    • messages.getDialogs
    • messages.getDialogUnreadMarks
    • messages.getOnlines
    • messages.getPeerDialogs
    • messages.getPeerSettings
    • messages.getPinnedDialogs
    • messages.hidePeerSettingsBar
    • messages.markDialogUnread
    • messages.reorderPinnedDialogs
    • messages.sendScreenshotNotification
    • messages.setTyping
    • messages.toggleDialogPin
  • Working with drafts
    • messages.clearAllDrafts
    • messages.getAllDrafts
    • messages.saveDraft
  • Working with emoji keywords
    • messages.getEmojiKeywords
    • messages.getEmojiKeywordsDifference
    • messages.getEmojiKeywordsLanguages
    • messages.getEmojiURL
  • Working with files
    • help.getCdnConfig
    • messages.getDocumentByHash
    • messages.uploadEncryptedFile
    • messages.uploadMedia
    • upload.getCdnFile
    • upload.getCdnFileHashes
    • upload.getFile
    • upload.getFileHashes
    • upload.getWebfile
    • upload.reuploadCdnFile
    • upload.saveBigFilePart
    • upload.saveFilePart
  • Working with folders
    • folders.deleteFolder
    • folders.editPeerFolders
    • messages.getDialogFilters
    • messages.getSuggestedDialogFilters
    • messages.updateDialogFilter
    • messages.updateDialogFiltersOrder
  • Working with games
    • messages.getGameHighScores
    • messages.getInlineGameHighScores
    • messages.setGameScore
    • messages.setInlineGameScore
  • Working with GDPR export
    • account.finishTakeoutSession
    • account.initTakeoutSession
    • channels.getLeftChannels
    • invokeWithMessagesRange
    • invokeWithTakeout
    • messages.getSplitRanges
  • Working with GIFs (actually MPEG4 GIFs)
    • messages.getSavedGifs
    • messages.saveGif
    • messages.searchGifs
  • Working with instant view pages
    • messages.getWebPage
    • messages.getWebPagePreview
  • Working with localization packs
    • langpack.getDifference
    • langpack.getLangPack
    • langpack.getLanguage
    • langpack.getLanguages
    • langpack.getStrings
  • Working with media autodownload settings
    • account.getAutoDownloadSettings
    • account.saveAutoDownloadSettings
  • Working with message reactions
    • messages.getMessageReactionsList
    • messages.getMessagesReactions
    • messages.sendReaction
  • Working with message threads
    • contacts.blockFromReplies
    • messages.getDiscussionMessage
    • messages.getReplies
    • messages.readDiscussion
  • Working with messages
    • messages.deleteHistory
    • messages.deleteMessages
    • messages.editMessage
    • messages.forwardMessages
    • messages.getHistory
    • messages.getMessageEditData
    • messages.getMessages
    • messages.getMessagesViews
    • messages.getRecentLocations
    • messages.getSearchCounters
    • messages.getUnreadMentions
    • messages.readHistory
    • messages.readMentions
    • messages.readMessageContents
    • messages.receivedMessages
    • messages.search
    • messages.searchGlobal
    • messages.sendMedia
    • messages.sendMessage
    • messages.sendMultiMedia
    • messages.unpinAllMessages
    • messages.updatePinnedMessage
  • Working with notification settings
    • account.getNotifyExceptions
    • account.getNotifySettings
    • account.registerDevice
    • account.resetNotifySettings
    • account.unregisterDevice
    • account.updateDeviceLocked
    • account.updateNotifySettings
  • Working with other users
    • users.getFullUser
    • users.getUsers
  • Working with payments
    • account.getTmpPassword
    • messages.setBotPrecheckoutResults
    • messages.setBotShippingResults
    • payments.clearSavedInfo
    • payments.getPaymentForm
    • payments.getPaymentReceipt
    • payments.getSavedInfo
    • payments.sendPaymentForm
    • payments.validateRequestedInfo
  • Working with polls
    • messages.getPollResults
    • messages.getPollVotes
    • messages.sendVote
  • Working with Public Service Announcement and MTProxy channels
    • help.getPromoData
    • help.hidePromoData
  • Working with scheduled messages
    • messages.deleteScheduledMessages
    • messages.getScheduledHistory
    • messages.getScheduledMessages
    • messages.sendScheduledMessages
  • Working with Seamless Telegram Login
    • account.getWebAuthorizations
    • account.resetWebAuthorization
    • account.resetWebAuthorizations
    • messages.acceptUrlAuth
    • messages.requestUrlAuth
  • Working with secret chats
    • messages.acceptEncryption
    • messages.discardEncryption
    • messages.getDhConfig
    • messages.readEncryptedHistory
    • messages.receivedQueue
    • messages.requestEncryption
    • messages.sendEncrypted
    • messages.sendEncryptedFile
    • messages.sendEncryptedService
    • messages.setEncryptedTyping
  • Working with sensitive content (NSFW)
    • account.getContentSettings
    • account.setContentSettings
  • Working with sponsored proxies
    • help.getProxyData
  • Working with stickers
    • messages.clearRecentStickers
    • messages.faveSticker
    • messages.getAllStickers
    • messages.getArchivedStickers
    • messages.getAttachedStickers
    • messages.getFavedStickers
    • messages.getFeaturedStickers
    • messages.getMaskStickers
    • messages.getOldFeaturedStickers
    • messages.getRecentStickers
    • messages.getStickers
    • messages.getStickerSet
    • messages.installStickerSet
    • messages.readFeaturedStickers
    • messages.reorderStickerSets
    • messages.saveRecentSticker
    • messages.searchStickerSets
    • messages.toggleStickerSets
    • messages.uninstallStickerSet
    • stickers.addStickerToSet
    • stickers.changeStickerPosition
    • stickers.createStickerSet
    • stickers.removeStickerFromSet
    • stickers.setStickerSetThumb
  • Working with telegram passport
    • account.acceptAuthorization
    • account.deleteSecureValue
    • account.getAllSecureValues
    • account.getAuthorizationForm
    • account.getAuthorizations
    • account.getSecureValue
    • account.saveSecureValue
    • account.sendVerifyEmailCode
    • account.sendVerifyPhoneCode
    • account.verifyEmail
    • account.verifyPhone
    • help.getPassportConfig
    • users.setSecureValueErrors
  • Working with the user's account
    • account.changePhone
    • account.confirmPhone
    • account.deleteAccount
    • account.getAccountTTL
    • account.getGlobalPrivacySettings
    • account.getPrivacy
    • account.resetAuthorization
    • account.sendChangePhoneCode
    • account.sendConfirmPhoneCode
    • account.setAccountTTL
    • account.setGlobalPrivacySettings
    • account.setPrivacy
    • account.updateProfile
    • account.updateStatus
  • Working with TSF (internal use only)
    • help.editUserInfo
    • help.getUserInfo
  • Working with updates
    • updates.getChannelDifference
    • updates.getDifference
    • updates.getState
  • Working with user profile pictures
    • photos.deletePhotos
    • photos.getUserPhotos
    • photos.updateProfilePhoto
    • photos.uploadProfilePhoto
  • Working with usernames
    • account.checkUsername
    • account.updateUsername
    • channels.checkUsername
    • channels.updateUsername
    • contacts.resolveUsername
  • Working with VoIP calls
    • phone.acceptCall
    • phone.confirmCall
    • phone.discardCall
    • phone.getCallConfig
    • phone.receivedCall
    • phone.requestCall
    • phone.saveCallDebug
    • phone.sendSignalingData
    • phone.setCallRating
  • Working with wallpapers
    • account.getMultiWallPapers
    • account.getWallPaper
    • account.getWallPapers
    • account.installWallPaper
    • account.resetWallPapers
    • account.saveWallPaper
    • account.uploadWallPaper
Powered by GitBook
On this page
  • Installation
  • Full API

Was this helpful?

Quick Start

this should set you up in no time!

NextAdvanced Installation

Last updated 4 years ago

Was this helpful?

Installation

Installing Gramjs is a straight forward process:

$ npm i telegram

If you want to use gramjs in a browser please check the advanced installation page.

Once you've installed gramjs you'll need an API ID and an API hash (read more in ). Get them from : Afterward, you can use the following code to send a message to yourself.

hello.js
const { TelegramClient } = require('telegram')
const { StringSession } = require('telegram/sessions')
const input = require('input') // npm i input

const apiId = 123456
const apiHash = '123456abcdfg'
const stringSession = new StringSession(''); // fill this later with the value from session.save()
(async () => {
    console.log('Loading interactive example...')
    const client = new TelegramClient(stringSession, apiId, apiHash, { connectionRetries: 5 })
    await client.start({
        phoneNumber: async () => await input.text('number ?'),
        password: async () => await input.text('password?'),
        phoneCode: async () => await input.text('Code ?'),
        onError: (err) => console.log(err),
    });
    console.log('You should now be connected.')
    console.log(client.session.save()) // Save this string to avoid logging in again
    await client.sendMessage('me', { message: 'Hello!' });
})()

hello.ts
import { TelegramClient } from 'telegram'
import { StringSession }  from 'telegram/sessions'
import input from 'input'; // npm i input

const apiId = 123456
const apiHash = '123456abcdfg'
const stringSession = new StringSession(''); // fill this later with the value from session.save()
(async () => {
    console.log('Loading interactive example...');
    const client = new TelegramClient(stringSession, apiId, apiHash, { connectionRetries: 5 });
    await client.start({
        phoneNumber: async () => await input.text('number ?'),
        password: async () => await input.text('password?'),
        phoneCode: async () => await input.text('Code ?'),
        onError: (err) => console.log(err),
    });
    console.log('You should now be connected.');
    console.log(client.session.save()) // Save this string to avoid logging in again
    await client.sendMessage('me', { message: 'Hello!' });
})()

Using session strings is the most reliable way to save your session for now.

Full API

gramjs is still in its early stages but it can access all API methods from telegram using the following

fullapi.js
const {Api} = require("telegram/tl");

const result = await client.invoke(new Api.channels.CheckUsername({
    username: "testing"
}));
console.log("Result is ",result);
fullapi.ts
import {Api} from "telegram/tl";

const result = await client.invoke(new Api.channels.CheckUsername({
    username: "testing"
}));
console.log("Result is ",result);

All methods and classes are accessible under Api. for a full list of them check out

Authorization
https://my.telegram.org/apps
https://gram.js.org/