xaxaxage-telegrambot-library
v2.0.0
Published
<h1 align="center"><b>Telegram bot library</b></h1>
Readme
Class TelegramBot with constructor TelegramBot(token)
Bot.data
Bot.data.update_id - Update id Bot.data.message.message_id - Message id Bot.data.message.from.id - User id Bot.data.message.from.is_bot - If user is bot. (true or false) Bot.data.message.from.first_name - User firstname Bot.data.message.from.last_name - User lastname Bot.data.message.from.username - User username Bot.data.message.from.language_code User laguage code Bot.data.message.chat.id - Chat id Bot.data.message.chat.type - Chat type (private or public) Bot.data.message.date - Message date Bot.data.message.text - Message text
Function getMessage
Takes two arguments: gettingText, callBack
gettingText - Message bot has to answer (string) (required) callBack - Function that bot has to call if gettingText was sent to bot (function) (required)
Function sendMessage
Takes two arguments: messageText and parse_mode
messageText - Message to response (string) (required) parse_mode - Parse mode (string) (not required)
Must be called only in getMessage or setCommand functions
Function sendSticker
Takes one argument: sticker_id
sticker_id - Id of sticker to send (string) (required)
Must be called only in getMessage or setCommand functions
Function setCommand
Takes three arguments: command, description and callBack
command - Command to get (string) (required) description - Description for command. If no description leave '' (string) (required) callBack - Function that bot has to call if command was sent to bot (function) (required)
Function setChatMenu
Takes no arguments
Adding menu button to a telegram bot
Function setReplyKeyboard
Takes one argument: Object with text, keyboard, is_persisent, resize_keyboard, input_field_placeholder, one_time_keyboard, selective
Object - {text: messageText, keyboard: keyboard, is_persisent: is_persisent, resize_keyboard: resize_keyboard, input_field_placeholder: input_field_placeholder selective: selective}
text - Message to send (string) (required) keyboard - Buttons of a keyboard (Array of a buttons) (required)
Look at documentation:
is_persisent (bool) (not required) resize_keyboard (bool) (not required) input_field_placeholder (string) (not required) one_time_keyboard (bool) (not required) selective (bool) (not required)
Must be called only in getMessage or setCommand functions
Function replyKeyboardRemove
Takes one argument: chat_id
chat_id - Id of the chat. Must be: Bot.data.message.chat.id (string or integer) (required)
Must be called only in getMessage or setCommand functions
Function setReplyKeyboard
Takes one argument: Object with text, keyboard
Object - {text: messageText, keyboard: keyboard}
text - Message to send (string) (required) keyboard - Buttons of a keyboard (Array of a buttons) (required)
Look at documentation:
Must be called only in getMessage or setCommand functions
Function polling
Takes no arguments
Starts the bot
const Bot = new TelegramBot(token)
// --sendMessage--------------------------------------------------------------------------
Bot.getMessage('message', () => {
Bot.sendMessage('message to send', 'parse mode')
})
// --setCommand--------------------------------------------------------------------------
Bot.setCommand('/command', 'description', () => {
Bot.sendMessage('message to send', 'parse mode')
})
// --sendSticker-------------------------------------------------------------------------
Bot.getMessage('message2', () => {
Bot.sendSticker('sticker id')
})
// --setChatMenu-------------------------------------------------------------------------
Bot.setChatMenu()
// --setReplyKeyboard--------------------------------------------------------------------
Bot.getMessage('keyboard', () => {
const markup =
[
['Button1_row_1', 'Button2_row_1'],
['Button1_row_2', 'Button2_row_2'],
]
Bot.setReplyKeyboard({text: 'Keyboard', keyboard: markup})
})
// --replyKeyboardRemove-----------------------------------------------------------------
Bot.getMessage('keyboard button message', () => {
Bot.replyKeyboardRemove(Bot.data.message.chat.id)
})
// --setInlineKeyboard-------------------------------------------------------------------
Bot.getMessage('inline keyboard', () => {
const markup =
[
[{text: 'Button1_row1', url: 'url'}, {text: 'Button2_row1'}],
[{text: 'Button1_row2', url: 'url'}, {text: 'Button2_row2'}]
]
Bot.setInlineKeyboard({text: 'Keyboard', keyboard: markup})
})
// --polling-----------------------------------------------------------------------------
Bot.polling()