A clean and robust Node.js module to interact with official Telegram Bot API.
npm install --save telegram-nodity
const telegram_nodity = require('telegram-nodity')
const tg = new telegram_nodity({
method : 'update', // update => run in getUpdates, hook => run in webhook
api : {
token : "BOT_TOKEN",
id : "BOT_NAME"
},
response : {
parse_mode : "Markdown"
},
})
tg.on('message', (request, response) =>
{
response.reply(request.getText(), (_err, _res) =>
response.end()
)
})
string
hook: run in 127.0.0.2:3313
and listen for webhook request (default)
update: run a task and check getUpdates every 1000ms
object
string
if method
is hook
server run in this host (default is 127.0.0.2
)
nubmer
if method
is hook
server run in this port (default is 3313
)
number
if method
is update
this property is request.timeout
for getUpdates (default is 2000ms
)
number
if method
is update
this property is send request every update_listen_time
in getUpdates (default is 1000ms
)
number
if don't use response.end()
in every reques, end request after queue_timeout
(default is 3000ms
)
telegram send nine event to bot (message, edited_message, channel_post, edited_channel_post, inline_query, chosen_inline_result, callback_query, shipping_query, pre_checkout_query); telegram-nodity
send every event to custom router
tg.on('message', (request, response) => {})
tg.on('edited_message', (request, response) => {})
tg.on('channel_post', (request, response) => {})
tg.on('edited_channel_post', (request, response) => {})
tg.on('inline_query', (request, response) => {})
tg.on('chosen_inline_result', (request, response) => {})
tg.on('callback_query', (request, response) => {})
tg.on('shipping_query', (request, response) => {})
tg.on('pre_checkout_query', (request, response) => {})
tg.on('text', (request, response) => {})
tg.on('type:photo', (request, response) => {})
tg.on('file', (request, response) => {})
tg.on('forward', (request, response) => {})
tg.on('reply', (request, response) => {})
return message.text
or message.caption
tg.on('message', (request, response) => {
console.log(request.getText())
response.end()
})
return message message_id
tg.on('message', (request, response) => {
console.log(request.getMessage_id())
response.end()
})
return message message.chat.id
tg.on('message', (request, response) => {
console.log(request.getChat_id())
response.end()
})
return message user.id
tg.on('message', (request, response) => {
console.log(request.getUser_id())
response.end()
})
return message.edit_date
return message get forward properties
return message message.forward_from.id
return message message.forward_from
return message message.forward_from_chat.id
return message message.forward_from_chat
return message message.forward_from_message_id
return message message.forward_date
return message message.reply_to_message.message_id
return text | photo | audio | voice | video | document | photo | sticker | contact | venue
return message.from.id
return true if type
is text
return
return true if type
is send file
return true if send group or channel action
return action type
if isAction
is true
return true if type
is sticker
return true if type
is contact
return true if type
is venue
... and other methods and properties
end this request, if don't use this, request ended after tg.queue_timeout
send _method
with _parameters
to telegram and call _callback(err, response)
after end request
reply to request.message.message_id
with _parameters
and call _callback(err, response)
after end request
tg.on('message', (request, response) => {
response.reply('Hello', (err, resp) => {
response.end()
})
})
tg.on('message', (request, response) => {
response.reply({text: 'hello'}, (err, resp) => {
response.end()
})
})
sendMessage
to message.chat.id
with _parameters
and call _callback(err, response)
after end request
sendMessage
to message.user.id
with _parameters
and call _callback(err, response)
after end request
forward message from _parameters
to message.user.id
and call _callback(err, response)
after end request
forward message.message_id
to _parameters
and call _callback(err, response)
after end request
message response + =>
message response + =>
message response + =>