node-tg-bot
node-tg-bot is a node module for implementing Telegram bots in Nodejs using Telegram Bot Api 2.3.1
Installing
npm install node-tg-bot --save
Getting Started
const Telegram = ;
Then to create a bot (the polling way)
const token = 'YOUR BOT TOKEN';const bot = token polling: interval: 1000 timeout: 4000 ;
Or the webhook way (see https://core.telegram.org/bots/self-signed to create your self signed ssl cert/key)
var bot = token webHook: key: 'your_private.key' cert: 'your_public.pem' ;
Then if you are using a webhook
bot;
Commands
Since node-tg-bot is an event emitter you can listen for events to be fired when commands with the same name are sent
bot;
Command parameters are passed in the params argument
/* we send "/hello world"*/bot;/* bot sends "Hi, world"*/
Some events are emitted by default by node-tg-bot such as 'update'. This event is called everytime an update is available
bot;
or the '' event, called whenever an unknown command is sent and 'photo', fired when a photo is uploaded in a chat / conversation
bot;
Here is how you can use your Message Instance
bot;
Classes, methods and properties
Each of the available types (most of them) are implemented as Classes. Properties, when possible, are Instances of available types as well. As an example when we have an incoming update or photo we get
bot;
For further details on types properties refer to https://core.telegram.org/bots/api#available-types
List of available Classes
Telegram.Bot
setWebhook getUpdates getMe sendMessage sendPhoto sendAudio sendDocument sendSticker sendVideo sendVoice sendLocation sendVenue sendContact sendChatAction getUserProfilePhotos getFile kickChatMember leaveChat unbanChatMember getChat getChatAdministrators getChatMembersCount getChatMember answerCallbackQuery answerInlineQuery editMessageText editMessageCaption editMessageReplyMarkup sendGame setGameScore getGameHighScores create an anchor
.setWebhook(url<String>, certificate<InputFile>)
Returns: Promise<Boolean>
.getUpdates(offset<Integer>, limit<Integer>, timeout<Integer>, allowed_updates<Array<String>>)
Returns: Promise<Array<Update>>
.getMe()
Returns: Promise<User>
Update
Properties
Message
Properties
Methods
message.forwardTo(recipient_id)
message.editText(text[, options)
message.editCaption(options)
message.editReplyMarkup(options)
message.getType(void)
User
Properties
Methods
user.sendMessage(text[,options)
user.forwardMessage(message)
user.sendPhoto(photo[, options)
user.sendAudio(audio[, options)
user.sendDocument(document[, options)
user.sendSticker(sticker[, options)
user.sendVideo(video[, options)
user.sendVoice(voice[, options)
user.sendLocation(latitude, longitude[, options)
user.sendVenue(latitude, longitude, title, address[, options)
user.sendChatAction(chat_action)
user.getUserProfilePhotos(offset, limit)
user.kickFromChat(chat_id)
user.unbanFromChat(chat_id)
Chat
Properties
Methods
chat.sendMessage(text[,options)
chat.forwardMessage(message)
chat.sendPhoto(photo[, options)
chat.sendAudio(audio[, options)
chat.sendDocument(document[, options)
chat.sendSticker(sticker[, options)
chat.sendVideo(video[, options)
chat.sendVoice(voice[, options)
chat.sendLocation(latitude, longitude[, options)
chat.sendVenue(latitude, longitude, title, address[, options)
chat.sendChatAction(chat_action)
chat.getUserProfilePhotos(offset, limit)
chat.kickMember(user_id)
chat.unbanMember(user_id)