Skip to content

Latest commit

 

History

History
351 lines (259 loc) · 5.98 KB

File metadata and controls

351 lines (259 loc) · 5.98 KB

messaging-api-telegram

Messaging API client for Telegram

Table of Contents

Installation

npm i --save messaging-api-telegram

or

yarn add messaging-api-telegram

Usage

Initialize

import { TelegramClient } from 'messaging-api-telegram';

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

API Reference

All methods return a Promise.

Webhook API

getWebhookInfo

client.getWebhookInfo()

setWebhook(url)

client.setWebhook('https://4a16faff.ngrok.io/');

deleteWebhook

client.deleteWebhook();

Send API

Official docs
Content type

sendMessage(chatId, text, options)

client.sendMessage(427770117, 'hi', {
  disable_web_page_preview: true,
  disable_notification: true,
});

Official docs

sendPhoto(chatId, photo, options)

client.sendPhoto(
  427770117,
  'https://example.com/image.png',
  {
    caption: 'gooooooodPhoto',
    disable_notification: true,
  }
);

Official docs

sendAudio(chatId, audio, options)

client.sendAudio(
  427770117,
  'https://example.com/audio.mp3',
  {
    caption: 'gooooooodAudio',
    disable_notification: true,
  }
);

Official docs

sendDocument(chatId, document, options)

client.sendDocument(
  427770117,
  'https://example.com/doc.gif',
  {
    caption: 'gooooooodDocument',
    disable_notification: true,
  }
);

Official docs

sendSticker(chatId, sticker, options)

client.sendSticker(
  427770117,
  'CAADAgADQAADyIsGAAE7MpzFPFQX5QI',
  {
    disable_notification: true,
  }
);

Official docs

sendVideo(chatId, video, options)

client.sendVideo(
  427770117,
  'https://example.com/video.mp4',
  {
    caption: 'gooooooodVideo',
    disable_notification: true,
  }
);

Official docs

sendVoice(chatId, voice, options)

client.sendVoice(
  427770117,
  'https://example.com/voice.ogg',
  {
    caption: 'gooooooodVoice',
    disable_notification: true,
  }
);

Official docs

sendLocation(chatId, location, options)

client.sendLocation(
  427770117,
  {
    latitude: 30,
    longitude: 45,
  },
  {
    disable_notification: true,
  }
);

Official docs

sendVenue(chatId, venue, options)

client.sendVenue(
  427770117,
  {
    latitude: 30,
    longitude: 45,
    title: 'a_title',
    address: 'an_address',
  },
  {
    disable_notification: true,
  }
);

Official docs

sendContact(chatId, contact, options)

client.sendContact(
  427770117,
  {
    phoneNumber: '886123456789',
    firstName: 'first',
  },
  { last_name: 'last' }
);

Official docs

sendChatAction(chatId, action)

client.sendChatAction(427770117, 'typing');

Official docs

Get API

getMe

client.getMe()
.then(result => {
  console.log(result);
  // {
  //   ok: true,
  //   result: {
  //     id: 313534466,
  //     first_name: 'first',
  //     username: 'a_bot'
  //   }
  // }
});

Official docs

getUserProfilePhotos(userId, options)

client.getUserProfilePhotos(
  313534466,
  { limit: 2 }
);

Official docs

getFile(fileId)

client.getFile('UtAqweADGTo4Gz8cZAeR-ouu4XBx78EeqRkABPL_pM4A1UpI0koD65K2');

Official docs

getChat(chatId)

client.getChat(427770117);

Official docs

getChatAdministrators(chatId)

client.getChatAdministrators(427770117);

Official docs

getChatMembersCount(chatId)

client.getChatMembersCount(427770117);

Official docs

getChatMember(chatId, userId)

client.getChatMember(427770117, 313534466);

Official docs

updating API

editMessageText(text, options)

client.editMessageText('new_text', { message_id: 66 });

Official docs

editMessageCaption(caption, options)

client.editMessageCaption('new_caption', { message_id: 66 });

Official docs

editMessageReplyMarkup(replyMarkup, options)

client.editMessageReplyMarkup(
  {
    keyboard: [[{ text: 'new_button_1' }, { text: 'new_button_2' }]],
    resize_keyboard: true,
    one_time_keyboard: true,
  },
  { message_id: 66 }
);

Official docs

deleteMessage(chatId, messageId)

client.deleteMessage(427770117, 66);

Official docs

Others

forwardMessage(chatId, fromChatId, messageId, options)

client.forwardMessage(
  427770117,
  313534466,
  203,
  { disable_notification: true }
);

Official docs