Socket
Socket
Sign inDemoInstall

messaging-api-telegram

Package Overview
Dependencies
26
Maintainers
3
Versions
78
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    messaging-api-telegram

Messaging API client for Telegram


Version published
Weekly downloads
1.2K
increased by4.57%
Maintainers
3
Install size
3.76 MB
Created
Weekly downloads
 

Readme

Source

messaging-api-telegram

Messaging API client for Telegram

Telegram

Table of Contents

  • Installation
  • Usage
  • API Reference
  • Debug Tips
  • Testing

Installation

npm i --save messaging-api-telegram

or

yarn add messaging-api-telegram

Usage

Initialize

const { TelegramClient } = require('messaging-api-telegram');

// get accessToken from telegram [@BotFather](https://telegram.me/BotFather)
const client = new TelegramClient({
  accessToken: '12345678:AaBbCcDdwhatever',
});

Error Handling

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.

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
});

API Reference

All methods return a Promise.


Webhook API


Send API - Official Docs


Get API


Updating API


Group API


Payments API


Inline mode API


Game API


Others


Debug Tips

Log Requests Details

To enable default request debugger, use following DEBUG env variable:

DEBUG=messaging-api:request

If you want to use a custom request logging function, just provide your own onRequest:

const client = new TelegramClient({
  accessToken: ACCESS_TOKEN,
  onRequest: ({ method, url, headers, body }) => {
    /* */
  },
});

Testing

Point Requests to Your Dummy Server

To avoid sending requests to real Telegram server, specify the origin option when constructing your client:

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.

Keywords

FAQs

Last updated on 04 Oct 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc