Messaging API client for Telegram
npm install messaging-api-telegram> Messaging API client for Telegram

- Installation
- Usage
- API Reference
- Webhook API
- Send API
- Get API
- Updating API
- Group API
- Payments API
- Inline Mode API
- Game API
- Others
- Debug Tips
- Testing
``sh`
npm i --save messaging-api-telegram
or
`sh`
yarn add messaging-api-telegram
`js
const { TelegramClient } = require('messaging-api-telegram');
// get accessToken from telegram @BotFather
const client = new TelegramClient({
accessToken: '12345678:AaBbCcDdwhatever',
});
`
messaging-api-telegram uses axios as HTTP client. We use axios-error package to wrap API error instances for better formatting error messages. Directly calling console.log with the error instance will return formatted message. If you'd like to get the axios request, response, or config, you can still get them via those keys on the error instance.
`js`
client.getWebhookInfo().catch((error) => {
console.log(error); // formatted error message
console.log(error.stack); // error stack trace
console.log(error.config); // axios request config
console.log(error.request); // HTTP request
console.log(error.response); // HTTP response
});
All methods return a Promise.
- getWebhookInfo
- getUpdates
- setWebhook
- deleteWebhook
- sendMessage
- sendPhoto
- sendAudio
- sendDocument
- sendSticker
- sendVideo
- sendVoice
- sendVideoNote
- sendMediaGroup
- sendLocation
- sendVenue
- sendContact
- sendChatAction
- getMe
- getUserProfilePhotos
- getFile
- getFileLink
- getChat
- getChatAdministrators
- getChatMembersCount
- getChatMember
- editMessageText
- editMessageCaption
- editMessageReplyMarkup
- deleteMessage
- editMessageLiveLocation
- stopMessageLiveLocation
- kickChatMember
- unbanChatMember
- restrictChatMember
- promoteChatMember
- exportChatInviteLink
- deleteChatPhoto
- setChatTitle
- setChatDescription
- setChatStickerSet
- deleteChatStickerSet
- pinChatMessage
- unpinChatMessage
- leaveChat
- sendInvoice
- answerShippingQuery
- answerPreCheckoutQuery
- sendGame
- setGameScore
- getGameHighScores
To enable default request debugger, use following DEBUG env variable:
`sh`
DEBUG=messaging-api:request
If you want to use a custom request logging function, just provide your own onRequest:
`js`
const client = new TelegramClient({
accessToken: ACCESS_TOKEN,
onRequest: ({ method, url, headers, body }) => {
/ /
},
});
To avoid sending requests to real Telegram server, specify the origin option when constructing your client:
`js
const { TelegramClient } = require('messaging-api-telegram');
const client = new TelegramClient({
accessToken: ACCESS_TOKEN,
origin: 'https://mydummytestserver.com',
});
``
> Warning: Don't do this on your production server.