Messaging API client for Telegram
npm i --save messaging-api-telegram
or
yarn add messaging-api-telegram
import { TelegramClient } from 'messaging-api-telegram';
// get accessToken from telegram [@BotFather](https://telegram.me/BotFather)
const client = TelegramClient.connect('12345678:AaBbCcDdwhatever');
All methods return a Promise.
client.getWebhookInfo()
client.setWebhook('https://4a16faff.ngrok.io/');
client.deleteWebhook();
client.sendMessage(427770117, 'hi', {
disable_web_page_preview: true,
disable_notification: true,
});
client.sendPhoto(
427770117,
'https://example.com/image.png',
{
caption: 'gooooooodPhoto',
disable_notification: true,
}
);
client.sendAudio(
427770117,
'https://example.com/audio.mp3',
{
caption: 'gooooooodAudio',
disable_notification: true,
}
);
client.sendDocument(
427770117,
'https://example.com/doc.gif',
{
caption: 'gooooooodDocument',
disable_notification: true,
}
);
client.sendSticker(
427770117,
'CAADAgADQAADyIsGAAE7MpzFPFQX5QI',
{
disable_notification: true,
}
);
client.sendVideo(
427770117,
'https://example.com/video.mp4',
{
caption: 'gooooooodVideo',
disable_notification: true,
}
);
client.sendVoice(
427770117,
'https://example.com/voice.ogg',
{
caption: 'gooooooodVoice',
disable_notification: true,
}
);
client.sendLocation(
427770117,
{
latitude: 30,
longitude: 45,
},
{
disable_notification: true,
}
);
client.sendVenue(
427770117,
{
latitude: 30,
longitude: 45,
title: 'a_title',
address: 'an_address',
},
{
disable_notification: true,
}
);
client.sendContact(
427770117,
{
phoneNumber: '886123456789',
firstName: 'first',
},
{ last_name: 'last' }
);
client.sendChatAction(427770117, 'typing');
client.getMe()
.then(result => {
console.log(result);
// {
// ok: true,
// result: {
// id: 313534466,
// first_name: 'first',
// username: 'a_bot'
// }
// }
});
client.getUserProfilePhotos(
313534466,
{ limit: 2 }
);
client.getFile('UtAqweADGTo4Gz8cZAeR-ouu4XBx78EeqRkABPL_pM4A1UpI0koD65K2');
client.getChat(427770117);
client.getChatAdministrators(427770117);
client.getChatMembersCount(427770117);
client.getChatMember(427770117, 313534466);
client.editMessageText('new_text', { message_id: 66 });
client.editMessageCaption('new_caption', { message_id: 66 });
client.editMessageReplyMarkup(
{
keyboard: [[{ text: 'new_button_1' }, { text: 'new_button_2' }]],
resize_keyboard: true,
one_time_keyboard: true,
},
{ message_id: 66 }
);
client.deleteMessage(427770117, 66);
client.forwardMessage(
427770117,
313534466,
203,
{ disable_notification: true }
);